MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_pk_violation

Method test_pk_violation

test/orm/test_transaction.py:1562–1601  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1560 __sparse_driver_backend__ = True
1561
1562 def test_pk_violation(self):
1563 User, Address = self.classes.User, self.classes.Address
1564 s = fixture_session()
1565
1566 a1 = Address(email_address="foo")
1567 u1 = User(id=1, name="ed", addresses=[a1])
1568 s.add(u1)
1569 s.commit()
1570
1571 a2 = Address(email_address="bar")
1572 u2 = User(id=1, name="jack", addresses=[a2])
1573
1574 u1.name = "edward"
1575 a1.email_address = "foober"
1576 s.add(u2)
1577
1578 with expect_warnings("New instance"):
1579 assert_raises(sa_exc.IntegrityError, s.commit)
1580
1581 assert_raises(sa_exc.InvalidRequestError, s.commit)
1582 s.rollback()
1583 assert u2 not in s
1584 assert a2 not in s
1585 assert u1 in s
1586 assert a1 in s
1587 assert u1.name == "ed"
1588 assert a1.email_address == "foo"
1589 u1.name = "edward"
1590 a1.email_address = "foober"
1591 s.commit()
1592 eq_(
1593 s.query(User).all(),
1594 [
1595 User(
1596 id=1,
1597 name="edward",
1598 addresses=[Address(email_address="foober")],
1599 )
1600 ],
1601 )
1602
1603 @testing.requires.savepoints
1604 def test_pk_violation_with_savepoint(self):

Callers

nothing calls this directly

Calls 11

fixture_sessionFunction · 0.90
expect_warningsFunction · 0.90
assert_raisesFunction · 0.90
eq_Function · 0.90
AddressClass · 0.70
UserClass · 0.70
addMethod · 0.45
commitMethod · 0.45
rollbackMethod · 0.45
allMethod · 0.45
queryMethod · 0.45

Tested by

no test coverage detected