本文整理汇总了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())
示例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')
示例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)
示例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)