diff --git a/.gitignore b/.gitignore index b226997..c845b88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ *.sw? .DS_Store index.json +*.pyc +*.xml +report.html +log.html +*.pdf diff --git a/_sources/python-bdd/features/example.feature b/_sources/python-bdd/features/example.feature new file mode 100644 index 0000000..3d80839 --- /dev/null +++ b/_sources/python-bdd/features/example.feature @@ -0,0 +1,7 @@ +Feature: Testing passwords + + Scenario: Invalid password + Given that I have a username foo + And that I have a password test123 + When I try to create an user + Then I should get an error of invalid password diff --git a/_sources/python-bdd/features/mainsource.py b/_sources/python-bdd/features/mainsource.py new file mode 120000 index 0000000..f66c870 --- /dev/null +++ b/_sources/python-bdd/features/mainsource.py @@ -0,0 +1 @@ +../mainsource.py \ No newline at end of file diff --git a/_sources/python-bdd/features/steps/example_steps.py b/_sources/python-bdd/features/steps/example_steps.py new file mode 100644 index 0000000..3a1bd15 --- /dev/null +++ b/_sources/python-bdd/features/steps/example_steps.py @@ -0,0 +1,34 @@ +# -*- encoding: utf-8 -*- + +"""Behave steps.""" + +import behave +import mainsource + + +@behave.given("that I have a username {name}") +def set_username(context, name): + context.username = name + return + + +@behave.given("that I have a password {password}") +def set_password(context, password): + context.password = password + return + + +@behave.when("I try to create an user") +def create_user(context): + try: + mainsource.create_user(context.username, context.password) + except mainsource.UserCreationError as exc: + context.last_exception = exc + return + + +@behave.then("I should get an error of invalid password") +def is_invalid_password(context): + assert hasattr(context, 'last_exception') + assert isinstance(context.last_exception, + mainsource.PasswordIsNotStrongEnough) diff --git a/python-bdd.html b/python-bdd.html index 55881a7..63b641d 100644 --- a/python-bdd.html +++ b/python-bdd.html @@ -233,6 +233,8 @@ if __name__ == "__main__":

Robot Framework

+

pip install robotframework

+
+ +
+

Robot Framework

+ +

Vantagens:

+ + +

Behave

+ +

pip install behave

+ + +
+ +
+

Behave

+ +
Feature: Testing passwords
+
+	Scenario: Invalid password
+		Given that I have a username foo
+		  And that I have a password test123
+		 When I try to create an user
+		 Then I should get an error of invalid password
+
+ +
+

Behave

+ +
# -*- encoding: utf-8 -*-
+
+"""Behave steps."""
+
+import behave
+import mainsource
+
+
+@behave.given("that I have a username {name}")
+def set_username(context, name):
+    context.username = name
+    return
+
+
+@behave.given("that I have a password {password}")
+def set_password(context, password):
+    context.password = password
+    return
+
+
+@behave.when("I try to create an user")
+def create_user(context):
+    try:
+        mainsource.create_user(context.username, context.password)
+    except mainsource.UserCreationError as exc:
+        context.last_exception = exc
+    return
+
+
+@behave.then("I should get an error of invalid password")
+def is_invalid_password(context):
+    assert hasattr(context, 'last_exception')
+    assert isinstance(context.last_exception,
+                      mainsource.PasswordIsNotStrongEnough)
+ +
+ +
+

Behave

+ +
Feature: Testing passwords # features/example.feature:1
+
+  Scenario: Invalid password                       # features/example.feature:3
+    Given that I have a username foo               # features/steps/example_steps.py:9 0.001s
+    And that I have a password test123             # features/steps/example_steps.py:15 0.000s
+    When I try to create an user                   # features/steps/example_steps.py:21 0.001s
+    Then I should get an error of invalid password # features/steps/example_steps.py:30 0.000s
+
+1 feature passed, 0 failed, 0 skipped
+1 scenario passed, 0 failed, 0 skipped
+4 steps passed, 0 failed, 0 skipped, 0 undefined
+Took 0m0.002s 
+
+ +
+

Behave

+ +

Vantagens:

+ +