diff options
Diffstat (limited to 'test/orm/inheritance/test_poly_persistence.py')
| -rw-r--r-- | test/orm/inheritance/test_poly_persistence.py | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/test/orm/inheritance/test_poly_persistence.py b/test/orm/inheritance/test_poly_persistence.py index 6939479b1..5b5844b70 100644 --- a/test/orm/inheritance/test_poly_persistence.py +++ b/test/orm/inheritance/test_poly_persistence.py @@ -27,20 +27,20 @@ class PolymorphTest(fixtures.MappedTest): global companies, people, engineers, managers, boss companies = Table('companies', metadata, - Column('company_id', Integer, primary_key=True, + Column('company_id', Integer, primary_key=True, test_needs_autoincrement=True), Column('name', String(50))) people = Table('people', metadata, - Column('person_id', Integer, primary_key=True, + Column('person_id', Integer, primary_key=True, test_needs_autoincrement=True), - Column('company_id', Integer, ForeignKey('companies.company_id'), + Column('company_id', Integer, ForeignKey('companies.company_id'), nullable=False), Column('name', String(50)), Column('type', String(30))) engineers = Table('engineers', metadata, - Column('person_id', Integer, ForeignKey('people.person_id'), + Column('person_id', Integer, ForeignKey('people.person_id'), primary_key=True), Column('status', String(30)), Column('engineer_name', String(50)), @@ -48,14 +48,14 @@ class PolymorphTest(fixtures.MappedTest): ) managers = Table('managers', metadata, - Column('person_id', Integer, ForeignKey('people.person_id'), + Column('person_id', Integer, ForeignKey('people.person_id'), primary_key=True), Column('status', String(30)), Column('manager_name', String(50)) ) boss = Table('boss', metadata, - Column('boss_id', Integer, ForeignKey('managers.person_id'), + Column('boss_id', Integer, ForeignKey('managers.person_id'), primary_key=True), Column('golf_swing', String(30)), ) @@ -74,14 +74,14 @@ class InsertOrderTest(PolymorphTest): 'person':people.select(people.c.type=='person'), }, None, 'pjoin') - person_mapper = mapper(Person, people, - with_polymorphic=('*', person_join), - polymorphic_on=person_join.c.type, + person_mapper = mapper(Person, people, + with_polymorphic=('*', person_join), + polymorphic_on=person_join.c.type, polymorphic_identity='person') - mapper(Engineer, engineers, inherits=person_mapper, + mapper(Engineer, engineers, inherits=person_mapper, polymorphic_identity='engineer') - mapper(Manager, managers, inherits=person_mapper, + mapper(Manager, managers, inherits=person_mapper, polymorphic_identity='manager') mapper(Company, companies, properties={ 'employees': relationship(Person, @@ -113,16 +113,16 @@ class RoundTripTest(PolymorphTest): def _generate_round_trip_test(include_base, lazy_relationship, redefine_colprop, with_polymorphic): """generates a round trip test. - + include_base - whether or not to include the base 'person' type in the union. - + lazy_relationship - whether or not the Company relationship to People is lazy or eager. - + redefine_colprop - if we redefine the 'name' column to be 'people_name' on the base Person class - + use_literal_join - primary join condition is explicitly specified """ def test_roundtrip(self): @@ -158,21 +158,21 @@ def _generate_round_trip_test(include_base, lazy_relationship, manager_with_polymorphic = None if redefine_colprop: - person_mapper = mapper(Person, people, - with_polymorphic=person_with_polymorphic, - polymorphic_on=people.c.type, - polymorphic_identity='person', + person_mapper = mapper(Person, people, + with_polymorphic=person_with_polymorphic, + polymorphic_on=people.c.type, + polymorphic_identity='person', properties= {'person_name':people.c.name}) else: - person_mapper = mapper(Person, people, - with_polymorphic=person_with_polymorphic, - polymorphic_on=people.c.type, + person_mapper = mapper(Person, people, + with_polymorphic=person_with_polymorphic, + polymorphic_on=people.c.type, polymorphic_identity='person') - mapper(Engineer, engineers, inherits=person_mapper, + mapper(Engineer, engineers, inherits=person_mapper, polymorphic_identity='engineer') - mapper(Manager, managers, inherits=person_mapper, - with_polymorphic=manager_with_polymorphic, + mapper(Manager, managers, inherits=person_mapper, + with_polymorphic=manager_with_polymorphic, polymorphic_identity='manager') mapper(Boss, boss, inherits=Manager, polymorphic_identity='boss') @@ -190,19 +190,19 @@ def _generate_round_trip_test(include_base, lazy_relationship, person_attribute_name = 'name' employees = [ - Manager(status='AAB', manager_name='manager1', + Manager(status='AAB', manager_name='manager1', **{person_attribute_name:'pointy haired boss'}), - Engineer(status='BBA', engineer_name='engineer1', - primary_language='java', + Engineer(status='BBA', engineer_name='engineer1', + primary_language='java', **{person_attribute_name:'dilbert'}), ] if include_base: employees.append(Person(**{person_attribute_name:'joesmith'})) employees += [ - Engineer(status='CGG', engineer_name='engineer2', - primary_language='python', + Engineer(status='CGG', engineer_name='engineer2', + primary_language='python', **{person_attribute_name:'wally'}), - Manager(status='ABA', manager_name='manager2', + Manager(status='ABA', manager_name='manager2', **{person_attribute_name:'jsmith'}) ] @@ -222,7 +222,7 @@ def _generate_round_trip_test(include_base, lazy_relationship, session.expunge_all() eq_(session.query(Person).filter( - Person.person_id==dilbert.person_id).one(), + Person.person_id==dilbert.person_id).one(), dilbert) session.expunge_all() @@ -242,9 +242,9 @@ def _generate_round_trip_test(include_base, lazy_relationship, else: self.assert_sql_count(testing.db, go, 6) - # test selecting from the query, using the base + # test selecting from the query, using the base # mapped table (people) as the selection criterion. - # in the case of the polymorphic Person query, + # in the case of the polymorphic Person query, # the "people" selectable should be adapted to be "person_join" eq_( session.query(Person).filter( @@ -264,9 +264,9 @@ def _generate_round_trip_test(include_base, lazy_relationship, dilbert ) - # test selecting from the query, joining against + # test selecting from the query, joining against # an alias of the base "people" table. test that - # the "palias" alias does *not* get sucked up + # the "palias" alias does *not* get sucked up # into the "person_join" conversion. palias = people.alias("palias") dilbert = session.query(Person).get(dilbert.person_id) @@ -287,35 +287,35 @@ def _generate_round_trip_test(include_base, lazy_relationship, session.expunge_all() def go(): - session.query(Person).filter(getattr(Person, + session.query(Person).filter(getattr(Person, person_attribute_name)=='dilbert').first() self.assert_sql_count(testing.db, go, 1) session.expunge_all() - dilbert = session.query(Person).filter(getattr(Person, + dilbert = session.query(Person).filter(getattr(Person, person_attribute_name)=='dilbert').first() def go(): - # assert that only primary table is queried for + # assert that only primary table is queried for # already-present-in-session - d = session.query(Person).filter(getattr(Person, + d = session.query(Person).filter(getattr(Person, person_attribute_name)=='dilbert').first() self.assert_sql_count(testing.db, go, 1) # test standalone orphans - daboss = Boss(status='BBB', - manager_name='boss', - golf_swing='fore', + daboss = Boss(status='BBB', + manager_name='boss', + golf_swing='fore', **{person_attribute_name:'daboss'}) session.add(daboss) assert_raises(sa_exc.DBAPIError, session.flush) c = session.query(Company).first() daboss.company = c - manager_list = [e for e in c.employees + manager_list = [e for e in c.employees if isinstance(e, Manager)] session.flush() session.expunge_all() - eq_(session.query(Manager).order_by(Manager.person_id).all(), + eq_(session.query(Manager).order_by(Manager.person_id).all(), manager_list) c = session.query(Company).first() @@ -337,11 +337,11 @@ for lazy_relationship in [True, False]: for with_polymorphic in ['unions', 'joins', 'auto', 'none']: if with_polymorphic == 'unions': for include_base in [True, False]: - _generate_round_trip_test(include_base, - lazy_relationship, + _generate_round_trip_test(include_base, + lazy_relationship, redefine_colprop, with_polymorphic) else: - _generate_round_trip_test(False, - lazy_relationship, + _generate_round_trip_test(False, + lazy_relationship, redefine_colprop, with_polymorphic) |
