Move geo cache commit handling into repository layer
This commit is contained in:
@@ -116,6 +116,51 @@ async def test_upsert_entry_and_neg_entry(tmp_path: Path) -> None:
|
||||
assert row[0] is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_upsert_entry_and_commit_commits_transaction(tmp_path: Path) -> None:
|
||||
db_path = str(tmp_path / "geo_cache.db")
|
||||
async with aiosqlite.connect(db_path) as db:
|
||||
await _create_geo_cache_table(db)
|
||||
|
||||
await geo_cache_repo.upsert_entry_and_commit(
|
||||
db,
|
||||
"13.13.13.13",
|
||||
"NL",
|
||||
"Netherlands",
|
||||
"AS1313",
|
||||
"TestOrg",
|
||||
)
|
||||
|
||||
async with db.execute("SELECT country_code FROM geo_cache WHERE ip = ?", ("13.13.13.13",)) as cur:
|
||||
row = await cur.fetchone()
|
||||
assert row is not None
|
||||
assert row[0] == "NL"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bulk_upsert_entries_and_neg_entries_and_commit_commits_once(tmp_path: Path) -> None:
|
||||
db_path = str(tmp_path / "geo_cache.db")
|
||||
async with aiosqlite.connect(db_path) as db:
|
||||
await _create_geo_cache_table(db)
|
||||
|
||||
rows = [
|
||||
("14.14.14.14", "BE", "Belgium", "AS1414", "Test"),
|
||||
]
|
||||
count, neg_count = await geo_cache_repo.bulk_upsert_entries_and_neg_entries_and_commit(
|
||||
db,
|
||||
rows,
|
||||
["15.15.15.15"],
|
||||
)
|
||||
|
||||
assert count == 1
|
||||
assert neg_count == 1
|
||||
|
||||
async with db.execute("SELECT COUNT(*) FROM geo_cache") as cur:
|
||||
row = await cur.fetchone()
|
||||
assert row is not None
|
||||
assert int(row[0]) == 2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bulk_upsert_entries_and_neg_entries(tmp_path: Path) -> None:
|
||||
db_path = str(tmp_path / "geo_cache.db")
|
||||
|
||||
Reference in New Issue
Block a user