On Thu, 2006-06-08 at 23:07 -0400, Todd O'Bryan wrote: > I'm having a chicken-and-egg problem. > > So, I want to drop the test database, recreate it, sync it to the > models, and then populate it with test data, ideally automatically > because automatic tests are far more likely to get run. > > If I want the drop and create commands to be generic, they need > access to the current DATABASE_NAME, so they have to be called while > the server or shell is running so that they pick up any --settings= > options from the command line and know which database to use. > > But then I have to run syncdb, which I can't figure out how to run > under program control. Well, I can, but it prints out all the stuff > it would print if it was called on the command line and stops to ask > if I want to create a superuser, which is kind of annoying in the > middle of a test script. > > And then I need to be running under program control again to add all > my test data to the the db. > > Please tell me that I'm overthinking this and there's some easy way > out of this!
Warning: I haven't tested what I'm about to suggest here, but it should come close... It sounds like you want to do the equivalent of "manage.py reset" -- drop all the data and tables and recreate them for a bunch of apps that you know about. So have a look at how django/core/management.py implements the reset() method. Duplicating the three or four lines of code that do the real work there should not be too hard. Looping through each of your apps, you basically want to do sql_list = get_sql_reset(app) cursor = connection.cursor() for sql in sql_list: cursor.execute(sql) with some exception handling wrapped in somewhere. Doing that inside your test framework will work, won't it. And you're not duplicating too much code here: the above fragement uses core.management.get_sql_reset() to do all the heavy lifting. Best wishes, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---