summaryrefslogtreecommitdiff
path: root/test/orm/test_unitofworkv2.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/orm/test_unitofworkv2.py')
-rw-r--r--test/orm/test_unitofworkv2.py150
1 files changed, 107 insertions, 43 deletions
diff --git a/test/orm/test_unitofworkv2.py b/test/orm/test_unitofworkv2.py
index 126b95082..8fd1df148 100644
--- a/test/orm/test_unitofworkv2.py
+++ b/test/orm/test_unitofworkv2.py
@@ -1910,7 +1910,7 @@ class EagerDefaultsTest(fixtures.MappedTest):
self.assert_sql_count(testing.db, go, 0)
- def test_insert_defaults_non_present(self):
+ def test_insert_defaults_nonpresent(self):
Thing = self.classes.Thing
s = Session()
@@ -1921,20 +1921,40 @@ class EagerDefaultsTest(fixtures.MappedTest):
s.add_all([t1, t2])
- self.assert_sql_execution(
- testing.db,
- s.commit,
- CompiledSQL(
- "INSERT INTO test (id) VALUES (%(id)s) RETURNING test.foo",
- [{'id': 1}],
- dialect='postgresql'
- ),
- CompiledSQL(
- "INSERT INTO test (id) VALUES (%(id)s) RETURNING test.foo",
- [{'id': 2}],
- dialect='postgresql'
- ),
- )
+ if testing.db.dialect.implicit_returning:
+ self.assert_sql_execution(
+ testing.db,
+ s.commit,
+ CompiledSQL(
+ "INSERT INTO test (id) VALUES (%(id)s) RETURNING test.foo",
+ [{'id': 1}],
+ dialect='postgresql'
+ ),
+ CompiledSQL(
+ "INSERT INTO test (id) VALUES (%(id)s) RETURNING test.foo",
+ [{'id': 2}],
+ dialect='postgresql'
+ ),
+ )
+ else:
+ self.assert_sql_execution(
+ testing.db,
+ s.commit,
+ CompiledSQL(
+ "INSERT INTO test (id) VALUES (:id)",
+ [{'id': 1}, {'id': 2}]
+ ),
+ CompiledSQL(
+ "SELECT test.foo AS test_foo FROM test "
+ "WHERE test.id = :param_1",
+ [{'param_1': 1}]
+ ),
+ CompiledSQL(
+ "SELECT test.foo AS test_foo FROM test "
+ "WHERE test.id = :param_1",
+ [{'param_1': 2}]
+ )
+ )
def test_update_defaults_nonpresent(self):
Thing2 = self.classes.Thing2
@@ -1957,34 +1977,78 @@ class EagerDefaultsTest(fixtures.MappedTest):
t4.foo = 8
t4.bar = 12
- self.assert_sql_execution(
- testing.db,
- s.commit,
- CompiledSQL(
- "UPDATE test2 SET foo=%(foo)s WHERE test2.id = %(test2_id)s "
- "RETURNING test2.bar",
- [{'foo': 5, 'test2_id': 1}],
- dialect='postgresql'
- ),
- CompiledSQL(
- "UPDATE test2 SET foo=%(foo)s, bar=%(bar)s "
- "WHERE test2.id = %(test2_id)s",
- [{'foo': 6, 'bar': 10, 'test2_id': 2}],
- dialect='postgresql'
- ),
- CompiledSQL(
- "UPDATE test2 SET foo=%(foo)s WHERE test2.id = %(test2_id)s "
- "RETURNING test2.bar",
- [{'foo': 7, 'test2_id': 3}],
- dialect='postgresql'
- ),
- CompiledSQL(
- "UPDATE test2 SET foo=%(foo)s, bar=%(bar)s "
- "WHERE test2.id = %(test2_id)s",
- [{'foo': 8, 'bar': 12, 'test2_id': 4}],
- dialect='postgresql'
- ),
- )
+ if testing.db.dialect.implicit_returning:
+ self.assert_sql_execution(
+ testing.db,
+ s.flush,
+ CompiledSQL(
+ "UPDATE test2 SET foo=%(foo)s "
+ "WHERE test2.id = %(test2_id)s "
+ "RETURNING test2.bar",
+ [{'foo': 5, 'test2_id': 1}],
+ dialect='postgresql'
+ ),
+ CompiledSQL(
+ "UPDATE test2 SET foo=%(foo)s, bar=%(bar)s "
+ "WHERE test2.id = %(test2_id)s",
+ [{'foo': 6, 'bar': 10, 'test2_id': 2}],
+ dialect='postgresql'
+ ),
+ CompiledSQL(
+ "UPDATE test2 SET foo=%(foo)s "
+ "WHERE test2.id = %(test2_id)s "
+ "RETURNING test2.bar",
+ [{'foo': 7, 'test2_id': 3}],
+ dialect='postgresql'
+ ),
+ CompiledSQL(
+ "UPDATE test2 SET foo=%(foo)s, bar=%(bar)s "
+ "WHERE test2.id = %(test2_id)s",
+ [{'foo': 8, 'bar': 12, 'test2_id': 4}],
+ dialect='postgresql'
+ ),
+ )
+ else:
+ self.assert_sql_execution(
+ testing.db,
+ s.flush,
+ CompiledSQL(
+ "UPDATE test2 SET foo=:foo WHERE test2.id = :test2_id",
+ [{'foo': 5, 'test2_id': 1}]
+ ),
+ CompiledSQL(
+ "UPDATE test2 SET foo=:foo, bar=:bar "
+ "WHERE test2.id = :test2_id",
+ [{'foo': 6, 'bar': 10, 'test2_id': 2}],
+ ),
+ CompiledSQL(
+ "UPDATE test2 SET foo=:foo WHERE test2.id = :test2_id",
+ [{'foo': 7, 'test2_id': 3}]
+ ),
+ CompiledSQL(
+ "UPDATE test2 SET foo=:foo, bar=:bar "
+ "WHERE test2.id = :test2_id",
+ [{'foo': 8, 'bar': 12, 'test2_id': 4}],
+ ),
+ CompiledSQL(
+ "SELECT test2.bar AS test2_bar FROM test2 "
+ "WHERE test2.id = :param_1",
+ [{'param_1': 1}]
+ ),
+ CompiledSQL(
+ "SELECT test2.bar AS test2_bar FROM test2 "
+ "WHERE test2.id = :param_1",
+ [{'param_1': 3}]
+ )
+ )
+
+ def go():
+ eq_(t1.bar, 2)
+ eq_(t2.bar, 10)
+ eq_(t3.bar, 4)
+ eq_(t4.bar, 12)
+
+ self.assert_sql_count(testing.db, go, 0)
def test_update_defaults_present(self):
Thing2 = self.classes.Thing2