Skip to content

Commit

Permalink
Acceptance tests using Behave, WebTest and Nose work!
Browse files Browse the repository at this point in the history
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
codeinthehole committed Sep 10, 2013
1 parent 825672b commit cc8fd0d
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ django-webtest>=1.5.7,<1.6
detox==0.9.2
coveralls>=0.1.1,<0.2
purl>=0.4
behave==1.2.3

# i18n
transifex-client>=0.8,<0.9
Expand Down
1 change: 1 addition & 0 deletions tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def configure():
'oscar.apps.customer.notifications.context_processors.notifications',
'oscar.apps.promotions.context_processors.promotions',
'oscar.apps.checkout.context_processors.checkout',
'oscar.core.context_processors.metadata',
),
'TEMPLATE_DIRS': (
location('templates'),
Expand Down
Empty file added tests/features/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions tests/features/environment.py
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()
12 changes: 12 additions & 0 deletions tests/features/homepage.feature
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.
34 changes: 34 additions & 0 deletions tests/features/steps/homepage_steps.py
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)

1 comment on commit cc8fd0d

@codeinthehole
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Please sign in to comment.