Search code examples
djangotestingdjango-modelstddtraceback

Error in test using from django.contrib.auth.models import User


I am using the django.contrib.auth and came across the following error:

Creating test database for alias 'default'...
...EE..
======================================================================
ERROR: test_create (new_way.core.tests.test_models.EmployeeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/rg3915/git/my/new_way_project/new_way/core/tests/test_models.py", line 121, in setUp
    comission=180.5
  File "/home/rg3915/git/my/new_way_project/lib/python3.4/site-packages/django/db/models/base.py", line 452, in __init__
    raise TypeError("'%s' is an invalid keyword argument for this function" % list(kwargs)[0])
TypeError: 'birthday' is an invalid keyword argument for this function

======================================================================
ERROR: test_has_created_at (new_way.core.tests.test_models.EmployeeTest)
Employee must have automatic created_at
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/rg3915/git/my/new_way_project/new_way/core/tests/test_models.py", line 121, in setUp
    comission=180.5
  File "/home/rg3915/git/my/new_way_project/lib/python3.4/site-packages/django/db/models/base.py", line 452, in __init__
    raise TypeError("'%s' is an invalid keyword argument for this function" % list(kwargs)[0])
TypeError: 'birthday' is an invalid keyword argument for this function

----------------------------------------------------------------------
Ran 7 tests in 0.010s

FAILED (errors=2)
Destroying test database for alias 'default'...

See my models.

https://gist.github.com/rg3915/1f8094c5e3626ae56386

I suspect this error related to the User.


Solution

  • As far as I understand, you intended to have the Employee model being based on the Person abstract model and not the UserProfile:

    class Employee(Person):
        ...