小编use*_*703的帖子

在Django中加载Selenium测试夹具时的完整性错误

我想为我的硒测试加载一个夹具.在我的初始测试中使用灯具是成功的,所以我知道我能够在我的测试设置中加载灯具并在我的测试中使用它们.我尝试了几种方法.首先,我生成了特定于我使用dumpdata测试的模型的灯具.一个例子如下:

python manage.py dumpdata protocols.Step --indent=2 > functional_tests/fixtures/step.json
Run Code Online (Sandbox Code Playgroud)

在我的测试中用作如下:

class SignInTest(FunctionalTest):
    fixtures = ['admin_user.json', 'protocol.json', 'step.json',
             'protocol_element.json']

    def test_login_and_view_user_data(self):
        ...
Run Code Online (Sandbox Code Playgroud)

我收到错误:

django.db.utils.IntegrityError: Problem installing fixtures: The row in table 'protocols_protocolelement' with primary key '37' has an invalid foreign key: protocols_protocolelement.element_content_type_id contains a value '41' that does not have a corresponding value in django_content_type.id.
Run Code Online (Sandbox Code Playgroud)

第二次尝试涉及在我的表中使用所有测试数据,但不包括contenttypes:

python manage.py dumpdata --indent=2 -e contenttypes > functional_tests/fixtures/initial_data.json

class SignInTest(FunctionalTest):
    fixtures = ['initial_data.json']
    ...
Run Code Online (Sandbox Code Playgroud)

得到错误:

django.db.utils.OperationalError: Problem installing fixture '.../mike/mike/functional_tests/fixtures/initial_data.json': Could not load auth.Permission(pk=103): no such …
Run Code Online (Sandbox Code Playgroud)

django selenium fixtures django-testing

7
推荐指数
1
解决办法
2562
查看次数

标签 统计

django ×1

django-testing ×1

fixtures ×1

selenium ×1