Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/garethr/django-test-extensions
A set of custom assertions and examples for use testing django applications
https://github.com/garethr/django-test-extensions
Last synced: 5 days ago
JSON representation
A set of custom assertions and examples for use testing django applications
- Host: GitHub
- URL: https://github.com/garethr/django-test-extensions
- Owner: garethr
- License: mit
- Created: 2008-10-27T14:36:11.000Z (about 16 years ago)
- Default Branch: master
- Last Pushed: 2011-10-26T19:21:18.000Z (about 13 years ago)
- Last Synced: 2024-12-08T16:22:56.695Z (14 days ago)
- Language: Python
- Homepage:
- Size: 215 KB
- Stars: 144
- Watchers: 3
- Forks: 29
- Open Issues: 11
-
Metadata Files:
- Readme: README.textile
- License: LICENSE
Awesome Lists containing this project
README
PyUnit provides a basic set of assertions which can get you started with unit testing python, but it's always useful to have more. Django also has a few specific requirements and common patterns when it comes to testing. This set of classes aims to provide a useful starting point for both these situations.
The application also overrides the default Django test runner, adding a few useful features:
h2. Installation
Just add the project to your INSTALLED_APPS.
INSTALLED_APPS = (
'test_extensions',
)Note that this application steals the test command from django, overriding it with extra toys. If another application in your INSTALLED_APPS does this too then the last one in the list will win. South migrations does this in order to use the django syncdb command for testing, which test_extensions does too. As of 0.4 test_extensions works with South, just as long as you include it after south in the list of installed apps.
h2. Assertions
See the examples directory in the src/test_extensions directory for details of a large number of useful assertions for testing django apps:
* assert_response_contains
* assert_response_doesnt_contain
* assert_regex_contains
* assert_render_matches
* assert_code
* assert_render
* assert_render_matches
* assert_doesnt_render
* assert_render_contains
* assert_render_doesnt_containh2. Test Runners
h3. XMLUnit
Sometimes it's nice to have a file reporting the results of a test run. Some applications such as CruiseControl can use this to display the results in a user interface.
python manage.py test --xmlh3. Code Coverage
If you want to know what code is being run when you run your test suite then codecoverage is for you. These two flags use two different third party libraries to calculate coverage statistics. The first dumps the results to stdout, --xmlcoverage creates a cobertura-compatible xml output, and the last one creates a series of files displaying the results.
python manage.py test --coveragepython manage.py test --xmlcoveragepython manage.py test --figleafh3. No Database
Sometimes your don't want the overhead of setting up a database during testing, probably because your application just doesn't use it.
python manage.py test --nodbpython manage.py test --nodb --coveragepython manage.py test --nodb --xmlcoverage*WARNING* Don't use this if you use the ORM in your app. An "outstanding issue":http://github.com/garethr/django-test-extensions/issues#issue/13 means that you can get into trouble. Your tests will still hit the database, but it will be your non test data.
h2. Local Continuous Integration Command
Thanks to Roberto Aguilar (http://github.com/rca) for providing a auto-reloading version of the test runner. Run the runtester command and it should run your test suite whenever you change a file (similar to how runserver reloads the server each time you change something.)
See "this thread":http://groups.google.com/group/django-developers/browse_thread/thread/ac991410674c195d/f7179acc65e686cc
from the Django Developer list of more information and discussion.python manage.py runtesterh2. Licence
XMLUnit is included out of convenience. It was written by Marc-Elian Begin and is Copyright (c) Members of the EGEE Collaboration. 2004. http://www.eu-egee.org
The rest of the code is licensed under an MIT license:
Copyright (c) 2008 Gareth Rushgrove
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.