-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Acceptance tests using Behave, WebTest and Nose work!
The hard work for this is done in django_nose which provides the appropriate WebTest app, which we can simply re-use in the behave environment.py. They need to be run using: behave tests/features Note, you need to use: behave --no-capture tests/features for PDB to work. First feature is not erroring Simple homepage tests works Extra scenario added
- Loading branch information
1 parent
825672b
commit cc8fd0d
Showing
7 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
def before_all(context): | ||
from tests.config import configure | ||
configure() | ||
|
||
from django.test import utils | ||
utils.setup_test_environment() | ||
|
||
|
||
def before_scenario(context, scenario): | ||
from django.db import connection | ||
connection.creation.create_test_db(verbosity=1, autoclobber=True) | ||
|
||
# Set-up webtest app | ||
from django_webtest import DjangoTestApp | ||
context.browser = DjangoTestApp() | ||
|
||
|
||
def after_scenario(context, scenario): | ||
from django.db import connection | ||
connection.creation.destroy_test_db('', verbosity=1) | ||
|
||
|
||
def after_all(context): | ||
from django.test import utils | ||
utils.teardown_test_environment() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Feature: Smoke test | ||
Scenario: Homepage exists | ||
Given a user | ||
When I view the homepage | ||
Then I get a 200 response | ||
And page includes "Oscar" | ||
|
||
Scenario: Silly page doesn't exist | ||
Given a user | ||
When I view a silly page | ||
Then I get a 404 response | ||
And page includes "Page not found!" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from behave import * | ||
from nose.tools import * | ||
|
||
|
||
@given('a user') | ||
def step(context): | ||
from django_dynamic_fixture import G | ||
from oscar.core.compat import get_user_model | ||
User = get_user_model() | ||
G(User) | ||
|
||
|
||
@when('I view the homepage') | ||
def step(context): | ||
br = context.browser | ||
context.response = br.get('/') | ||
|
||
|
||
@when('I view a silly page') | ||
def step(context): | ||
br = context.browser | ||
context.response = br.get('/silly/', status='*') | ||
|
||
|
||
@then('I get a {code} response') | ||
def step(context, code): | ||
eq_(int(code), context.response.status_code, | ||
"Response did not return a %s code" % code) | ||
|
||
|
||
@then('page includes "{text}"') | ||
def step(context, text): | ||
ok_(text.encode('utf8') in context.response.content, | ||
"%r not page content" % text) |
cc8fd0d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.