django - 使用 from django.contrib.auth.models import User 进行测试时出错

标签 django testing django-models tdd traceback

我正在使用 django.contrib.auth 并遇到以下错误:

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'...

查看我的模型。

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

我怀疑这个错误与用户有关。

最佳答案

据我了解,您打算让 Employee 模型基于 Person 抽象模型而不是 UserProfile:

class Employee(Person):
    ...

关于django - 使用 from django.contrib.auth.models import User 进行测试时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28292339/

相关文章:

python - Django 唯一的、空的和空白的 CharField 在管理页面上给出 'already exists' 错误

django - 从 pickle 数据加载会导致新保存的数据库错误

Django基于M2M关系上的多个字段注释多个对象

c++ - 暴力破解不同输入导致程序崩溃的策略是什么?

android - 收到一条错误消息使用 Android 位置服务模拟位置

ruby-on-rails - capybara ,在 css 元素中查找

django - 如何从数据库中删除大量对象

python - 从多对多字段中获取对象

mysql - django - 记录未保存在 MySQL 数据库中但自动增量增加

python - Django ckeditor 无法添加 youtube 插件