Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

More tests for the simple_* methods #16596

Merged
merged 15 commits into from
Nov 7, 2023
42 changes: 42 additions & 0 deletions tests/storage/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,45 @@ def test_upsert_with_where(
["oldvalue", "newvalue"],
)
self.assertTrue(result)

@defer.inlineCallbacks
def test_upsert_many(self) -> Generator["defer.Deferred[object]", object, None]:
yield defer.ensureDeferred(
self.datastore.db_pool.simple_upsert_many(
table="tablename",
key_names=["columnname"],
key_values=[["oldvalue"]],
value_names=["othercol"],
value_values=[["newvalue"]],
desc="",
)
)
clokep marked this conversation as resolved.
Show resolved Hide resolved

# TODO Test postgres variant.

self.mock_txn.executemany.assert_called_with(
"INSERT INTO tablename (columnname, othercol) VALUES (?, ?) ON CONFLICT (columnname) DO UPDATE SET othercol=EXCLUDED.othercol",
[("oldvalue", "newvalue")],
)

@defer.inlineCallbacks
def test_upsert_many_no_values(
self,
) -> Generator["defer.Deferred[object]", object, None]:
yield defer.ensureDeferred(
self.datastore.db_pool.simple_upsert_many(
table="tablename",
key_names=["columnname"],
key_values=[["oldvalue"]],
value_names=[],
value_values=[],
desc="",
)
)

# TODO Test postgres variant.

self.mock_txn.executemany.assert_called_with(
"INSERT INTO tablename (columnname) VALUES (?) ON CONFLICT (columnname) DO NOTHING",
[("oldvalue",)],
)