gpt4 book ai didi

django - Django 1.6.5 和 factory_boy 的异常

转载 作者:行者123 更新时间:2023-12-01 01:00:34 26 4
gpt4 key购买 nike

我决定在我的简单 django 应用程序中使用 factory_boy 进行测试。
但我有一个简单的例子的问题。这是我的简单测试的代码。

from django.utils import unittest
from ..models import Server, ServerAddress, L2TPServer, serialize_open_vpn_server_json

from factory import django as django_factory


class SshOpenVpnServerFactory(django_factory.DjangoModelFactory):
class Meta:
model = L2TPServer
django_get_or_create = ('name', 'address')

name = 'Hello'
address = 'Nono'


class ServersTestCase(unittest.TestCase):

def test_serialize_server_info(self):
print Server.objects.all()
SshOpenVpnServerFactory.build()

当 test-runner 执行这个测试时,我收到一个错误:
Traceback (most recent call last):
File "/Users/green/Development/Wasel/experimental/wasel_services/packages/waselcore/backend/tests/test_models.py", line 20, in test_serialize_server_info
SshOpenVpnServerFactory.build()
File "/Users/green/Development/Wasel/experimental/env/wasel_sevices/lib/python2.7/site-packages/factory/base.py", line 504, in build
attrs = cls.attributes(create=False, extra=kwargs)
File "/Users/green/Development/Wasel/experimental/env/wasel_sevices/lib/python2.7/site-packages/factory/base.py", line 365, in attributes
force_sequence=force_sequence,
File "/Users/green/Development/Wasel/experimental/env/wasel_sevices/lib/python2.7/site-packages/factory/containers.py", line 265, in build
sequence = self.factory._generate_next_sequence()
File "/Users/green/Development/Wasel/experimental/env/wasel_sevices/lib/python2.7/site-packages/factory/base.py", line 338, in _generate_next_sequence
cls._setup_counter()
File "/Users/green/Development/Wasel/experimental/env/wasel_sevices/lib/python2.7/site-packages/factory/base.py", line 318, in _setup_counter
first_seq = cls._setup_next_sequence()
File "/Users/green/Development/Wasel/experimental/env/wasel_sevices/lib/python2.7/site-packages/factory/django.py", line 83, in _setup_next_sequence
manager = cls._get_manager(model)
File "/Users/green/Development/Wasel/experimental/env/wasel_sevices/lib/python2.7/site-packages/factory/django.py", line 76, in _get_manager
return target_class.objects
AttributeError: 'NoneType' object has no attribute 'objects'

我哪里错了? factory_boy 支持 django 1.6.5 吗?

最佳答案

建议的语法使用 Meta class 将仅作为(未发布的)Factory Boy 2.4 的一部分发布。使用 SshOpenVpnServerFactory.FACTORY_FOR反而。相关问题:https://github.com/rbarrois/factory_boy/issues/143

关于django - Django 1.6.5 和 factory_boy 的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23826382/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com