All checks were successful
CD Pipeline / workflow-shape (push) Successful in 1s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 2m59s
CD Pipeline / build-and-deploy (push) Successful in 15m26s
AWOOOI Harbor 110 Local Repair / workflow-shape (push) Successful in 2s
AWOOOI Harbor 110 Local Repair / harbor-110-local-repair (push) Successful in 25s
CD Pipeline / post-deploy-checks (push) Successful in 1m56s
55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
from typing import Any
|
|
|
|
import src.jobs.asset_change_tracker_job as tracker
|
|
|
|
|
|
class _FakeResult:
|
|
def __init__(self, rows: list[tuple[str]] | None = None) -> None:
|
|
self._rows = rows or []
|
|
self.rowcount = 0
|
|
|
|
def fetchall(self) -> list[tuple[str]]:
|
|
return self._rows
|
|
|
|
|
|
class _FakeDb:
|
|
async def execute(
|
|
self,
|
|
statement: Any,
|
|
_params: dict[str, Any] | None = None,
|
|
) -> _FakeResult:
|
|
if "SELECT run_id FROM asset_discovery_run" in str(statement):
|
|
return _FakeResult([("newer-run",), ("older-run",)])
|
|
return _FakeResult()
|
|
|
|
|
|
class _FakeDbContext:
|
|
async def __aenter__(self) -> _FakeDb:
|
|
return _FakeDb()
|
|
|
|
async def __aexit__(self, *_args: object) -> None:
|
|
return None
|
|
|
|
|
|
def test_change_tracker_scopes_every_database_path_to_awoooi(monkeypatch: Any) -> None:
|
|
project_ids: list[str] = []
|
|
|
|
def _get_db_context(project_id: str) -> _FakeDbContext:
|
|
project_ids.append(project_id)
|
|
return _FakeDbContext()
|
|
|
|
monkeypatch.setattr("src.db.base.get_db_context", _get_db_context)
|
|
|
|
assert asyncio.run(tracker._get_recent_runs()) == ["newer-run", "older-run"]
|
|
assert asyncio.run(tracker._diff_runs("newer-run", "older-run")) == {
|
|
"added": 0,
|
|
"removed": 0,
|
|
"modified": 0,
|
|
}
|
|
asyncio.run(tracker._log_aol({"added": 0, "removed": 0, "modified": 0}, 1, None))
|
|
|
|
assert project_ids == ["awoooi", "awoooi", "awoooi"]
|