コード例 #1
0
 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
0
 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
0
 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
0
 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
0
 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
0
    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
0
    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
0
 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
0
 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
0
# 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
0
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
0
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
0
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
0
"""

    @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="*****@*****.**",
        password="******",
        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
0
 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))