正在处理基于配置的django包,它将添加关系,例如
@receiver(class_prepared, dispatch_uid='add_store_fields')
def add_store_fields(sender, **kwargs):
""" add_store_fields
"""
if sender.__name__ == 'Store':
# allowing multiple stores in installation
if settings.SHOPLER_STORE_FOREIGN_KEY:
field = models.ForeignKey(settings.SHOPLER_STORE_FOREIGN_KEY)
field.contribute_to_class(sender, "store_owner")
我正在尝试为此构建测试用例,因此我会在指定SHOPLER_STORE_FOREIGN_KEY时运行测试用例,而不是。为此,我做了以下
class SingleStoreModeTestCase(TestCase):
""" SingleStoreModeTestCase
single store mode is tests performed when store is singular by design
"""
def setUp(self):
""" setup """
@override_settings(SHOPLER_STORE_FOREIGN_KEY=None)
def test_forieng_key_installed_correctly(self):
""" test_forieng_key_installed_correctly
"""
print hasattr(Store, 'store_owner')
self.assertEqual(1, 1, '')
class MultiStoreModeTestCase(TestCase):
""" MultiStoreModeTestCase
single store mode is tests performed when store is singular by design
"""
def setUp(self):
""" setup """
@override_settings(SHOPLER_STORE_FOREIGN_KEY=settings.AUTH_USER_MODEL)
def test_forieng_key_installed_correctly(self):
""" test_forieng_key_installed_correctly
"""
print hasattr(Store, 'store_owner')
self.assertEqual(1, 1, '')
我遇到的问题是,override_settings只是将它传递给函数,因此模式的启动发生在较早的步骤。如何使用设置覆盖强制架构在每个测试用例上重建?有谁可以提供建议?
谢谢,