On Sat, May 15, 2010 at 3:04 AM, ses1984 <ses1...@gmail.com> wrote: > I am interested in writing unit tests to cover some custom commands I > have written, but I'm unsure how I can pass options to these commands > through my unittest.TestCase classes. > > I have a command to import data from my client's flat file system into > Django models, which originally existed as a NoArgsCommand with no > options. I tested it like this: > > class ImportDataTest(unittest.TestCase): > > def setUp(self): > test_command = import_flatfile_data.Command() > test_command.handle_noargs() > > I have added a boolean flag option to this command, so I would like to > split this test case in two, where one case sets up the command as > with the flag set to true, and one case where the flag is false. > > I tried looking for testing coverage of django's own management > commands, but I was unable to find those.
There aren't a lot of specific tests for Django's management commands. This is generally because the commands are either testing database-specific setup behavior (which is very hard to test specifically), or they are thin wrappers around an underlying function that is tested separately. However, a couple of management commands are used extensively in tests - in particular, loaddata, dumpdata and flush. If you look at the fixtures_regress test, you'll see lots of calls to management.call_command, which is used to invoke management commands. Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.