本文整理汇总了Python中class_fixtures.models.Fixture.add方法的典型用法代码示例。如果您正苦于以下问题:Python Fixture.add方法的具体用法?Python Fixture.add怎么用?Python Fixture.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类class_fixtures.models.Fixture
的用法示例。
在下文中一共展示了Fixture.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fk_to_pk_value
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add [as 别名]
def test_fk_to_pk_value(self):
company = Company.objects.create(name='Macrohard')
employee_fixture = Fixture(Employee)
employee_fixture.add(1, name='Andy Depressant', company=1, manager=None)
employee_fixture.load()
self.assertEqual(Employee.objects.count(), 1)
self.assertTrue(Employee.objects.all()[0].company == company)
示例2: test_illegal_reverse_fk_assignment
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add [as 别名]
def test_illegal_reverse_fk_assignment(self):
employee_fixture = Fixture(Employee)
# This specific example would fail at the Django level due to
# Employee.company not being null=True, but we expect failure before
# getting to that level, so using Employee for this is fine.
employee_fixture.add(1, name='Andy Depressant', manager=None)
company_fixture = Fixture(Company)
self.assertRaises(RelatedObjectError, company_fixture.add, 1, name='Macrohard', employee_set=employee_fixture.fk(1))
示例3: test_single_m2m_to_pk_value
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add [as 别名]
def test_single_m2m_to_pk_value(self):
band = Band.objects.create(pk=1, name="Nuns N' Hoses")
roadie_fixture = Fixture(Roadie)
roadie_fixture.add(1, name='Marshall Amp', hauls_for=[1])
roadie_fixture.load()
self.assertEqual(Roadie.objects.count(), 1)
self.assertEqual(Roadie.objects.get(name='Marshall Amp').hauls_for.filter(name="Nuns N' Hoses").count(), 1)
self.assertEqual(Band.objects.get(name="Nuns N' Hoses").roadie_set.filter(name='Marshall Amp').count(), 1)
示例4: test_fk_relation
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add [as 别名]
def test_fk_relation(self):
company_fixture = Fixture(Company)
company_fixture.add(1, name='Macrohard')
employee_fixture = Fixture(Employee)
employee_fixture.add(1, name='Andy Depressant', company=company_fixture.fk(1), manager=None)
company_fixture.load()
employee_fixture.load()
self.assertEqual(Company.objects.count(), 1)
self.assertEqual(Employee.objects.count(), 1)
self.assertTrue(Employee.objects.all()[0].company == Company.objects.all()[0])
示例5: test_o2o_to_preexisting_object
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add [as 别名]
def test_o2o_to_preexisting_object(self):
company = Company.objects.create(pk=1, name='Macrohard')
employee = Employee.objects.create(pk=1, name='Andy Depressant', company=company, manager=None)
history_fixture = Fixture(EmployeeHistory)
history_fixture.add(1, employee=employee, date_joined='2007-02-22')
history_fixture.load()
self.assertEqual(Company.objects.count(), 1)
self.assertEqual(Employee.objects.count(), 1)
self.assertEqual(EmployeeHistory.objects.count(), 1)
self.assertEqual(Employee.objects.all()[0].employeehistory, EmployeeHistory.objects.all()[0])
示例6: test_multiple_m2ms_to_pk_values
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add [as 别名]
def test_multiple_m2ms_to_pk_values(self):
band1 = Band.objects.create(pk=1, name="Nuns N' Hoses")
band2 = Band.objects.create(pk=2, name='Led Dirigible')
roadie_fixture = Fixture(Roadie)
roadie_fixture.add(1, name='Marshall Amp', hauls_for=[1, 2])
roadie_fixture.load()
self.assertEqual(Roadie.objects.count(), 1)
self.assertEqual(Roadie.objects.get(name='Marshall Amp').hauls_for.count(), 2)
self.assertEqual(Band.objects.get(name="Nuns N' Hoses").roadie_set.count(), 1)
self.assertEqual(Band.objects.get(name='Led Dirigible').roadie_set.count(), 1)
示例7: test_one_level_fk_hierarchy
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add [as 别名]
def test_one_level_fk_hierarchy(self):
# FK from Employee to Company
company_fixture = Fixture(Company)
company_fixture.add(1, name='Macrohard')
employee_fixture = Fixture(Employee)
employee_fixture.add(1, name='Andy Depressant', company=company_fixture.fk(1), manager=None)
# Load in reverse order: 2nd, 1st level
employee_fixture.load()
self.assertEqual(Company.objects.count(), 1)
self.assertEqual(Employee.objects.count(), 1)
示例8: test_reverse_single_m2m_relation
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add [as 别名]
def test_reverse_single_m2m_relation(self):
roadie_fixture = Fixture(Roadie)
roadie_fixture.add(1, name='Marshall Amp')
band_fixture = Fixture(Band)
band_fixture.add(1, name="Nuns N' Hoses", roadie_set=[roadie_fixture.m2m(1)])
roadie_fixture.load()
band_fixture.load()
self.assertEqual(Band.objects.count(), 1)
self.assertEqual(Roadie.objects.count(), 1)
self.assertEqual(Roadie.objects.get(name='Marshall Amp').hauls_for.filter(name="Nuns N' Hoses").count(), 1)
self.assertEqual(Band.objects.get(name="Nuns N' Hoses").roadie_set.filter(name='Marshall Amp').count(), 1)
示例9: test_multiple_m2m_relations
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add [as 别名]
def test_multiple_m2m_relations(self):
band_fixture = Fixture(Band)
band_fixture.add(1, name="Nuns N' Hoses")
band_fixture.add(2, name='Led Dirigible')
roadie_fixture = Fixture(Roadie)
roadie_fixture.add(1, name='Marshall Amp', hauls_for=[band_fixture.m2m(1), band_fixture.m2m(2)])
band_fixture.load()
roadie_fixture.load()
self.assertEqual(Band.objects.count(), 2)
self.assertEqual(Roadie.objects.count(), 1)
self.assertEqual(Roadie.objects.get(name='Marshall Amp').hauls_for.count(), 2)
self.assertEqual(Band.objects.get(name="Nuns N' Hoses").roadie_set.count(), 1)
self.assertEqual(Band.objects.get(name='Led Dirigible').roadie_set.count(), 1)
示例10: test_multiple_m2ms_to_mixed_fixture_pk_preexisting
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add [as 别名]
def test_multiple_m2ms_to_mixed_fixture_pk_preexisting(self):
band1 = Band.objects.create(pk=1, name="Nuns N' Hoses")
band2_fixture = Fixture(Band)
band2_fixture.add(2, name='Led Dirigible')
band3 = Band.objects.create(pk=3, name='Bar Fighters')
roadie_fixture = Fixture(Roadie)
roadie_fixture.add(1, name='Marshall Amp', hauls_for=[band1, band2_fixture.fk(2), 3])
roadie_fixture.load()
self.assertEqual(Band.objects.count(), 3)
self.assertEqual(Roadie.objects.count(), 1)
self.assertEqual(Roadie.objects.get(name='Marshall Amp').hauls_for.count(), 3)
self.assertEqual(Band.objects.get(name="Nuns N' Hoses").roadie_set.count(), 1)
self.assertEqual(Band.objects.get(name='Led Dirigible').roadie_set.count(), 1)
self.assertEqual(Band.objects.get(name='Bar Fighters').roadie_set.count(), 1)
示例11: test_with_explicit_delayed_m2m_relation
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add [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')
示例12: test_with_explicit_delayed_fk_relation
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add [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)
示例13: test_alternate_database
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add [as 别名]
def test_alternate_database(self):
"""
Explicitly assign fixtures to a non-default database.
"""
if self.do_tests:
band_fixture = Fixture(Band)
band_fixture.add(1, name="Nuns N' Hoses")
band_fixture.add(2, name='Led Dirigible')
roadie_fixture = Fixture(Roadie)
roadie_fixture.add(1, name='Marshall Amp', hauls_for=[band_fixture.m2m(1), band_fixture.m2m(2)])
call_command('loaddata', band_fixture, roadie_fixture, database='alternate', verbosity=0)
self.assertEqual(Band.objects.using('alternate').count(), 2)
self.assertEqual(Roadie.objects.using('alternate').count(), 1)
self.assertEqual(Band.objects.count(), 0)
self.assertEqual(Roadie.objects.count(), 0)
self.assertEqual(Roadie.objects.using('alternate').get(name='Marshall Amp').hauls_for.count(), 2)
self.assertEqual(Band.objects.using('alternate').get(name="Nuns N' Hoses").roadie_set.count(), 1)
self.assertEqual(Band.objects.using('alternate').get(name='Led Dirigible').roadie_set.count(), 1)
示例14: test_m2m_dependent_first
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add [as 别名]
def test_m2m_dependent_first(self):
# The above FK tests already apply to explicit "through" M2Ms, so this
# only tests normal, "non-through" ones.
band_fixture = Fixture(Band)
band_fixture.add(1, name="Nuns N' Hoses")
band_fixture.add(2, name='Led Dirigible')
roadie_fixture = Fixture(Roadie)
roadie_fixture.add(1, name='Marshall Amp', hauls_for=[band_fixture.m2m(1), band_fixture.m2m(2)])
# M2M relations are two-way, but like only one end has the
# ManyToManyField, the fixture dependency is also defined in one end
# of the relation. roadie_fixture is the dependent here, load it first
# to test proper dependency resolution.
roadie_fixture.load()
self.assertEqual(Band.objects.count(), 2)
self.assertEqual(Roadie.objects.count(), 1)
self.assertEqual(Roadie.objects.get(name='Marshall Amp').hauls_for.count(), 2)
self.assertEqual(Band.objects.get(name="Nuns N' Hoses").roadie_set.count(), 1)
self.assertEqual(Band.objects.get(name='Led Dirigible').roadie_set.count(), 1)
示例15: test_natural_keys_to_preexisting_objects
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import add [as 别名]
def test_natural_keys_to_preexisting_objects(self):
rails_n00b = Competency.objects.create(framework='Ruby on Rails', level=1)
cake_adept = Competency.objects.create(framework='CakePHP', level=2)
spring_master = Competency.objects.create(framework='Spring', level=3)
django_guru = Competency.objects.create(framework='Django', level=4)
jobs = Fixture(JobPosting)
# No M2M
jobs.add(1, title='Rails Intern', main_competency=('Ruby on Rails', 1))
# Single M2M with a tuple in a single-item list
jobs.add(2, title='Elder Django Deity', main_competency=('Django', 4),
additional_competencies=[('Ruby on Rails', 1)])
# Several M2Ms with a list of tuples
jobs.add(3, title='A man of many talents', main_competency=('Spring', 3),
additional_competencies=[('CakePHP', 2), ('Ruby on Rails', 1)]
)
jobs.load()
self.assertEqual(JobPosting.objects.count(), 3)
no_m2m_job = JobPosting.objects.get(pk=1)
self.assertEqual(no_m2m_job.main_competency, rails_n00b)
single_m2m_job = JobPosting.objects.get(pk=2)
self.assertEqual(single_m2m_job.additional_competencies.count(), 1)
self.assertTrue(rails_n00b in single_m2m_job.additional_competencies.all())
multi_m2m_job = JobPosting.objects.get(pk=3)
self.assertEqual(multi_m2m_job.additional_competencies.count(), 2)
self.assertTrue(all([c in multi_m2m_job.additional_competencies.all() for c in [cake_adept, rails_n00b]]))