From: Mike Bayer Date: Tue, 14 Apr 2020 19:30:28 +0000 (-0400) Subject: Pass connection to TablesTest.insert_data() X-Git-Tag: rel_1_3_17~27^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3294998c6458fce28526fef99386e395bbdc745a;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Pass connection to TablesTest.insert_data() towards the goal of reducing verbosity and repetition in test fixtures as well as that we are moving to connection only for execution, move the insert_data() classmethod to accept a connection and adjust all fixtures to use it. Change-Id: I3bf534acca0d5f4cda1d4da8ae91f1155b829b09 (cherry picked from commit 5c010c097352c783729e210018b95130ef94a926) --- diff --git a/lib/sqlalchemy/testing/fixtures.py b/lib/sqlalchemy/testing/fixtures.py index 4f60834019..e5e6c42fc0 100644 --- a/lib/sqlalchemy/testing/fixtures.py +++ b/lib/sqlalchemy/testing/fixtures.py @@ -135,7 +135,8 @@ class TablesTest(TestBase): def _setup_once_inserts(cls): if cls.run_inserts == "once": cls._load_fixtures() - cls.insert_data() + with cls.bind.begin() as conn: + cls.insert_data(conn) @classmethod def _setup_once_tables(cls): @@ -157,7 +158,8 @@ class TablesTest(TestBase): def _setup_each_inserts(self): if self.run_inserts == "each": self._load_fixtures() - self.insert_data() + with self.bind.begin() as conn: + self.insert_data(conn) def _teardown_each_tables(self): if self.run_define_tables == "each": @@ -224,7 +226,7 @@ class TablesTest(TestBase): return {} @classmethod - def insert_data(cls): + def insert_data(cls, connection): pass def sql_count_(self, count, fn): diff --git a/lib/sqlalchemy/testing/suite/test_cte.py b/lib/sqlalchemy/testing/suite/test_cte.py index 012de7911d..2dbb540f9c 100644 --- a/lib/sqlalchemy/testing/suite/test_cte.py +++ b/lib/sqlalchemy/testing/suite/test_cte.py @@ -36,8 +36,8 @@ class CTETest(fixtures.TablesTest): ) @classmethod - def insert_data(cls): - config.db.execute( + def insert_data(cls, connection): + connection.execute( cls.tables.some_table.insert(), [ {"id": 1, "data": "d1", "parent_id": None}, diff --git a/lib/sqlalchemy/testing/suite/test_results.py b/lib/sqlalchemy/testing/suite/test_results.py index 125fefce98..78b2430a1f 100644 --- a/lib/sqlalchemy/testing/suite/test_results.py +++ b/lib/sqlalchemy/testing/suite/test_results.py @@ -36,8 +36,8 @@ class RowFetchTest(fixtures.TablesTest): ) @classmethod - def insert_data(cls): - config.db.execute( + def insert_data(cls, connection): + connection.execute( cls.tables.plain_pk.insert(), [ {"id": 1, "data": "d1"}, @@ -46,7 +46,7 @@ class RowFetchTest(fixtures.TablesTest): ], ) - config.db.execute( + connection.execute( cls.tables.has_dates.insert(), [{"id": 1, "today": datetime.datetime(2006, 5, 12, 12, 0, 0)}], ) diff --git a/lib/sqlalchemy/testing/suite/test_select.py b/lib/sqlalchemy/testing/suite/test_select.py index 06f1aa65c6..d29449a519 100644 --- a/lib/sqlalchemy/testing/suite/test_select.py +++ b/lib/sqlalchemy/testing/suite/test_select.py @@ -35,8 +35,8 @@ class CollateTest(fixtures.TablesTest): ) @classmethod - def insert_data(cls): - config.db.execute( + def insert_data(cls, connection): + connection.execute( cls.tables.some_table.insert(), [ {"id": 1, "data": "collate data1"}, @@ -83,8 +83,8 @@ class OrderByLabelTest(fixtures.TablesTest): ) @classmethod - def insert_data(cls): - config.db.execute( + def insert_data(cls, connection): + connection.execute( cls.tables.some_table.insert(), [ {"id": 1, "x": 1, "y": 2, "q": "q1", "p": "p3"}, @@ -155,8 +155,8 @@ class LimitOffsetTest(fixtures.TablesTest): ) @classmethod - def insert_data(cls): - config.db.execute( + def insert_data(cls, connection): + connection.execute( cls.tables.some_table.insert(), [ {"id": 1, "x": 1, "y": 2}, @@ -250,8 +250,8 @@ class CompoundSelectTest(fixtures.TablesTest): ) @classmethod - def insert_data(cls): - config.db.execute( + def insert_data(cls, connection): + connection.execute( cls.tables.some_table.insert(), [ {"id": 1, "x": 1, "y": 2}, @@ -377,8 +377,8 @@ class ExpandingBoundInTest(fixtures.TablesTest): ) @classmethod - def insert_data(cls): - config.db.execute( + def insert_data(cls, connection): + connection.execute( cls.tables.some_table.insert(), [ {"id": 1, "x": 1, "y": 2, "z": "z1"}, @@ -565,8 +565,8 @@ class LikeFunctionsTest(fixtures.TablesTest): ) @classmethod - def insert_data(cls): - config.db.execute( + def insert_data(cls, connection): + connection.execute( cls.tables.some_table.insert(), [ {"id": 1, "data": "abcdefg"}, @@ -676,12 +676,11 @@ class ComputedColumnTest(fixtures.TablesTest): ) @classmethod - def insert_data(cls): - with config.db.begin() as conn: - conn.execute( - cls.tables.square.insert(), - [{"id": 1, "side": 10}, {"id": 10, "side": 42}], - ) + def insert_data(cls, connection): + connection.execute( + cls.tables.square.insert(), + [{"id": 1, "side": 10}, {"id": 10, "side": 42}], + ) def test_select_all(self): with config.db.connect() as conn: diff --git a/lib/sqlalchemy/testing/suite/test_update_delete.py b/lib/sqlalchemy/testing/suite/test_update_delete.py index 97bdf0ad76..25f9d47163 100644 --- a/lib/sqlalchemy/testing/suite/test_update_delete.py +++ b/lib/sqlalchemy/testing/suite/test_update_delete.py @@ -21,8 +21,8 @@ class SimpleUpdateDeleteTest(fixtures.TablesTest): ) @classmethod - def insert_data(cls): - config.db.execute( + def insert_data(cls, connection): + connection.execute( cls.tables.plain_pk.insert(), [ {"id": 1, "data": "d1"}, diff --git a/test/aaa_profiling/test_orm.py b/test/aaa_profiling/test_orm.py index 2b07f25390..6b48c556b2 100644 --- a/test/aaa_profiling/test_orm.py +++ b/test/aaa_profiling/test_orm.py @@ -74,11 +74,13 @@ class MergeTest(fixtures.MappedTest): mapper(Child, child) @classmethod - def insert_data(cls): + def insert_data(cls, connection): parent, child = cls.tables.parent, cls.tables.child - parent.insert().execute({"id": 1, "data": "p1"}) - child.insert().execute({"id": 1, "data": "p1c1", "parent_id": 1}) + connection.execute(parent.insert(), {"id": 1, "data": "p1"}) + connection.execute( + child.insert(), {"id": 1, "data": "p1c1", "parent_id": 1} + ) def test_merge_no_load(self): Parent = self.classes.Parent @@ -183,13 +185,15 @@ class LoadManyToOneFromIdentityTest(fixtures.MappedTest): mapper(Child, child) @classmethod - def insert_data(cls): + def insert_data(cls, connection): parent, child = cls.tables.parent, cls.tables.child - child.insert().execute( - [{"id": i, "data": "c%d" % i} for i in range(1, 251)] + connection.execute( + child.insert(), + [{"id": i, "data": "c%d" % i} for i in range(1, 251)], ) - parent.insert().execute( + connection.execute( + parent.insert(), [ { "id": i, @@ -197,7 +201,7 @@ class LoadManyToOneFromIdentityTest(fixtures.MappedTest): "child_id": (i % 250) + 1, } for i in range(1, 1000) - ] + ], ) def test_many_to_one_load_no_identity(self): @@ -286,9 +290,9 @@ class MergeBackrefsTest(fixtures.MappedTest): mapper(D, d) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, B, C, D = cls.classes.A, cls.classes.B, cls.classes.C, cls.classes.D - s = Session() + s = Session(connection) s.add_all( [ A( @@ -352,9 +356,9 @@ class DeferOptionsTest(fixtures.MappedTest): mapper(A, a) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A = cls.classes.A - s = Session() + s = Session(connection) s.add_all( [ A( @@ -654,9 +658,9 @@ class SelectInEagerLoadTest(fixtures.MappedTest): mapper(C, c) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, B, C = cls.classes("A", "B", "C") - s = Session() + s = Session(connection) s.add(A(bs=[B(cs=[C()]), B(cs=[C()])])) s.commit() @@ -785,9 +789,9 @@ class JoinedEagerLoadTest(fixtures.MappedTest): mapper(G, g) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, B, C, D, E, F, G = cls.classes("A", "B", "C", "D", "E", "F", "G") - s = Session() + s = Session(connection) s.add( A( bs=[B(cs=[C(ds=[D()])]), B(cs=[C()])], @@ -1151,9 +1155,9 @@ class AnnotatedOverheadTest(fixtures.MappedTest): mapper(A, a) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A = cls.classes.A - s = Session() + s = Session(connection) s.add_all([A(data="asdf") for i in range(5)]) s.commit() diff --git a/test/dialect/mysql/test_for_update.py b/test/dialect/mysql/test_for_update.py index 3537c3220d..948be07977 100644 --- a/test/dialect/mysql/test_for_update.py +++ b/test/dialect/mysql/test_for_update.py @@ -43,12 +43,12 @@ class MySQLForUpdateLockingTest(fixtures.DeclarativeMappedTest): __table_args__ = {"mysql_engine": "InnoDB"} @classmethod - def insert_data(cls): + def insert_data(cls, connection): A = cls.classes.A B = cls.classes.B # all the x/y are < 10 - s = Session() + s = Session(connection) s.add_all( [ A(x=5, y=5, bs=[B(x=4, y=4), B(x=2, y=8), B(x=7, y=1)]), diff --git a/test/dialect/mysql/test_query.py b/test/dialect/mysql/test_query.py index e492f1e17f..35d3c0f84d 100644 --- a/test/dialect/mysql/test_query.py +++ b/test/dialect/mysql/test_query.py @@ -231,9 +231,9 @@ class AnyAllTest(fixtures.TablesTest): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): stuff = cls.tables.stuff - testing.db.execute( + connection.execute( stuff.insert(), [ {"id": 1, "value": 1}, diff --git a/test/dialect/oracle/test_types.py b/test/dialect/oracle/test_types.py index e664ba50ec..4c61f08b44 100644 --- a/test/dialect/oracle/test_types.py +++ b/test/dialect/oracle/test_types.py @@ -908,7 +908,7 @@ class LOBFetchTest(fixtures.TablesTest): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): cls.data = data = [ dict( id=i, @@ -918,7 +918,7 @@ class LOBFetchTest(fixtures.TablesTest): for i in range(1, 20) ] - testing.db.execute(cls.tables.z_test.insert(), data) + connection.execute(cls.tables.z_test.insert(), data) binary_table = cls.tables.binary_table fname = os.path.join( @@ -928,7 +928,7 @@ class LOBFetchTest(fixtures.TablesTest): cls.stream = stream = file_.read(12000) for i in range(1, 11): - binary_table.insert().execute(id=i, data=stream) + connection.execute(binary_table.insert(), id=i, data=stream) def test_lobs_without_convert(self): engine = testing_engine(options=dict(auto_convert_lobs=False)) diff --git a/test/dialect/postgresql/test_query.py b/test/dialect/postgresql/test_query.py index 40cd85c798..01edf6595c 100644 --- a/test/dialect/postgresql/test_query.py +++ b/test/dialect/postgresql/test_query.py @@ -950,14 +950,14 @@ class ExtractTest(fixtures.TablesTest): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): # TODO: why does setting hours to anything # not affect the TZ in the DB col ? class TZ(datetime.tzinfo): def utcoffset(self, dt): return datetime.timedelta(hours=4) - cls.bind.execute( + connection.execute( cls.tables.t.insert(), { "dtme": datetime.datetime(2012, 5, 10, 12, 15, 25), diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py index 61fb9d6794..6b46a60044 100644 --- a/test/dialect/postgresql/test_types.py +++ b/test/dialect/postgresql/test_types.py @@ -79,20 +79,24 @@ class FloatCoercionTest(fixtures.TablesTest, AssertsExecutionResults): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): data_table = cls.tables.data_table - data_table.insert().execute( - {"data": 3}, - {"data": 5}, - {"data": 7}, - {"data": 2}, - {"data": 15}, - {"data": 12}, - {"data": 6}, - {"data": 478}, - {"data": 52}, - {"data": 9}, + connection.execute( + data_table.insert().values( + [ + {"data": 3}, + {"data": 5}, + {"data": 7}, + {"data": 2}, + {"data": 15}, + {"data": 12}, + {"data": 6}, + {"data": 478}, + {"data": 52}, + {"data": 9}, + ] + ) ) @testing.fails_on( diff --git a/test/ext/declarative/test_basic.py b/test/ext/declarative/test_basic.py index 264c4839c9..336c919a88 100644 --- a/test/ext/declarative/test_basic.py +++ b/test/ext/declarative/test_basic.py @@ -2181,7 +2181,7 @@ def _produce_test(inline, stringbased): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): params = [ dict(list(zip(("id", "name"), column_values))) for column_values in [ @@ -2192,8 +2192,9 @@ def _produce_test(inline, stringbased): ] ] - User.__table__.insert().execute(params) - Address.__table__.insert().execute( + connection.execute(User.__table__.insert(), params) + connection.execute( + Address.__table__.insert(), [ dict(list(zip(("id", "user_id", "email"), column_values))) for column_values in [ @@ -2203,7 +2204,7 @@ def _produce_test(inline, stringbased): (4, 8, "ed@lala.com"), (5, 9, "fred@fred.com"), ] - ] + ], ) def test_aliased_join(self): diff --git a/test/ext/test_associationproxy.py b/test/ext/test_associationproxy.py index e7cc6251bb..2054e023cd 100644 --- a/test/ext/test_associationproxy.py +++ b/test/ext/test_associationproxy.py @@ -24,7 +24,6 @@ from sqlalchemy.orm import create_session from sqlalchemy.orm import mapper from sqlalchemy.orm import relationship from sqlalchemy.orm import Session -from sqlalchemy.orm import sessionmaker from sqlalchemy.orm.collections import attribute_mapped_collection from sqlalchemy.orm.collections import collection from sqlalchemy.testing import assert_raises @@ -1614,7 +1613,7 @@ class ComparatorTest(fixtures.MappedTest, AssertsCompiledSQL): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): UserKeyword, User, Keyword, Singular = ( cls.classes.UserKeyword, cls.classes.User, @@ -1622,7 +1621,7 @@ class ComparatorTest(fixtures.MappedTest, AssertsCompiledSQL): cls.classes.Singular, ) - session = sessionmaker()() + session = Session(connection) words = ("quick", "brown", "fox", "jumped", "over", "the", "lazy") for ii in range(16): user = User("user%d" % ii) @@ -1649,7 +1648,9 @@ class ComparatorTest(fixtures.MappedTest, AssertsCompiledSQL): session.commit() cls.u = user cls.kw = user.keywords[0] - cls.session = session + + # TODO: this is not the correct pattern, use session per test + cls.session = Session(testing.db) def _equivalent(self, q_proxy, q_direct): proxy_sql = q_proxy.statement.compile(dialect=default.DefaultDialect()) @@ -3440,10 +3441,10 @@ class ScopeBehaviorTest(fixtures.DeclarativeMappedTest): data = Column(String(50)) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, B = cls.classes("A", "B") - s = Session(testing.db) + s = Session(connection) s.add_all( [ A(id=1, bs=[B(data="b1"), B(data="b2")]), diff --git a/test/ext/test_horizontal_shard.py b/test/ext/test_horizontal_shard.py index 16694c86f5..a3d1d957fa 100644 --- a/test/ext/test_horizontal_shard.py +++ b/test/ext/test_horizontal_shard.py @@ -512,9 +512,9 @@ class RefreshDeferExpireTest(fixtures.DeclarativeMappedTest): deferred_data = deferred(Column(String(30))) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A = cls.classes.A - s = Session() + s = Session(connection) s.add(A(data="d1", deferred_data="d2")) s.commit() diff --git a/test/ext/test_hybrid.py b/test/ext/test_hybrid.py index ab57ce6f47..353c52c5c0 100644 --- a/test/ext/test_hybrid.py +++ b/test/ext/test_hybrid.py @@ -579,8 +579,8 @@ class BulkUpdateTest(fixtures.DeclarativeMappedTest, AssertsCompiledSQL): return self.fname @classmethod - def insert_data(cls): - s = Session() + def insert_data(cls, connection): + s = Session(connection) jill = cls.classes.Person(id=3, first_name="jill") s.add(jill) s.commit() diff --git a/test/ext/test_serializer.py b/test/ext/test_serializer.py index ac5133fdaf..4080a0044b 100644 --- a/test/ext/test_serializer.py +++ b/test/ext/test_serializer.py @@ -81,7 +81,7 @@ class SerializeTest(AssertsCompiledSQL, fixtures.MappedTest): configure_mappers() @classmethod - def insert_data(cls): + def insert_data(cls, connection): params = [ dict(list(zip(("id", "name"), column_values))) for column_values in [ @@ -91,8 +91,9 @@ class SerializeTest(AssertsCompiledSQL, fixtures.MappedTest): (10, "chuck"), ] ] - users.insert().execute(params) - addresses.insert().execute( + connection.execute(users.insert(), params) + connection.execute( + addresses.insert(), [ dict(list(zip(("id", "user_id", "email"), column_values))) for column_values in [ @@ -102,7 +103,7 @@ class SerializeTest(AssertsCompiledSQL, fixtures.MappedTest): (4, 8, "ed@lala.com"), (5, 9, "fred@fred.com"), ] - ] + ], ) def test_tables(self): diff --git a/test/orm/inheritance/_poly_fixtures.py b/test/orm/inheritance/_poly_fixtures.py index 5cffa34066..4756ae78ad 100644 --- a/test/orm/inheritance/_poly_fixtures.py +++ b/test/orm/inheritance/_poly_fixtures.py @@ -151,7 +151,7 @@ class _PolymorphicFixtureBase(fixtures.MappedTest, AssertsCompiledSQL): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): cls.e1 = e1 = Engineer( name="dilbert", @@ -209,7 +209,7 @@ class _PolymorphicFixtureBase(fixtures.MappedTest, AssertsCompiledSQL): cls.c2 = c2 = Company(name="Elbonia, Inc.") c2.employees = [e3] - sess = create_session() + sess = create_session(connection) sess.add(c1) sess.add(c2) sess.flush() diff --git a/test/orm/inheritance/test_assorted_poly.py b/test/orm/inheritance/test_assorted_poly.py index dda1ce5758..3fa5c99870 100644 --- a/test/orm/inheritance/test_assorted_poly.py +++ b/test/orm/inheritance/test_assorted_poly.py @@ -1249,11 +1249,11 @@ class GenerativeTest(fixtures.MappedTest, AssertsExecutionResults): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): Status, Person, Engineer, Manager, Car = cls.classes( "Status", "Person", "Engineer", "Manager", "Car" ) - session = create_session() + session = create_session(connection) active = Status(name="active") dead = Status(name="dead") diff --git a/test/orm/inheritance/test_basic.py b/test/orm/inheritance/test_basic.py index 5a7b549ac8..8f1c6d014f 100644 --- a/test/orm/inheritance/test_basic.py +++ b/test/orm/inheritance/test_basic.py @@ -159,10 +159,10 @@ class PolyExpressionEagerLoad(fixtures.DeclarativeMappedTest): __mapper_args__ = {"polymorphic_identity": "b"} @classmethod - def insert_data(cls): + def insert_data(cls, connection): A = cls.classes.A - session = Session(testing.db) + session = Session(connection) session.add_all( [ A(id=1, discriminator="a"), @@ -1972,14 +1972,18 @@ class DistinctPKTest(fixtures.MappedTest): pass @classmethod - def insert_data(cls): + def insert_data(cls, connection): person_insert = person_table.insert() - person_insert.execute(id=1, name="alice") - person_insert.execute(id=2, name="bob") + connection.execute(person_insert, dict(id=1, name="alice")) + connection.execute(person_insert, dict(id=2, name="bob")) employee_insert = employee_table.insert() - employee_insert.execute(id=2, salary=250, person_id=1) # alice - employee_insert.execute(id=3, salary=200, person_id=2) # bob + connection.execute( + employee_insert, dict(id=2, salary=250, person_id=1) + ) # alice + connection.execute( + employee_insert, dict(id=3, salary=200, person_id=2) + ) # bob def test_implicit(self): person_mapper = mapper(Person, person_table) diff --git a/test/orm/inheritance/test_concrete.py b/test/orm/inheritance/test_concrete.py index cea7eeaac8..376337b253 100644 --- a/test/orm/inheritance/test_concrete.py +++ b/test/orm/inheritance/test_concrete.py @@ -1171,12 +1171,14 @@ class ColKeysTest(fixtures.MappedTest): ) @classmethod - def insert_data(cls): - refugees_table.insert().execute( + def insert_data(cls, connection): + connection.execute( + refugees_table.insert(), dict(refugee_fid=1, name="refugee1"), dict(refugee_fid=2, name="refugee2"), ) - offices_table.insert().execute( + connection.execute( + offices_table.insert(), dict(office_fid=1, name="office1"), dict(office_fid=2, name="office2"), ) diff --git a/test/orm/inheritance/test_poly_loading.py b/test/orm/inheritance/test_poly_loading.py index f450b760df..f3d08fb423 100644 --- a/test/orm/inheritance/test_poly_loading.py +++ b/test/orm/inheritance/test_poly_loading.py @@ -69,9 +69,9 @@ class BaseAndSubFixture(object): a_sub_id = Column(ForeignKey("asub.id")) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, B, ASub, C = cls.classes("A", "B", "ASub", "C") - s = Session() + s = Session(connection) s.add(A(id=1, adata="adata", bs=[B(), B()])) s.add( ASub( @@ -564,11 +564,11 @@ class LoaderOptionsTest( ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): Parent, ChildSubclass1, Other = cls.classes( "Parent", "ChildSubclass1", "Other" ) - session = Session() + session = Session(connection) parent = Parent(id=1) subclass1 = ChildSubclass1(id=1, parent=parent) diff --git a/test/orm/inheritance/test_poly_persistence.py b/test/orm/inheritance/test_poly_persistence.py index 00a240cdcb..1144929060 100644 --- a/test/orm/inheritance/test_poly_persistence.py +++ b/test/orm/inheritance/test_poly_persistence.py @@ -316,7 +316,7 @@ class RoundTripTest(PolymorphTest): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): redefine_colprop = cls.redefine_colprop include_base = cls.include_base @@ -354,7 +354,7 @@ class RoundTripTest(PolymorphTest): ), ] - session = Session() + session = Session(connection) c = Company(name="company1") c.employees = employees session.add(c) diff --git a/test/orm/inheritance/test_polymorphic_rel.py b/test/orm/inheritance/test_polymorphic_rel.py index 8e09dfc147..880cc5f913 100644 --- a/test/orm/inheritance/test_polymorphic_rel.py +++ b/test/orm/inheritance/test_polymorphic_rel.py @@ -45,8 +45,8 @@ class _PolymorphicTestBase(object): ) @classmethod - def insert_data(cls): - super(_PolymorphicTestBase, cls).insert_data() + def insert_data(cls, connection): + super(_PolymorphicTestBase, cls).insert_data(connection) global all_employees, c1_employees, c2_employees global c1, c2, e1, e2, e3, b1, m1 diff --git a/test/orm/inheritance/test_relationship.py b/test/orm/inheritance/test_relationship.py index 851ad60b87..48c71209f0 100644 --- a/test/orm/inheritance/test_relationship.py +++ b/test/orm/inheritance/test_relationship.py @@ -573,7 +573,7 @@ class M2MFilterTest(fixtures.MappedTest): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): Organization = cls.classes.Organization e1 = Engineer(name="e1") e2 = Engineer(name="e2") @@ -581,7 +581,7 @@ class M2MFilterTest(fixtures.MappedTest): e4 = Engineer(name="e4") org1 = Organization(name="org1", engineers=[e1, e2]) org2 = Organization(name="org2", engineers=[e3, e4]) - sess = create_session() + sess = create_session(connection) sess.add(org1) sess.add(org2) sess.flush() @@ -899,13 +899,13 @@ class EagerToSubclassTest(fixtures.MappedTest): mapper(Related, related) @classmethod - def insert_data(cls): + def insert_data(cls, connection): global p1, p2 Parent = cls.classes.Parent Sub = cls.classes.Sub Related = cls.classes.Related - sess = Session() + sess = Session(connection) r1, r2 = Related(data="r1"), Related(data="r2") s1 = Sub(data="s1", related=r1) s2 = Sub(data="s2", related=r2) @@ -1078,11 +1078,11 @@ class SubClassEagerToSubClassTest(fixtures.MappedTest): mapper(Sub, sub, inherits=Base, polymorphic_identity="s") @classmethod - def insert_data(cls): + def insert_data(cls, connection): global p1, p2 Sub, Subparent = cls.classes.Sub, cls.classes.Subparent - sess = create_session() + sess = create_session(connection) p1 = Subparent( data="p1", children=[Sub(data="s1"), Sub(data="s2"), Sub(data="s3")], @@ -1264,12 +1264,12 @@ class SameNamedPropTwoPolymorphicSubClassesTest(fixtures.MappedTest): mapper(D, cls.tables.d) @classmethod - def insert_data(cls): + def insert_data(cls, connection): B = cls.classes.B C = cls.classes.C D = cls.classes.D - session = Session() + session = Session(connection) d = D() session.add_all([B(related=[d]), C(related=[d])]) @@ -1435,10 +1435,10 @@ class SubClassToSubClassFromParentTest(fixtures.MappedTest): mapper(D, cls.tables.d, inherits=A, polymorphic_identity="d") @classmethod - def insert_data(cls): + def insert_data(cls, connection): B = cls.classes.B - session = Session() + session = Session(connection) session.add(B()) session.commit() @@ -1781,7 +1781,7 @@ class JoinedloadWPolyOfTypeContinued( id = Column(Integer, primary_key=True) @classmethod - def insert_data(cls): + def insert_data(cls, connection): User, Fred, SubBar, Bar, SubFoo = cls.classes( "User", "Fred", "SubBar", "Bar", "SubFoo" ) @@ -1791,7 +1791,7 @@ class JoinedloadWPolyOfTypeContinued( sub_bar = SubBar(fred=fred) rectangle = SubFoo(owner=user, baz=10, bar=bar, sub_bar=sub_bar) - s = Session() + s = Session(connection) s.add_all([user, fred, bar, sub_bar, rectangle]) s.commit() @@ -2726,9 +2726,9 @@ class M2ODontLoadSiblingTest(fixtures.DeclarativeMappedTest): child2 = relationship(Child2, viewonly=True) @classmethod - def insert_data(cls): + def insert_data(cls, connection): Other, Child1 = cls.classes("Other", "Child1") - s = Session() + s = Session(connection) obj = Other(parent=Child1()) s.add(obj) s.commit() diff --git a/test/orm/inheritance/test_single.py b/test/orm/inheritance/test_single.py index a33ea5ecb9..389cc4fa4d 100644 --- a/test/orm/inheritance/test_single.py +++ b/test/orm/inheritance/test_single.py @@ -1259,11 +1259,11 @@ class ManyToManyToSingleTest(fixtures.MappedTest, AssertsCompiledSQL): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): Parent = cls.classes.Parent SubChild1 = cls.classes.SubChild1 SubChild2 = cls.classes.SubChild2 - s = Session() + s = Session(connection) s.add_all( [ Parent( diff --git a/test/orm/test_ac_relationships.py b/test/orm/test_ac_relationships.py index aec9ee5e46..14fecf74a0 100644 --- a/test/orm/test_ac_relationships.py +++ b/test/orm/test_ac_relationships.py @@ -58,10 +58,10 @@ class PartitionByFixture(fixtures.DeclarativeMappedTest): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, B, C = cls.classes("A", "B", "C") - s = Session(testing.db) + s = Session(connection) s.add_all([A(id=i) for i in range(1, 4)]) s.flush() s.add_all( @@ -198,9 +198,9 @@ class AltSelectableTest( A.b = relationship(B_viacd, primaryjoin=A.b_id == j.c.b_id) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, B, C, D = cls.classes("A", "B", "C", "D") - sess = Session() + sess = Session(connection) for obj in [ B(id=1), diff --git a/test/orm/test_assorted_eager.py b/test/orm/test_assorted_eager.py index 21534d6bc9..f80b7040cc 100644 --- a/test/orm/test_assorted_eager.py +++ b/test/orm/test_assorted_eager.py @@ -143,7 +143,7 @@ class EagerTest(fixtures.MappedTest): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): Owner, Category, Option, Thing = ( cls.classes.Owner, cls.classes.Category, @@ -151,7 +151,7 @@ class EagerTest(fixtures.MappedTest): cls.classes.Thing, ) - session = create_session() + session = create_session(connection) o = Owner() c = Category(name="Some Category") diff --git a/test/orm/test_bundle.py b/test/orm/test_bundle.py index a17a00ed0d..f6d4e8e37f 100644 --- a/test/orm/test_bundle.py +++ b/test/orm/test_bundle.py @@ -64,8 +64,8 @@ class BundleTest(fixtures.MappedTest, AssertsCompiledSQL): mapper(cls.classes.Other, cls.tables.other) @classmethod - def insert_data(cls): - sess = Session() + def insert_data(cls, connection): + sess = Session(connection) sess.add_all( [ cls.classes.Data( diff --git a/test/orm/test_cascade.py b/test/orm/test_cascade.py index 5f4519bcf7..611f6e1763 100644 --- a/test/orm/test_cascade.py +++ b/test/orm/test_cascade.py @@ -1562,7 +1562,7 @@ class M2OCascadeDeleteOrphanTestOne(fixtures.MappedTest): mapper(Foo, foo) @classmethod - def insert_data(cls): + def insert_data(cls, connection): Pref, User, Extra = ( cls.classes.Pref, cls.classes.User, @@ -1572,7 +1572,7 @@ class M2OCascadeDeleteOrphanTestOne(fixtures.MappedTest): u1 = User(name="ed", pref=Pref(data="pref 1", extra=[Extra()])) u2 = User(name="jack", pref=Pref(data="pref 2", extra=[Extra()])) u3 = User(name="foo", pref=Pref(data="pref 3", extra=[Extra()])) - sess = create_session() + sess = create_session(connection) sess.add_all((u1, u2, u3)) sess.flush() sess.close() diff --git a/test/orm/test_deferred.py b/test/orm/test_deferred.py index 5b97308beb..03bd70285c 100644 --- a/test/orm/test_deferred.py +++ b/test/orm/test_deferred.py @@ -1188,10 +1188,10 @@ class SelfReferentialMultiPathTest(testing.fixtures.DeclarativeMappedTest): name = sa.Column(sa.String(10)) @classmethod - def insert_data(cls): + def insert_data(cls, connection): Node = cls.classes.Node - session = Session() + session = Session(connection) session.add_all( [ Node(id=1, name="name"), @@ -1651,9 +1651,9 @@ class WithExpressionTest(fixtures.DeclarativeMappedTest): b_expr = query_expression() @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, B = cls.classes("A", "B") - s = Session() + s = Session(connection) s.add_all( [ diff --git a/test/orm/test_eager_relations.py b/test/orm/test_eager_relations.py index a5953452ae..cbf2c4bfbf 100644 --- a/test/orm/test_eager_relations.py +++ b/test/orm/test_eager_relations.py @@ -2995,8 +2995,8 @@ class InnerJoinSplicingTest(fixtures.MappedTest, testing.AssertsCompiledSQL): ] @classmethod - def insert_data(cls): - s = Session(testing.db) + def insert_data(cls, connection): + s = Session(connection) s.add_all(cls._fixture_data()) s.commit() @@ -3223,8 +3223,8 @@ class InnerJoinSplicingWSecondaryTest( ] @classmethod - def insert_data(cls): - s = Session(testing.db) + def insert_data(cls, connection): + s = Session(connection) s.add_all(cls._fixture_data()) s.commit() @@ -4200,25 +4200,34 @@ class MixedSelfReferentialEagerTest(fixtures.MappedTest): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): b_table, a_table = cls.tables.b_table, cls.tables.a_table - a_table.insert().execute(dict(id=1), dict(id=2), dict(id=3)) - b_table.insert().execute( - dict(id=1, parent_a_id=2, parent_b1_id=None, parent_b2_id=None), - dict(id=2, parent_a_id=1, parent_b1_id=1, parent_b2_id=None), - dict(id=3, parent_a_id=1, parent_b1_id=1, parent_b2_id=2), - dict(id=4, parent_a_id=3, parent_b1_id=1, parent_b2_id=None), - dict(id=5, parent_a_id=3, parent_b1_id=None, parent_b2_id=2), - dict(id=6, parent_a_id=1, parent_b1_id=1, parent_b2_id=3), - dict(id=7, parent_a_id=2, parent_b1_id=None, parent_b2_id=3), - dict(id=8, parent_a_id=2, parent_b1_id=1, parent_b2_id=2), - dict(id=9, parent_a_id=None, parent_b1_id=1, parent_b2_id=None), - dict(id=10, parent_a_id=3, parent_b1_id=7, parent_b2_id=2), - dict(id=11, parent_a_id=3, parent_b1_id=1, parent_b2_id=8), - dict(id=12, parent_a_id=2, parent_b1_id=5, parent_b2_id=2), - dict(id=13, parent_a_id=3, parent_b1_id=4, parent_b2_id=4), - dict(id=14, parent_a_id=3, parent_b1_id=7, parent_b2_id=2), + connection.execute( + a_table.insert(), [dict(id=1), dict(id=2), dict(id=3)] + ) + connection.execute( + b_table.insert(), + [ + dict( + id=1, parent_a_id=2, parent_b1_id=None, parent_b2_id=None + ), + dict(id=2, parent_a_id=1, parent_b1_id=1, parent_b2_id=None), + dict(id=3, parent_a_id=1, parent_b1_id=1, parent_b2_id=2), + dict(id=4, parent_a_id=3, parent_b1_id=1, parent_b2_id=None), + dict(id=5, parent_a_id=3, parent_b1_id=None, parent_b2_id=2), + dict(id=6, parent_a_id=1, parent_b1_id=1, parent_b2_id=3), + dict(id=7, parent_a_id=2, parent_b1_id=None, parent_b2_id=3), + dict(id=8, parent_a_id=2, parent_b1_id=1, parent_b2_id=2), + dict( + id=9, parent_a_id=None, parent_b1_id=1, parent_b2_id=None + ), + dict(id=10, parent_a_id=3, parent_b1_id=7, parent_b2_id=2), + dict(id=11, parent_a_id=3, parent_b1_id=1, parent_b2_id=8), + dict(id=12, parent_a_id=2, parent_b1_id=5, parent_b2_id=2), + dict(id=13, parent_a_id=3, parent_b1_id=4, parent_b2_id=4), + dict(id=14, parent_a_id=3, parent_b1_id=7, parent_b2_id=2), + ], ) def test_eager_load(self): @@ -4818,16 +4827,18 @@ class CorrelatedSubqueryTest(fixtures.MappedTest): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): stuff, users = cls.tables.stuff, cls.tables.users - users.insert().execute( + connection.execute( + users.insert(), {"id": 1, "name": "user1"}, {"id": 2, "name": "user2"}, {"id": 3, "name": "user3"}, ) - stuff.insert().execute( + connection.execute( + stuff.insert(), {"id": 1, "user_id": 1, "date": datetime.date(2007, 10, 15)}, {"id": 2, "user_id": 1, "date": datetime.date(2007, 12, 15)}, {"id": 3, "user_id": 1, "date": datetime.date(2007, 11, 15)}, @@ -5544,9 +5555,9 @@ class LazyLoadOptSpecificityTest(fixtures.DeclarativeMappedTest): b_id = Column(ForeignKey("b.id")) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, B, C = cls.classes("A", "B", "C") - s = Session() + s = Session(connection) s.add(A(id=1, bs=[B(cs=[C()])])) s.add(A(id=2)) s.commit() diff --git a/test/orm/test_events.py b/test/orm/test_events.py index 846f6241ba..1774bbc546 100644 --- a/test/orm/test_events.py +++ b/test/orm/test_events.py @@ -653,9 +653,9 @@ class RestoreLoadContextTest(fixtures.DeclarativeMappedTest): a_id = Column(ForeignKey("a.id")) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, B = cls.classes("A", "B") - s = Session(testing.db) + s = Session(connection) s.add(A(bs=[B(), B(), B()])) s.commit() diff --git a/test/orm/test_expire.py b/test/orm/test_expire.py index ed4950a06c..fafaba4842 100644 --- a/test/orm/test_expire.py +++ b/test/orm/test_expire.py @@ -1302,15 +1302,17 @@ class PolymorphicExpireTest(fixtures.MappedTest): pass @classmethod - def insert_data(cls): + def insert_data(cls, connection): people, engineers = cls.tables.people, cls.tables.engineers - people.insert().execute( + connection.execute( + people.insert(), {"person_id": 1, "name": "person1", "type": "person"}, {"person_id": 2, "name": "engineer1", "type": "engineer"}, {"person_id": 3, "name": "engineer2", "type": "engineer"}, ) - engineers.insert().execute( + connection.execute( + engineers.insert(), {"person_id": 2, "status": "new engineer"}, {"person_id": 3, "status": "old engineer"}, ) diff --git a/test/orm/test_froms.py b/test/orm/test_froms.py index 72358553ed..a586d3ada3 100644 --- a/test/orm/test_froms.py +++ b/test/orm/test_froms.py @@ -803,10 +803,10 @@ class AddEntityEquivalenceTest(fixtures.MappedTest, AssertsCompiledSQL): mapper(D, d, inherits=A, polymorphic_identity="d") @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, C, B = (cls.classes.A, cls.classes.C, cls.classes.B) - sess = create_session() + sess = create_session(connection) sess.add_all( [ B(name="b1"), @@ -3619,8 +3619,8 @@ class LabelCollideTest(fixtures.MappedTest): mapper(cls.classes.Bar, cls.tables.foo_bar) @classmethod - def insert_data(cls): - s = Session() + def insert_data(cls, connection): + s = Session(connection) s.add_all([cls.classes.Foo(id=1, bar_id=2), cls.classes.Bar(id=3)]) s.commit() diff --git a/test/orm/test_joins.py b/test/orm/test_joins.py index eca4068b4e..aaa96ae4ad 100644 --- a/test/orm/test_joins.py +++ b/test/orm/test_joins.py @@ -3092,10 +3092,10 @@ class SelfReferentialTest(fixtures.MappedTest, AssertsCompiledSQL): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): Node = cls.classes.Node - sess = create_session() + sess = create_session(connection) n1 = Node(data="n1") n1.append(Node(data="n11")) n1.append(Node(data="n12")) @@ -3802,7 +3802,7 @@ class SelfReferentialM2MTest(fixtures.MappedTest): pass @classmethod - def insert_data(cls): + def insert_data(cls, connection): Node, nodes, node_to_nodes = ( cls.classes.Node, cls.tables.nodes, @@ -3822,7 +3822,7 @@ class SelfReferentialM2MTest(fixtures.MappedTest): ) }, ) - sess = create_session() + sess = create_session(connection) n1 = Node(data="n1") n2 = Node(data="n2") n3 = Node(data="n3") diff --git a/test/orm/test_lazy_relations.py b/test/orm/test_lazy_relations.py index 3566a5ca72..df2452adfd 100644 --- a/test/orm/test_lazy_relations.py +++ b/test/orm/test_lazy_relations.py @@ -1246,16 +1246,18 @@ class CorrelatedTest(fixtures.MappedTest): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): stuff, user_t = cls.tables.stuff, cls.tables.user_t - user_t.insert().execute( + connection.execute( + user_t.insert(), {"id": 1, "name": "user1"}, {"id": 2, "name": "user2"}, {"id": 3, "name": "user3"}, ) - stuff.insert().execute( + connection.execute( + stuff.insert(), {"id": 1, "user_id": 1, "date": datetime.date(2007, 10, 15)}, {"id": 2, "user_id": 1, "date": datetime.date(2007, 12, 15)}, {"id": 3, "user_id": 1, "date": datetime.date(2007, 11, 15)}, diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py index 72e428efcd..0aed3a5c18 100644 --- a/test/orm/test_mapper.py +++ b/test/orm/test_mapper.py @@ -2841,7 +2841,7 @@ class SecondaryOptionsTest(fixtures.MappedTest): mapper(Related, related) @classmethod - def insert_data(cls): + def insert_data(cls, connection): child1, child2, base, related = ( cls.tables.child1, cls.tables.child2, @@ -2849,7 +2849,8 @@ class SecondaryOptionsTest(fixtures.MappedTest): cls.tables.related, ) - base.insert().execute( + connection.execute( + base.insert(), [ {"id": 1, "type": "child1"}, {"id": 2, "type": "child1"}, @@ -2857,18 +2858,20 @@ class SecondaryOptionsTest(fixtures.MappedTest): {"id": 4, "type": "child2"}, {"id": 5, "type": "child2"}, {"id": 6, "type": "child2"}, - ] + ], ) - child2.insert().execute([{"id": 4}, {"id": 5}, {"id": 6}]) - child1.insert().execute( + connection.execute(child2.insert(), [{"id": 4}, {"id": 5}, {"id": 6}]) + connection.execute( + child1.insert(), [ {"id": 1, "child2id": 4}, {"id": 2, "child2id": 5}, {"id": 3, "child2id": 6}, - ] + ], ) - related.insert().execute( - [{"id": 1}, {"id": 2}, {"id": 3}, {"id": 4}, {"id": 5}, {"id": 6}] + connection.execute( + related.insert(), + [{"id": 1}, {"id": 2}, {"id": 3}, {"id": 4}, {"id": 5}, {"id": 6}], ) def test_contains_eager(self): @@ -3029,13 +3032,13 @@ class DeferredPopulationTest(fixtures.MappedTest): mapper(Thing, thing, properties={"name": deferred(thing.c.name)}) @classmethod - def insert_data(cls): + def insert_data(cls, connection): thing, human = cls.tables.thing, cls.tables.human - thing.insert().execute([{"id": 1, "name": "Chair"}]) + connection.execute(thing.insert(), [{"id": 1, "name": "Chair"}]) - human.insert().execute( - [{"id": 1, "thing_id": 1, "name": "Clark Kent"}] + connection.execute( + human.insert(), [{"id": 1, "thing_id": 1, "name": "Clark Kent"}] ) def _test(self, thing): diff --git a/test/orm/test_merge.py b/test/orm/test_merge.py index 89fb4d6e17..b52f4ddb1c 100644 --- a/test/orm/test_merge.py +++ b/test/orm/test_merge.py @@ -1662,9 +1662,9 @@ class M2ONoUseGetLoadingTest(fixtures.MappedTest): assert Address.user.property._use_get is False @classmethod - def insert_data(cls): + def insert_data(cls, connection): User, Address = cls.classes.User, cls.classes.Address - s = Session() + s = Session(connection) s.add_all( [ User( diff --git a/test/orm/test_of_type.py b/test/orm/test_of_type.py index 59391b0fc6..bf7ee28286 100644 --- a/test/orm/test_of_type.py +++ b/test/orm/test_of_type.py @@ -564,8 +564,8 @@ class SubclassRelationshipTest( name = Column(String(10)) @classmethod - def insert_data(cls): - s = Session(testing.db) + def insert_data(cls, connection): + s = Session(connection) s.add_all(cls._fixture()) s.commit() @@ -1022,8 +1022,8 @@ class SubclassRelationshipTest2( c = relationship("C", backref="ds") @classmethod - def insert_data(cls): - s = Session(testing.db) + def insert_data(cls, connection): + s = Session(connection) s.add_all(cls._fixture()) s.commit() diff --git a/test/orm/test_relationships.py b/test/orm/test_relationships.py index 4b7d4d18e5..6cec819ce7 100644 --- a/test/orm/test_relationships.py +++ b/test/orm/test_relationships.py @@ -280,7 +280,7 @@ class DependencyTwoParentTest(fixtures.MappedTest): mapper(D, tbl_d, properties=dict(b_row=relationship(B))) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, C, B, D = ( cls.classes.A, cls.classes.C, @@ -288,7 +288,7 @@ class DependencyTwoParentTest(fixtures.MappedTest): cls.classes.D, ) - session = create_session() + session = create_session(connection) a = A(name="a1") b = B(name="b1") c = C(name="c1", a_row=a) @@ -3468,9 +3468,9 @@ class FunctionAsPrimaryJoinTest(fixtures.DeclarativeMappedTest): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): Venue = cls.classes.Venue - s = Session() + s = Session(connection) s.add_all( [ Venue(name="parent1"), @@ -3548,9 +3548,9 @@ class RemoteForeignBetweenColsTest(fixtures.DeclarativeMappedTest): ip_addr = Column(Integer, primary_key=True) @classmethod - def insert_data(cls): + def insert_data(cls, connection): Network, Address = cls.classes.Network, cls.classes.Address - s = Session(testing.db) + s = Session(connection) s.add_all( [ @@ -4169,9 +4169,9 @@ class SecondaryNestedJoinTest( mapper(D, d) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, B, C, D = cls.classes.A, cls.classes.B, cls.classes.C, cls.classes.D - sess = Session() + sess = Session(connection) a1, a2, a3, a4 = A(name="a1"), A(name="a2"), A(name="a3"), A(name="a4") b1, b2, b3, b4 = B(name="b1"), B(name="b2"), B(name="b3"), B(name="b4") c1, c2, c3, c4 = C(name="c1"), C(name="c2"), C(name="c3"), C(name="c4") @@ -5507,10 +5507,10 @@ class SecondaryIncludesLocalColsTest(fixtures.MappedTest): mapper(B, b) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, B = cls.classes("A", "B") - s = Session() + s = Session(connection) s.add_all( [ A(id=1, b_ids="1"), diff --git a/test/orm/test_selectin_relations.py b/test/orm/test_selectin_relations.py index f3e0baa1fb..d74c52bfef 100644 --- a/test/orm/test_selectin_relations.py +++ b/test/orm/test_selectin_relations.py @@ -1675,7 +1675,7 @@ class BaseRelationFromJoinedSubclassTest(_Polymorphic): mapper(Paperwork, paperwork) @classmethod - def insert_data(cls): + def insert_data(cls, connection): e1 = Engineer(primary_language="java") e2 = Engineer(primary_language="c++") @@ -1684,7 +1684,7 @@ class BaseRelationFromJoinedSubclassTest(_Polymorphic): Paperwork(description="tps report #2"), ] e2.paperwork = [Paperwork(description="tps report #3")] - sess = create_session() + sess = create_session(connection) sess.add_all([e1, e2]) sess.flush() @@ -1982,7 +1982,7 @@ class HeterogeneousSubtypesTest(fixtures.DeclarativeMappedTest): name = Column(String(50)) @classmethod - def insert_data(cls): + def insert_data(cls, connection): Company, Programmer, Manager, GolfSwing, Language = cls.classes( "Company", "Programmer", "Manager", "GolfSwing", "Language" ) @@ -2006,7 +2006,7 @@ class HeterogeneousSubtypesTest(fixtures.DeclarativeMappedTest): ), ], ) - sess = Session() + sess = Session(connection) sess.add_all([c1, c2]) sess.commit() @@ -2108,10 +2108,10 @@ class TupleTest(fixtures.DeclarativeMappedTest): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, B = cls.classes("A", "B") - session = Session() + session = Session(connection) session.add_all( [ A(id1=i, id2=i + 2, bs=[B(id=(i * 6) + j) for j in range(6)]) @@ -2216,10 +2216,10 @@ class ChunkingTest(fixtures.DeclarativeMappedTest): a = relationship("A", back_populates="bs") @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, B = cls.classes("A", "B") - session = Session() + session = Session(connection) session.add_all( [ A(id=i, bs=[B(id=(i * 6) + j) for j in range(1, 6)]) @@ -2450,9 +2450,9 @@ class SubRelationFromJoinedSubclassMultiLevelTest(_Polymorphic): mapper(MachineType, machine_type) @classmethod - def insert_data(cls): + def insert_data(cls, connection): c1 = cls._fixture() - sess = create_session() + sess = create_session(connection) sess.add(c1) sess.flush() @@ -2828,10 +2828,10 @@ class SelfRefInheritanceAliasedTest( __mapper_args__ = {"polymorphic_identity": "bar"} @classmethod - def insert_data(cls): + def insert_data(cls, connection): Foo, Bar = cls.classes("Foo", "Bar") - session = Session() + session = Session(connection) target = Bar(id=1) b1 = Bar(id=2, foo=Foo(id=3, foo=target)) session.add(b1) @@ -2933,12 +2933,12 @@ class TestExistingRowPopulation(fixtures.DeclarativeMappedTest): id = Column(Integer, primary_key=True) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, A2, B, C1o2m, C2o2m, C1m2o, C2m2o = cls.classes( "A", "A2", "B", "C1o2m", "C2o2m", "C1m2o", "C2m2o" ) - s = Session() + s = Session(connection) b = B( c1_o2m=[C1o2m()], c2_o2m=[C2o2m()], c1_m2o=C1m2o(), c2_m2o=C2m2o() @@ -3015,10 +3015,10 @@ class SingleInhSubclassTest( user_id = Column(Integer, ForeignKey("user.id")) @classmethod - def insert_data(cls): + def insert_data(cls, connection): EmployerUser, Role = cls.classes("EmployerUser", "Role") - s = Session() + s = Session(connection) s.add(EmployerUser(roles=[Role(), Role(), Role()])) s.commit() @@ -3066,10 +3066,10 @@ class MissingForeignTest( y = Column(Integer) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, B = cls.classes("A", "B") - s = Session() + s = Session(connection) b1, b2 = B(id=1, x=5, y=9), B(id=2, x=10, y=8) s.add_all( [ @@ -3120,10 +3120,10 @@ class M2OWDegradeTest( y = Column(Integer) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, B = cls.classes("A", "B") - s = Session() + s = Session(connection) b1, b2 = B(id=1, x=5, y=9), B(id=2, x=10, y=8) s.add_all( [ @@ -3359,11 +3359,11 @@ class SameNamePolymorphicTest(fixtures.DeclarativeMappedTest): parent = relationship("ParentB", back_populates="children") @classmethod - def insert_data(cls): + def insert_data(cls, connection): ParentA, ParentB, ChildA, ChildB = cls.classes( "ParentA", "ParentB", "ChildA", "ChildB" ) - session = Session() + session = Session(connection) parent_a = ParentA(id=1) parent_b = ParentB(id=2) for i in range(10): diff --git a/test/orm/test_subquery_relations.py b/test/orm/test_subquery_relations.py index ddd8306775..61ff11ec9c 100644 --- a/test/orm/test_subquery_relations.py +++ b/test/orm/test_subquery_relations.py @@ -1633,7 +1633,7 @@ class BaseRelationFromJoinedSubclassTest(_Polymorphic): mapper(Page, pages) @classmethod - def insert_data(cls): + def insert_data(cls, connection): e1 = Engineer(primary_language="java") e2 = Engineer(primary_language="c++") @@ -1654,7 +1654,7 @@ class BaseRelationFromJoinedSubclassTest(_Polymorphic): ), ] e2.paperwork = [Paperwork(description="tps report #3")] - sess = create_session() + sess = create_session(connection) sess.add_all([e1, e2]) sess.flush() @@ -2124,9 +2124,9 @@ class SubRelationFromJoinedSubclassMultiLevelTest(_Polymorphic): mapper(MachineType, machine_type) @classmethod - def insert_data(cls): + def insert_data(cls, connection): c1 = cls._fixture() - sess = create_session() + sess = create_session(connection) sess.add(c1) sess.flush() @@ -2778,7 +2778,7 @@ class SubqueryloadDistinctTest( movie_id = Column(Integer, ForeignKey("movie.id")) @classmethod - def insert_data(cls): + def insert_data(cls, connection): Movie = cls.classes.Movie Director = cls.classes.Director DirectorPhoto = cls.classes.DirectorPhoto @@ -2790,7 +2790,7 @@ class SubqueryloadDistinctTest( Movie(title="Manhattan", credits=[Credit(), Credit()]), Movie(title="Sweet and Lowdown", credits=[Credit()]), ] - sess = create_session() + sess = create_session(connection) sess.add_all([d]) sess.flush() @@ -2954,11 +2954,11 @@ class JoinedNoLoadConflictTest(fixtures.DeclarativeMappedTest): ) @classmethod - def insert_data(cls): + def insert_data(cls, connection): Parent = cls.classes.Parent Child = cls.classes.Child - s = Session() + s = Session(connection) s.add(Parent(name="parent", children=[Child(name="c1")])) s.commit() @@ -3004,10 +3004,10 @@ class SelfRefInheritanceAliasedTest( __mapper_args__ = {"polymorphic_identity": "bar"} @classmethod - def insert_data(cls): + def insert_data(cls, connection): Foo, Bar = cls.classes("Foo", "Bar") - session = Session() + session = Session(connection) target = Bar(id=1) b1 = Bar(id=2, foo=Foo(id=3, foo=target)) session.add(b1) @@ -3113,12 +3113,12 @@ class TestExistingRowPopulation(fixtures.DeclarativeMappedTest): id = Column(Integer, primary_key=True) @classmethod - def insert_data(cls): + def insert_data(cls, connection): A, A2, B, C1o2m, C2o2m, C1m2o, C2m2o = cls.classes( "A", "A2", "B", "C1o2m", "C2o2m", "C1m2o", "C2m2o" ) - s = Session() + s = Session(connection) b = B( c1_o2m=[C1o2m()], c2_o2m=[C2o2m()], c1_m2o=C1m2o(), c2_m2o=C2m2o() diff --git a/test/orm/test_update_delete.py b/test/orm/test_update_delete.py index b90202f33f..46bb870621 100644 --- a/test/orm/test_update_delete.py +++ b/test/orm/test_update_delete.py @@ -56,16 +56,17 @@ class UpdateDeleteTest(fixtures.MappedTest): pass @classmethod - def insert_data(cls): + def insert_data(cls, connection): users = cls.tables.users - users.insert().execute( + connection.execute( + users.insert(), [ dict(id=1, name="john", age_int=25), dict(id=2, name="jack", age_int=47), dict(id=3, name="jill", age_int=29), dict(id=4, name="jane", age_int=37), - ] + ], ) @classmethod @@ -743,26 +744,28 @@ class UpdateDeleteIgnoresLoadersTest(fixtures.MappedTest): pass @classmethod - def insert_data(cls): + def insert_data(cls, connection): users = cls.tables.users - users.insert().execute( + connection.execute( + users.insert(), [ dict(id=1, name="john", age=25), dict(id=2, name="jack", age=47), dict(id=3, name="jill", age=29), dict(id=4, name="jane", age=37), - ] + ], ) documents = cls.tables.documents - documents.insert().execute( + connection.execute( + documents.insert(), [ dict(id=1, user_id=1, title="foo"), dict(id=2, user_id=1, title="bar"), dict(id=3, user_id=2, title="baz"), - ] + ], ) @classmethod @@ -862,16 +865,17 @@ class UpdateDeleteFromTest(fixtures.MappedTest): pass @classmethod - def insert_data(cls): + def insert_data(cls, connection): users = cls.tables.users - users.insert().execute( - [dict(id=1), dict(id=2), dict(id=3), dict(id=4)] + connection.execute( + users.insert(), [dict(id=1), dict(id=2), dict(id=3), dict(id=4)] ) documents = cls.tables.documents - documents.insert().execute( + connection.execute( + documents.insert(), [ dict(id=1, user_id=1, title="foo"), dict(id=2, user_id=1, title="bar"), @@ -879,7 +883,7 @@ class UpdateDeleteFromTest(fixtures.MappedTest): dict(id=4, user_id=2, title="hoho"), dict(id=5, user_id=3, title="lala"), dict(id=6, user_id=3, title="bleh"), - ] + ], ) @classmethod @@ -1140,13 +1144,13 @@ class InheritTest(fixtures.DeclarativeMappedTest): manager_name = Column(String(50)) @classmethod - def insert_data(cls): + def insert_data(cls, connection): Engineer, Person, Manager = ( cls.classes.Engineer, cls.classes.Person, cls.classes.Manager, ) - s = Session(testing.db) + s = Session(connection) s.add_all( [ Engineer(name="e1", engineer_name="e1"), diff --git a/test/sql/test_defaults.py b/test/sql/test_defaults.py index b7454cf198..f72f446798 100644 --- a/test/sql/test_defaults.py +++ b/test/sql/test_defaults.py @@ -1449,11 +1449,12 @@ class InsertFromSelectTest(fixtures.TablesTest): Table("data", metadata, Column("x", Integer), Column("y", Integer)) @classmethod - def insert_data(cls): + def insert_data(cls, connection): data = cls.tables.data - with testing.db.connect() as conn: - conn.execute(data.insert(), [{"x": 2, "y": 5}, {"x": 7, "y": 12}]) + connection.execute( + data.insert(), [{"x": 2, "y": 5}, {"x": 7, "y": 12}] + ) @testing.provide_metadata def test_insert_from_select_override_defaults(self, connection): diff --git a/test/sql/test_resultset.py b/test/sql/test_resultset.py index 5987c77467..db7c1f47b2 100644 --- a/test/sql/test_resultset.py +++ b/test/sql/test_resultset.py @@ -1250,17 +1250,19 @@ class KeyTargetingTest(fixtures.TablesTest): ) @classmethod - def insert_data(cls): - cls.tables.keyed1.insert().execute(dict(b="a1", q="c1")) - cls.tables.keyed2.insert().execute(dict(a="a2", b="b2")) - cls.tables.keyed3.insert().execute(dict(a="a3", d="d3")) - cls.tables.keyed4.insert().execute(dict(b="b4", q="q4")) - cls.tables.content.insert().execute(type="t1") + def insert_data(cls, connection): + conn = connection + conn.execute(cls.tables.keyed1.insert(), dict(b="a1", q="c1")) + conn.execute(cls.tables.keyed2.insert(), dict(a="a2", b="b2")) + conn.execute(cls.tables.keyed3.insert(), dict(a="a3", d="d3")) + conn.execute(cls.tables.keyed4.insert(), dict(b="b4", q="q4")) + conn.execute(cls.tables.content.insert(), dict(type="t1")) if testing.requires.schemas.enabled: - cls.tables[ - "%s.wschema" % testing.config.test_schema - ].insert().execute(dict(b="a1", q="c1")) + conn.execute( + cls.tables["%s.wschema" % testing.config.test_schema].insert(), + dict(b="a1", q="c1"), + ) @testing.requires.schemas def test_keyed_accessor_wschema(self): @@ -1472,9 +1474,9 @@ class PositionalTextTest(fixtures.TablesTest): ) @classmethod - def insert_data(cls): - cls.tables.text1.insert().execute( - [dict(a="a1", b="b1", c="c1", d="d1")] + def insert_data(cls, connection): + connection.execute( + cls.tables.text1.insert(), [dict(a="a1", b="b1", c="c1", d="d1")], ) def test_via_column(self): @@ -1651,8 +1653,8 @@ class AlternateResultProxyTest(fixtures.TablesTest): ) @classmethod - def insert_data(cls): - cls.engine.execute( + def insert_data(cls, connection): + connection.execute( cls.tables.test.insert(), [{"x": i, "y": "t_%d" % i} for i in range(1, 12)], )