test_update_delete.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from .. import fixtures
  2. from ..assertions import eq_
  3. from ..schema import Column
  4. from ..schema import Table
  5. from ... import Integer
  6. from ... import String
  7. class SimpleUpdateDeleteTest(fixtures.TablesTest):
  8. run_deletes = "each"
  9. __backend__ = True
  10. @classmethod
  11. def define_tables(cls, metadata):
  12. Table(
  13. "plain_pk",
  14. metadata,
  15. Column("id", Integer, primary_key=True),
  16. Column("data", String(50)),
  17. )
  18. @classmethod
  19. def insert_data(cls, connection):
  20. connection.execute(
  21. cls.tables.plain_pk.insert(),
  22. [
  23. {"id": 1, "data": "d1"},
  24. {"id": 2, "data": "d2"},
  25. {"id": 3, "data": "d3"},
  26. ],
  27. )
  28. def test_update(self, connection):
  29. t = self.tables.plain_pk
  30. r = connection.execute(
  31. t.update().where(t.c.id == 2), dict(data="d2_new")
  32. )
  33. assert not r.is_insert
  34. assert not r.returns_rows
  35. assert r.rowcount == 1
  36. eq_(
  37. connection.execute(t.select().order_by(t.c.id)).fetchall(),
  38. [(1, "d1"), (2, "d2_new"), (3, "d3")],
  39. )
  40. def test_delete(self, connection):
  41. t = self.tables.plain_pk
  42. r = connection.execute(t.delete().where(t.c.id == 2))
  43. assert not r.is_insert
  44. assert not r.returns_rows
  45. assert r.rowcount == 1
  46. eq_(
  47. connection.execute(t.select().order_by(t.c.id)).fetchall(),
  48. [(1, "d1"), (3, "d3")],
  49. )
  50. __all__ = ("SimpleUpdateDeleteTest",)