I am trying to create a set of test case to cover my django application. I need pre defined database data, to run some of my test. So I decided to use fixtures.
What I did was: 1) created fixture file: oleg$ python manage.py dumpdata goserver > fixture1.json 2) Placed the fixture in the directory where application lives oleg$ cp fixture1.json goserver/ 3) Write down the texture name in the tests file in my application
class GoserverTestCase(TestCase):
fixtures = ['fixture1.json']
def setUp(self):
pass
def testUserIsAdded(self):
print "Users" , User.objects.all()
#print ActiveList.objects.all()
self.assertEquals(True, True)
4) Run the text case with a command: oleg$ python manage.py test --verbosity=2 goserver
The output of the test run is (part of it):
Trying '/Users/oleg/jin/goclub/trunk/jin/../jin/register/fixtures' for xml fixture 'initial_data'... No xml fixture 'initial_data' in '/Users/oleg/jin/goclub/trunk/jin/../jin/register/fixtures'. Trying '/Users/oleg/jin/goclub/trunk/jin/../jin/register/fixtures' for json fixture 'initial_data'... No json fixture 'initial_data' in '/Users/oleg/jin/goclub/trunk/jin/../jin/register/fixtures'. Checking '/Users/oleg/jin/goclub/trunk/jin/../jin/captcha/fixtures' for fixtures... Trying '/Users/oleg/jin/goclub/trunk/jin/../jin/captcha/fixtures' for xml fixture 'initial_data'... No xml fixture 'initial_data' in '/Users/oleg/jin/goclub/trunk/jin/../jin/captcha/fixtures'. Trying '/Users/oleg/jin/goclub/trunk/jin/../jin/captcha/fixtures' for json fixture 'initial_data'... No json fixture 'initial_data' in '/Users/oleg/jin/goclub/trunk/jin/../jin/captcha/fixtures'. Checking '/Users/oleg/jin/goclub/trunk/jin/../jin/goserver/fixtures' for fixtures... Trying '/Users/oleg/jin/goclub/trunk/jin/../jin/goserver/fixtures' for xml fixture 'initial_data'... No xml fixture 'initial_data' in '/Users/oleg/jin/goclub/trunk/jin/../jin/goserver/fixtures'. Trying '/Users/oleg/jin/goclub/trunk/jin/../jin/goserver/fixtures' for json fixture 'initial_data'... No json fixture 'initial_data' in '/Users/oleg/jin/goclub/trunk/jin/../jin/goserver/fixtures'. Checking '/' for fixtures... Trying '/' for xml fixture 'initial_data'... No xml fixture 'initial_data' in '/'. Trying '/' for json fixture 'initial_data'... No json fixture 'initial_data' in '/'. Checking 'U' for fixtures... Trying 'U' for xml fixture 'initial_data'... No xml fixture 'initial_data' in 'U'. Trying 'U' for json fixture 'initial_data'... No json fixture 'initial_data' in 'U'. Checking 's' for fixtures... Trying 's' for xml fixture 'initial_data'... No xml fixture 'initial_data' in 's'. Trying 's' for json fixture 'initial_data'..
Actually the problem is that the fixture was not found at all, so no data I wanted to add into the test database was added. Could you please suggest me a way to solve the problem
I tried a new way to do it. I just made a dump of complete database and put it to the application folder.
But I came cross some encoding issues.
Can you please check the error response:
File "build/bdist.macosx-10.3-i386/egg/MySQLdb/cursors.py", line 168, in execute if not self._defer_warnings: self._warning_check() File "build/bdist.macosx-10.3-i386/egg/MySQLdb/cursors.py", line 82, in _warning_check warn(w[-1], self.Warning, 3) File "/opt/local/lib/python2.5/warnings.py", line 62, in warn globals) File "/opt/local/lib/python2.5/warnings.py", line 102, in warn_explicit raise message Warning: Incorrect string value: '\xD0\x9D\xD0\xB0 \xD0...' for column 'object_repr' at row 1
testUserIsAdded (jin.goserver.tests.GoserverTestCase) ... Users []
Have another problem. When I disabled fixtures I still getting an error:
Unit Test Code Coverage Results
Traceback (most recent call last): File "manage.py", line 11, in execute_manager(settings) File "/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/core/management/init.py", line 340, in execute_manager utility.execute() File "/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/core/management/init.py", line 295, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/core/management/base.py", line 192, in run_from_argv self.execute(*args, **options.dict) File "/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/core/management/base.py", line 219, in execute output = self.handle(*args, **options) File "/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/core/management/commands/test.py", line 33, in handle failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive) File "/opt/local/lib/python2.5/site-packages/django_test_coverage-0.1-py2.5.egg/django-test-coverage/runner.py", line 58, in run_tests modules.extend(_package_modules(*pkg)) File "/opt/local/lib/python2.5/site-packages/django_test_coverage-0.1-py2.5.egg/django-test-coverage/runner.py", line 92, in _package_modules modules.append(import(impstr + '.' + name, {}, {}, [''])) File "/Users/oleg/jin/goclub/trunk/jin/goserver/admin.py", line 11, in admin.site.register(ActiveList, ActiveListAdmin) File "/opt/local/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/contrib/admin/sites.py", line 64, in register raise AlreadyRegistered('The model %s is already registered' % model.name) django.contrib.admin.sites.AlreadyRegistered: The model ActiveList is already registered