tomchristie/django-rest-framework — Issue #89: Unittest fails on m2m_relation_through
Author: idbill
Created: 2011-12-08 23:07:53+00:00
State: open

I just started learning about django unit testing, and low and behold the following:

DatabaseError: relation "tests_customuser" does not exist

That table doesn't exist... why is django-rest-framework writing to a non-existent table?

======================================================================
ERROR: test_creation_with_m2m_relation_through (djangorestframework.tests.mixins.TestModelCreation)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/djangorestframework-0.2.3-py2.6.egg/djangorestframework/tests/mixins.py", line 75, in test_creation_with_m2m_relation_through
response = mixin.post(request)
File "/usr/lib/python2.6/site-packages/djangorestframework-0.2.3-py2.6.egg/djangorestframework/mixins.py", line 538, in post
instance.save()
File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 460, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 553, in save_base
result = manager._insert(values, return_id=update_pk, using=using)
File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line 195, in _insert
return insert_query(self.model, values, **kwargs)
File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 1436, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 791, in execute_sql
cursor = super(SQLInsertCompiler, self).execute_sql(None)
File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
cursor.execute(sql, params)
File "/usr/lib/python2.6/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 44, in execute
return self.cursor.execute(query, args)
DatabaseError: relation "tests_customuser" does not exist
LINE 1: INSERT INTO "tests_customuser" ("username") VALUES (E'bar0')
^

======================================================================
FAIL: test_creation_with_m2m_relation (djangorestframework.tests.modelviews.ModelViewTests)
Ensure that a model object with a m2m relation can be created
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/djangorestframework-0.2.3-py2.6.egg/djangorestframework/tests/modelviews.py", line 52, in test_creation_with_m2m_relation
self.assertEqual(0, User.objects.count())
AssertionError: 0 != 1

======================================================================
FAIL: test_creation_with_m2m_relation_through (djangorestframework.tests.modelviews.ModelViewTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/djangorestframework-0.2.3-py2.6.egg/djangorestframework/tests/modelviews.py", line 74, in test_creation_with_m2m_relation_through
self.assertEqual(0, User.objects.count())
AssertionError: 0 != 1

======================================================================
FAIL: test_creation_with_m2m_relation (djangorestframework.tests.mixins.TestModelCreation)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/djangorestframework-0.2.3-py2.6.egg/djangorestframework/tests/mixins.py", line 53, in test_creation_with_m2m_relation
self.assertEquals(1, User.objects.count())
AssertionError: 1 != 2

----------------------------------------------------------------------
Ran 429 tests in 11.309s