Thomas
Thomas

Reputation: 2276

Tests on Django 1.5 with AUTH_USER_MODEL

I migrated my django application to Django 1.5. I configured AUTH_USER_MODEL and everything looks fine, but when I tried to create some tests I got the following error:

DatabaseError: (1146, "Table 'test_X.auth_user' doesn't exist")

tests.py

class XXTest(unittest.TestCase):

    def setUp(self):
        self.data= {
            'password1':'aaaaa',
            'password2':'aaaaa',                
            'city':'NY', (....)

        }
        self.client = Client()

    def test_register(self):
        c = Client()
        resp = self.client.post('/register/user/', self.data)
        self.assertEqual(resp.status_code, 200)

Settings.py

    INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
  ...
    'myuser',
)
AUTH_USER_MODEL = 'myuser.MyUser'

I am using MySQL, in fact the table myuser isn't being created in test database. If I run python manage.py migrate I get no error. But If I run:

python manage.py syncdb

Syncing...
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)

Synced:
 > django.contrib.auth
 > django.contrib.contenttypes
 > django.contrib.sessions
 > django.contrib.sites
 > django.contrib.messages
 > django.contrib.staticfiles
 > django.contrib.admin
 > django.contrib.flatpages
 > django.contrib.sitemaps

... Not synced (use migrations): ...

- myuser
(use ./manage.py migrate to migrate these)

How can I make my tests working properly?

Upvotes: 4

Views: 2486

Answers (1)

Douglas Miranda
Douglas Miranda

Reputation: 341

You have to create your Custom User on the myuser/models.py

Just like https://docs.djangoproject.com/en/dev/topics/auth/customizing/#a-full-example

Upvotes: 4

Related Questions