本文整理汇总了Python中class_fixtures.models.Fixture.fk方法的典型用法代码示例。如果您正苦于以下问题:Python Fixture.fk方法的具体用法?Python Fixture.fk怎么用?Python Fixture.fk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类class_fixtures.models.Fixture
的用法示例。
在下文中一共展示了Fixture.fk方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_circular_dependency
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import fk [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)
示例2: test_raw_mode
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import fk [as 别名]
def test_raw_mode(self):
company_fixture = Fixture(Company)
company_fixture.add(1, name='Bloatware Corporation')
employee_fixture = Fixture(Employee)
employee_fixture.add(1, name='Andy Depressant', company=company_fixture.fk(1), manager=None)
# Due to raw=True, the custom save() method that sets
# 'cog_in_the_machine' to True should not get run.
raw_employee_fixture = Fixture(Employee, raw=True)
raw_employee_fixture.add(2, name='Sadie Peon', company=company_fixture.fk(1), manager=None)
company_fixture.load()
employee_fixture.load()
raw_employee_fixture.load()
self.assertEqual(Employee.objects.count(), 2)
normal = Employee.objects.get(name='Andy Depressant')
raw = Employee.objects.get(name='Sadie Peon')
self.assertEqual(normal.cog_in_the_machine, True)
self.assertEqual(raw.cog_in_the_machine, False)
示例3: test_fk_relation
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import fk [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])
示例4: test_one_level_fk_hierarchy
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import fk [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)
示例5: test_two_level_fk_o2o_hierarchy_mixed
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import fk [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)
示例6: test_with_explicit_delayed_m2m_relation
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import fk [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')
示例7: test_with_explicit_delayed_fk_relation
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import fk [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)
示例8: test_multiple_m2ms_to_mixed_fixture_pk_preexisting
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import fk [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)
示例9: test_o2o_relation
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import fk [as 别名]
def test_o2o_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)
history_fixture = Fixture(EmployeeHistory)
history_fixture.add(1, employee=employee_fixture.o2o(1), date_joined='2007-02-22')
company_fixture.load()
employee_fixture.load()
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])
示例10: Fixture
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import fk [as 别名]
# The fixtures in this file will be loaded during a syncdb operation.
from class_fixtures.models import Fixture
from class_fixtures.tests.models import Party, Politician
initial_party = Fixture(Party)
initial_politician = Fixture(Politician)
initial_party.add(2, name="The People's Technocratic Party of Vinnland")
initial_politician.add(2, name="Petrus T. Ratajczyk", party=initial_party.fk(2))
示例11: Fixture
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import fk [as 别名]
from class_fixtures.models import Fixture
from class_fixtures.tests.models import Company, Employee, EmployeeHistory
company_fixture = Fixture(Company)
employee_fixture = Fixture(Employee)
employee_history_fixture = Fixture(EmployeeHistory)
company_fixture.add(3, name="Dewey, Cheatem & Howe")
employee_fixture.add(5, name="Sly M. Ball", company=company_fixture.fk(3))
employee_fixture.add(6, name="Mei Ting", company=company_fixture.fk(3), manager=employee_fixture.fk(5))
employee_history_fixture.add(5, employee=employee_fixture.o2o(5), date_joined="2000-11-03")
employee_history_fixture.add(6, employee=employee_fixture.o2o(6), date_joined="1985-12-28")
示例12: Fixture
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import fk [as 别名]
from class_fixtures.models import Fixture
from class_fixtures.tests.models import *
membership_fixture = Fixture(Membership)
band_fixture = Fixture(Band)
musician_fixture = Fixture(Musician)
band_fixture.add(6, name="R.A.M.")
musician_fixture.add(7, name="Michael Skype")
# Keyword-based FK target lookup
membership_fixture.add(9,
musician = musician_fixture.fk(7),
band = band_fixture.fk(6),
date_joined = '1980-05-19',
instrument = "Voice",
)
示例13: Fixture
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import fk [as 别名]
membership_fixture = Fixture(Membership)
band_fixture = Fixture(Band)
metalband_fixture = Fixture(MetalBand)
musician_fixture = Fixture(Musician)
roadie_fixture = Fixture(Roadie)
band_fixture.add(5, name="Bar Fighters")
metalband_fixture.add(6, name="Brutallica", leather_pants_worn=True)
musician_fixture.add(5, name="Hamish Jetfield")
musician_fixture.add(6, name="Dave Growl")
# Keyword-based FK target lookup
membership_fixture.add(
7, musician=musician_fixture.fk(6), band=band_fixture.fk(5), date_joined="2000-04-01", instrument="All of them"
)
# Relation token -based FK target lookup
membership_fixture.add(
8,
musician=musician_fixture.fk(5),
band=metalband_fixture.fk(6),
date_joined="1982-03-03",
instrument="Guitarrrr-ahh",
)
# Single M2M addition with a kwarg
roadie_fixture.add(3, name="Tats Brimhat", hauls_for=[band_fixture.m2m(5)])
# Two M2M additions with a list of kwargs
示例14: Fixture
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import fk [as 别名]
"""
@author Nils Sohn
"""
from class_fixtures.models import Fixture
from registration.models import ShareZone, User
# Create Class Fixtures for User and Share Zone
user_l = Fixture(User)
zones = Fixture(ShareZone)
# Add an instance of a Share Zone to the Fixture
# Add the Share Zone into the User Fixture with other details
zones.add(1, zone = "14623")
user_l.add(
1,
first_name="Tall",
last_name="Paul",
email="[email protected]",
password="12345678",
zipcode="14623",
pick_up="My house",
my_zone=zones.fk(1),
question1="What is your mother's maiden name?",
answer1="I'm adopted",
question2="Where did your parents meet?",
answer2="My dad was a sperm doner"
)
示例15: test_illegal_reverse_fk_assignment
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import fk [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))