Snippet List
Ever tried to unit test custom fields or abstract models? If so, you probably used a solution like [this one](http://djangosnippets.org/snippets/2843/). It surely works, but it has some issues:
1. Runs 'syncdb' several times.
2. It's not automatic. You must add the mixin or copy the code to each of the TestCases.
This test runner adds to INSTALLED_APPS the 'app.tests' package for **each of the specified** apps, **before the 'syncdb' happens**.
This has the [discovery runner](https://pypi.python.org/pypi/django-discover-runner) as a dependency (for 1.5 only, it will be the default in 1.6). However, it comes as a mixin so it should be easily pluggable to other test runners.
If you intend to use the mixin with other runners, note that it imports 'app.tests.models' so it won't work with tests modules (tests.py). Your runner must "use" test packages (like discovery runner).
# USAGE
# in your settings.py:
TESTAPPS_INSTALL = (
'app1',
'app2',
# ...
)
TEST_RUNNER = 'testapp_runner.DiscoverTestAppRunner' # example import path
# extra apps in command line.
# run test for apps 'app1' to 'app4', adding 'app3' and 'app4' to the TESTAPPS_INSTALL setting.
manage.py test app1 app2 app3 app4 --with-test-app=app3 --with-test-app=app4
- django
- testing
- apps
- testrunner
- test-runner
- app-models
A simple script that I have put in my Django applications directory to fetch the latest application code from git and svn.
For example, your directory structure might look like so:
django-apps/
django-tagging/
django-pagination/
django-registration/
django-threadedcomments/
django-mptt/
update_apps.py
Where update_apps.py is the source of this snippet.
To run, simply execute:
# python update_apps.py
And the script will iterate through all of your apps and update them to the latest version.
- script
- update
- apps
- project
- svn
- git
How to make this work:
* Put the code into your settings.py (or even better, local_settings.py if you have one)
* Put 3rd party apps you'd like to use into the directories specified in APP_DIRS.
* Place 'appname', into INSTALLED_APPS.
Just a little trick I use to keep from having to install apps via setup.py; I can just stick apps into arbitrary locations and use them. I also do this to keep single copies of 3rd party apps I use in multiple projects (but again without installing to the global python path). No idea if this is bad practice or anything, but I find it useful.
- settings
- apps
- applications
Use this snippet at the end of your main settings.py file to automagically import the settings defined in each app of `INSTALLED_APPS` that begins with `APPS_BASE_NAME`.
Set `APPS_BASE_NAME` to the base name of your Django project (e.g. the parent directory) and put `settings.py` files in every app directory (next to the `models.py` file) you want to have local settings in.
# works in the Django shell
>>> from django.conf import settings
>>> settings.TEST_SETTING_FROM_APP
"this is great for reusable apps"
Please keep in mind that the imported settings will overwrite the already given and preceding settings, e.g. when you use the same setting name in different applications.
Props to [bartTC](http://www.djangosnippets.org/users/bartTC/) for the idea.
- settings
- import
- reusable
- apps
- applications
6 snippets posted so far.