MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_transaction

Method test_transaction

test/orm/test_session.py:397–425  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

395 @testing.requires.independent_connections
396 @engines.close_open_connections
397 def test_transaction(self):
398 User, users = self.classes.User, self.tables.users
399
400 self.mapper_registry.map_imperatively(User, users)
401 conn1 = testing.db.connect()
402 conn2 = testing.db.connect()
403
404 sess = Session(bind=conn1)
405 u = User(name="x")
406 sess.add(u)
407 sess.flush()
408 assert (
409 conn1.exec_driver_sql("select count(1) from users").scalar() == 1
410 )
411 assert (
412 conn2.exec_driver_sql("select count(1) from users").scalar() == 0
413 )
414 sess.commit()
415 assert (
416 conn1.exec_driver_sql("select count(1) from users").scalar() == 1
417 )
418
419 assert (
420 testing.db.connect()
421 .exec_driver_sql("select count(1) from users")
422 .scalar()
423 == 1
424 )
425 sess.close()
426
427
428class SessionUtilTest(_fixtures.FixtureTest):

Callers

nothing calls this directly

Calls 10

addMethod · 0.95
flushMethod · 0.95
commitMethod · 0.95
closeMethod · 0.95
SessionClass · 0.90
map_imperativelyMethod · 0.80
UserClass · 0.70
connectMethod · 0.45
scalarMethod · 0.45
exec_driver_sqlMethod · 0.45

Tested by

no test coverage detected