So I was writing Django view unit tests and setting up fixtures with
sample data, and it hit me -- wouldn't it be useful we made it easy to
run the Django development server with fixture data?
I'm proposing a "--with-fixture" flag to django-admin.py, so that you
could do something like this:
django-admin.py runserver --with-fixture=mydata.json
With this command, Django would:
* Create a new test database (following the TEST_DATABASE_NAME setting).
* Import the fixture data into that fresh test database (just as the
unit test framework does).
* Change the DATABASE_NAME setting in memory to point to the test database.
* Run the development server, pointing at the test database.
* Delete the test database when the development server is stopped.
The main benefit of this feature is that it would let developers poke
around their fixture data and, essentially, walk through unit tests
manually (in a Web browser rather than programatically).
Sure, developers could just set up a separate database, with a
separate settings file, but there are at least two problems with that.
One, it requires a fair amount of overhead, which would discourage
people from doing it. Two, it violates DRY -- if the fixture data is
already available in a fixture file, why not just use that?
In the future, the next step would be to keep track of any database
changes and optionally serialize them back into the fixture when the
server is stopped. This would let people add fixture data through
their Web application itself, whether it's the Django admin site or
something else. Now *that* would be cool and useful! But I'm only
proposing the first part of this for now.
I'm happy to implement this. I just wanted to get some opinions on it
before I start.
Adrian
--
Adrian Holovaty
holovaty.com | djangoproject.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---