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


Python Fixture.load方法代码示例

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


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

示例1: test_fk_to_pk_value

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import load [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)
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:9,代码来源:tests_loaddata.py

示例2: test_empty_fixture

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import load [as 别名]
 def test_empty_fixture(self):
     # Since we allow dynamic populating of Fixture instances, loading
     # empty ones should not produce an error (unlike Django, where empty
     # fixture files will do that).
     band_fixture = Fixture(Band)
     band_fixture.load()
     self.assertEqual(Band.objects.count(), 0)
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:9,代码来源:tests_loaddata.py

示例3: test_natural_keys_to_preexisting_objects

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import load [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]]))
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:29,代码来源:tests_loaddata.py

示例4: test_single_m2m_to_pk_value

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import load [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)
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:10,代码来源:tests_loaddata.py

示例5: test_circular_dependency

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import load [as 别名]
 def test_circular_dependency(self):
     company_fixture = Fixture(Company)
     employee_fixture = Fixture(Employee)
     company_fixture.add(1, name='Dewey, Cheatem & Howe')
     # Trying to be each other's managers
     employee_fixture.add(1, name='Sly M. Ball', company=company_fixture.fk(1), manager=employee_fixture.fk(2))
     employee_fixture.add(2, name='Mei Ting', company=company_fixture.fk(1), manager=employee_fixture.fk(1))
     company_fixture.load()
     self.assertRaises(RelatedObjectError, employee_fixture.load)
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:11,代码来源:tests_loaddata.py

示例6: test_fk_relation

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import load [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])
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:12,代码来源:tests_loaddata.py

示例7: test_one_level_fk_hierarchy

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import load [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)
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:12,代码来源:tests_loaddata.py

示例8: test_o2o_to_preexisting_object

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import load [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])
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:12,代码来源:tests_loaddata.py

示例9: test_multiple_m2ms_to_pk_values

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import load [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)
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:12,代码来源:tests_loaddata.py

示例10: test_with_generated_relation

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import load [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

示例11: test_reverse_single_m2m_relation

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import load [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)
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:13,代码来源:tests_loaddata.py

示例12: test_two_level_fk_o2o_hierarchy_mixed

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import load [as 别名]
 def test_two_level_fk_o2o_hierarchy_mixed(self):
     # FK from Employee to Company, O2O from EmployeeHistory to Employee
     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)
     history_fixture = Fixture(EmployeeHistory)
     history_fixture.add(1, employee=employee_fixture.o2o(1), date_joined='2007-02-22')
     # Load in mixed order: 3rd, 1st, 2nd level
     history_fixture.load()
     self.assertEqual(Company.objects.count(), 1)
     self.assertEqual(Employee.objects.count(), 1)
     self.assertEqual(EmployeeHistory.objects.count(), 1)
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:15,代码来源:tests_loaddata.py

示例13: test_multiple_m2m_relations

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import load [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)
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:15,代码来源:tests_loaddata.py

示例14: test_with_explicit_relation_to_preexisting_object

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import load [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

示例15: test_with_explicit_delayed_m2m_relation

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import load [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


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