当前位置: 首页>>代码示例>>Python>>正文


Python Fixture.add_random方法代码示例

本文整理汇总了Python中class_fixtures.models.Fixture.add_random方法的典型用法代码示例。如果您正苦于以下问题:Python Fixture.add_random方法的具体用法?Python Fixture.add_random怎么用?Python Fixture.add_random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在class_fixtures.models.Fixture的用法示例。


在下文中一共展示了Fixture.add_random方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_with_generated_relation

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add_random [as 别名]
 def test_with_generated_relation(self):
     if self.milkman_found:
         employee_fixture = Fixture(Employee)
         employee_fixture.add_random(1)
         employee_fixture.load()
         self.assertEqual(Employee.objects.count(), 1)
         # Since the Company FK is required, there should be one of those
         # around as well
         self.assertEqual(Company.objects.count(), 1)
         # And that company should be connected to the employee
         self.assertTrue(Employee.objects.all()[0] in Company.objects.all()[0].employee_set.all())
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:13,代码来源:tests_loaddata.py

示例2: test_with_explicit_delayed_m2m_relation

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add_random [as 别名]
    def test_with_explicit_delayed_m2m_relation(self):
        if self.milkman_found:
            band_fixture = Fixture(Band)
            roadie_fixture = Fixture(Roadie)

            band_fixture.add(1, name='Bar Fighters')
            # Name will be random
            roadie_fixture.add_random(1, hauls_for=[band_fixture.fk(1)])
            roadie_fixture.load()

            self.assertEqual(Band.objects.count(), 1)
            self.assertEqual(Roadie.objects.count(), 1)
            self.assertEqual(Roadie.objects.get(pk=1).hauls_for.count(), 1)
            self.assertEqual(Roadie.objects.get(pk=1).hauls_for.all()[0].name, 'Bar Fighters')
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:16,代码来源:tests_loaddata.py

示例3: test_with_explicit_relation_to_preexisting_object

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add_random [as 别名]
    def test_with_explicit_relation_to_preexisting_object(self):
        if self.milkman_found:
            company = Company.objects.create(name='Macrohard')
            manager = Employee.objects.create(name='Sue Ecide-Note', company=company, manager=None)

            employee_fixture = Fixture(Employee)
            # Name will be random
            employee_fixture.add_random(2, company=company, manager=manager)
            employee_fixture.load()

            self.assertEqual(Company.objects.count(), 1)
            self.assertEqual(Employee.objects.count(), 2)
            self.assertEqual(manager.employee_set.count(), 1)
            self.assertEqual(company.employee_set.count(), 2)
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:16,代码来源:tests_loaddata.py

示例4: test_with_explicit_delayed_fk_relation

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add_random [as 别名]
    def test_with_explicit_delayed_fk_relation(self):
        if self.milkman_found:
            company_fixture = Fixture(Company)
            employee_fixture = Fixture(Employee)

            company_fixture.add(1, name='Macrohard')
            # Name will be random
            employee_fixture.add_random(1, company=company_fixture.fk(1), manager=None)
            employee_fixture.load()

            self.assertEqual(Company.objects.count(), 1)
            self.assertEqual(Employee.objects.count(), 1)
            company = Company.objects.get(pk=1)
            self.assertEqual(company.employee_set.count(), 1)
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:16,代码来源:tests_loaddata.py


注:本文中的class_fixtures.models.Fixture.add_random方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。