-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
497 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ coverage.xml | |
|
||
# Django stuff: | ||
*.log | ||
*.sqlite3 | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
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,36 @@ | ||
# Contributing | ||
|
||
Wanna help out with behave-django? Yay! Here's a quick guide to do just that. | ||
|
||
Fork, then clone the repo: | ||
|
||
git clone [email protected]:your-username/behave-django.git | ||
|
||
Install the dependencies | ||
|
||
pip install -r requirements.txt | ||
|
||
Make sure the tests pass: | ||
|
||
python manage.py behave | ||
|
||
Start your topic branch | ||
|
||
git checkout -b your-topic-branch | ||
|
||
Make your change. Add tests for your change. Make the tests pass: | ||
|
||
python manage.py test | ||
|
||
Your tests don't have to be behave tests. :smile: | ||
|
||
Push to your fork and [submit a pull request][pr]. | ||
|
||
[pr]: https://github.com/mixxorz/behave-django/compare/ | ||
|
||
Other things to note: | ||
|
||
* Write tests. | ||
* We're using PEP8 as our code style guide | ||
|
||
Thanks :) |
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 |
---|---|---|
@@ -1,2 +1,68 @@ | ||
# behave-django | ||
Behave test runner for Django | ||
Behave BDD integration for Django | ||
|
||
## Features | ||
* Web Browser Automation ready | ||
* Database transactions per scenario | ||
* Use Django's testing client | ||
* Use unittest + Django assert library | ||
|
||
## Installation | ||
|
||
Install using pip | ||
|
||
pip install behave-django | ||
|
||
Add `behave_django` to your `INSTALLED_APPS` | ||
|
||
INSTALLED_APPS += ('behave_django',) | ||
|
||
Create the features directory in your project's root directory. | ||
|
||
features/ | ||
steps/ | ||
your_steps.py | ||
environment.py | ||
your-feature.feature | ||
|
||
Setup your `environment.py` file | ||
|
||
from behave_django import environment | ||
|
||
def before_scenario(context, scenario): | ||
environment.before_scenario(context, scenario) | ||
|
||
def after_scenario(context, scenario): | ||
environment.after_scenario(context, scenario) | ||
|
||
Run `python manage.py behave` | ||
|
||
Creating test database for alias 'default'... | ||
Feature: Running tests # features/running-tests.feature:1 | ||
In order to prove that behave-django works | ||
As the Maintainer | ||
I want to test running behave against this features directory | ||
Scenario: The Test # features/running-tests.feature:6 | ||
Given this step exists # features/steps/running_tests.py:4 0.000s | ||
When I run "python manage.py behave" # features/steps/running_tests.py:9 0.000s | ||
Then I should see the behave tests run # features/steps/running_tests.py:14 0.000s | ||
|
||
1 features passed, 0 failed, 0 skipped | ||
1 scenarios passed, 0 failed, 0 skipped | ||
3 steps passed, 0 failed, 0 skipped, 0 undefined | ||
Took.010s | ||
Destroying test database for alias 'default'... | ||
|
||
## TODO | ||
* You should be able to set where you features directory will be. | ||
* You should be able to pass regular behave command line args. | ||
* You should see behave's unimplemented step hints. | ||
* Support for Django 1.4.x, 1.6.x, 1.7.x, 1.8 on Python 2.6, 2.7, 3, 3.3, 3.4. | ||
|
||
## Contributing | ||
[Read the quick contributing guide](CONTRIBUTING.md) | ||
|
||
|
||
## Changelog | ||
### 0.1.0 | ||
* Initial release |
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 @@ | ||
# Release 0.1.0 |
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,13 @@ | ||
from behave_django.testcase import BehaveDjangoTestCase | ||
|
||
def before_scenario(context, scenario): | ||
# This is probably a hacky method of setting up the test case | ||
# outside of a test runner. Suggestions are welcome. :) | ||
context.test = BehaveDjangoTestCase() | ||
context.test.setUpClass() | ||
context.test() | ||
context.base_url = context.test.live_server_url | ||
|
||
def after_scenario(context, scenario): | ||
context.test.tearDownClass() | ||
del context.test |
Empty file.
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 __future__ import absolute_import | ||
import os | ||
|
||
from behave.configuration import Configuration | ||
from behave.runner import Runner | ||
from django.conf import settings | ||
from django.core.management.base import BaseCommand, CommandError | ||
from django.test.runner import DiscoverRunner | ||
|
||
from behave_django.testcase import BehaveDjangoTestCase | ||
|
||
|
||
class Command(BaseCommand): | ||
args = '<app_name app_name ...>' | ||
help = 'Runs behave tests' | ||
|
||
def handle(self, *args, **options): | ||
# Configure Behave | ||
configuration = Configuration() | ||
configuration.paths = [os.path.join(settings.BASE_DIR, 'features')] | ||
configuration.format = ['pretty'] | ||
|
||
# Configure django environment | ||
django_test_runner = DiscoverRunner() | ||
django_test_runner.setup_test_environment() | ||
old_config = django_test_runner.setup_databases() | ||
|
||
# Run Behave tests | ||
runner = Runner(configuration) | ||
runner.run() | ||
|
||
# Teardown django environment | ||
django_test_runner.teardown_databases(old_config) | ||
django_test_runner.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,6 @@ | ||
<!doctype html> | ||
<html> | ||
<body> | ||
Behave Django works | ||
</body> | ||
</html> |
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,6 @@ | ||
from django.contrib.staticfiles.testing import StaticLiveServerTestCase | ||
|
||
class BehaveDjangoTestCase(StaticLiveServerTestCase): | ||
|
||
def runTest(*args, **kwargs): | ||
pass |
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: Database Transactions | ||
In order to test if transactions are done per scenario | ||
As the Maintainer | ||
I want to save two database items | ||
|
||
Scenario: Save the first item | ||
When I save the object | ||
Then I should only have one object | ||
|
||
Scenario: Save the second item | ||
When I save the object | ||
Then I should only have one object |
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,8 @@ | ||
Feature: Django's test client | ||
In order to ensure that the django's test client works in behave steps | ||
As the Maintainer | ||
I want to test if the client works | ||
|
||
Scenario: Django's test client | ||
When I use django's test client to visit "/" | ||
Then it should return a successful response |
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: Django + unittest asserts | ||
In order to have cleaner assert calls | ||
As the Maintainer | ||
I want to use Django + unittest's built in assert library | ||
|
||
Scenario: Testing the unittest assert library | ||
When I use the unittest assert library | ||
Then it should work properly | ||
|
||
Scenario: Testing the django assert library | ||
When I use the django assert library | ||
Then it should work properly |
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,8 @@ | ||
from behave_django import environment | ||
|
||
|
||
def before_scenario(context, scenario): | ||
environment.before_scenario(context, scenario) | ||
|
||
def after_scenario(context, scenario): | ||
environment.after_scenario(context, scenario) |
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,8 @@ | ||
Feature: Live server | ||
In order to prove that the live server works | ||
As the Maintainer | ||
I want to send an HTTP request | ||
|
||
Scenario: HTTP GET | ||
When I visit "/" | ||
Then I should see "Behave Django works" |
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,9 @@ | ||
Feature: Running tests | ||
In order to prove that behave-django works | ||
As the Maintainer | ||
I want to test running behave against this features directory | ||
|
||
Scenario: The Test | ||
Given this step exists | ||
When I run "python manage.py behave" | ||
Then I should see the behave tests run |
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,13 @@ | ||
from behave import when, then | ||
|
||
from test_app.models import BehaveTestModel | ||
|
||
|
||
@when(u'I save the object') | ||
def save_object(context): | ||
BehaveTestModel.objects.create(name='Behave Works', number=123) | ||
|
||
|
||
@then(u'I should only have one object') | ||
def should_have_only_one_object(context): | ||
assert 1 == BehaveTestModel.objects.count() |
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,18 @@ | ||
from behave import when, then | ||
|
||
|
||
@when(u'I use the unittest assert library') | ||
def use_assert_library(context): | ||
# If one of them works, all of them work. ;) | ||
context.test.assertEqual(1, 1) | ||
|
||
|
||
@when(u'I use the django assert library') | ||
def use_assert_library(context): | ||
response = context.test.client.get('/') | ||
context.test.assertTemplateUsed(response, 'index.html') | ||
|
||
|
||
@then(u'it should work properly') | ||
def asserts_should_work(context): | ||
pass |
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,10 @@ | ||
from behave import when, then | ||
|
||
@when(u'I use django\'s test client to visit "{url}"') | ||
def use_django_client(context, url): | ||
context.response = context.test.client.get(url) | ||
|
||
|
||
@then(u'it should return a successful response') | ||
def it_should_be_successful(context): | ||
assert context.response.status_code == 200 |
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,13 @@ | ||
import urllib2 | ||
|
||
from behave import when, then | ||
|
||
|
||
@when(u'I visit "{url}"') | ||
def visit(context, url): | ||
context.response = urllib2.urlopen(context.base_url + url).read() | ||
|
||
|
||
@then(u'I should see "{text}"') | ||
def i_should_see(context, text): | ||
assert text in context.response |
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,16 @@ | ||
from behave import given, when, then | ||
|
||
|
||
@given(u'this step exists') | ||
def step_exists(context): | ||
pass | ||
|
||
|
||
@when(u'I run "python manage.py behave"') | ||
def run_command(context): | ||
pass | ||
|
||
|
||
@then(u'I should see the behave tests run') | ||
def is_running(context): | ||
pass |
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,10 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings") | ||
|
||
from django.core.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) |
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,2 @@ | ||
behave | ||
Django>=1.7 |
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,40 @@ | ||
import os | ||
from setuptools import find_packages, setup | ||
|
||
# allow setup.py to be run from any path | ||
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) | ||
|
||
setup( | ||
name='behave-django', | ||
version='0.1.0', | ||
packages=find_packages(), | ||
include_package_data=True, | ||
license='MIT License', | ||
description='Behave BDD integration for Django', | ||
url='https://github.com/mixxorz/behave-django', | ||
author='Mitchel Cabuloy', | ||
author_email='[email protected]', | ||
install_requires=[ | ||
'behave', | ||
'Django>=1.7' | ||
], | ||
classifiers=[ | ||
'Development Status :: 3 - Alpha', | ||
'Environment :: Console', | ||
'Environment :: Plugins', | ||
'Environment :: Web Environment', | ||
'Framework :: Django', | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: OS Independent', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 2', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.3', | ||
'Programming Language :: Python :: 3.4', | ||
'Topic :: Internet :: WWW/HTTP', | ||
'Topic :: Internet :: WWW/HTTP :: Dynamic Content', | ||
'Topic :: Software Development :: Testing', | ||
], | ||
) |
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,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
Oops, something went wrong.