test :ticket:`6360`
(
self, case_, begin, modify_unconditional, expire_on_commit
)
| 335 | ("nothing",), ("modify",), ("add",), ("delete",), argnames="case_" |
| 336 | ) |
| 337 | def test_autobegin_attr_change( |
| 338 | self, case_, begin, modify_unconditional, expire_on_commit |
| 339 | ): |
| 340 | """test :ticket:`6360`""" |
| 341 | |
| 342 | User, users = self.classes.User, self.tables.users |
| 343 | |
| 344 | self.mapper_registry.map_imperatively(User, users) |
| 345 | |
| 346 | s = Session( |
| 347 | testing.db, |
| 348 | expire_on_commit=expire_on_commit, |
| 349 | ) |
| 350 | |
| 351 | u = User(name="x") |
| 352 | u2 = User(name="d") |
| 353 | u3 = User(name="e") |
| 354 | s.add_all([u, u2, u3]) |
| 355 | |
| 356 | s.commit() |
| 357 | |
| 358 | if begin: |
| 359 | s.begin() |
| 360 | |
| 361 | if case_ == "add": |
| 362 | # this autobegins |
| 363 | s.add(User(name="q")) |
| 364 | elif case_ == "delete": |
| 365 | # this autobegins |
| 366 | s.delete(u2) |
| 367 | elif case_ == "modify": |
| 368 | # this autobegins |
| 369 | u3.name = "m" |
| 370 | |
| 371 | if case_ == "nothing" and not begin: |
| 372 | assert not s._transaction |
| 373 | expect_expire = expire_on_commit |
| 374 | else: |
| 375 | assert s._transaction |
| 376 | expect_expire = True |
| 377 | |
| 378 | if modify_unconditional: |
| 379 | # this autobegins |
| 380 | u.name = "y" |
| 381 | expect_expire = True |
| 382 | |
| 383 | if not expect_expire: |
| 384 | assert not s._transaction |
| 385 | |
| 386 | # test is that state is consistent after rollback() |
| 387 | s.rollback() |
| 388 | |
| 389 | if not expect_expire: |
| 390 | assert "name" in u.__dict__ |
| 391 | else: |
| 392 | assert "name" not in u.__dict__ |
| 393 | eq_(u.name, "x") |
| 394 |