|
|
@@ -104,6 +104,47 @@ def test_postgres_repository_lists_only_creation_candidates_for_decode():
|
|
|
assert items[0].platform == "xiaohongshu"
|
|
|
|
|
|
|
|
|
+def test_postgres_ensure_acquisition_job_merges_metadata_on_conflict():
|
|
|
+ job_id = uuid4()
|
|
|
+ run_id = uuid4()
|
|
|
+ query_id = uuid4()
|
|
|
+ repo = RecordingPostgresRepo()
|
|
|
+ repo.one_results.append(
|
|
|
+ {
|
|
|
+ "id": job_id,
|
|
|
+ "run_id": run_id,
|
|
|
+ "query_id": query_id,
|
|
|
+ "platform": "douyin",
|
|
|
+ "status": "done",
|
|
|
+ "search_limit": 10,
|
|
|
+ "display_limit": 5,
|
|
|
+ "attempt_count": 1,
|
|
|
+ "metadata": {"pagination": {"pages": [{"page_index": 1}]}, "query_text": "q"},
|
|
|
+ "error_message": None,
|
|
|
+ "started_at": None,
|
|
|
+ "finished_at": None,
|
|
|
+ "created_at": None,
|
|
|
+ "updated_at": None,
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ job = repo.ensure_acquisition_job(
|
|
|
+ run_id=run_id,
|
|
|
+ query_id=query_id,
|
|
|
+ platform="douyin",
|
|
|
+ search_limit=10,
|
|
|
+ display_limit=5,
|
|
|
+ status="pending",
|
|
|
+ metadata={"query_text": "q"},
|
|
|
+ )
|
|
|
+
|
|
|
+ sql, params = repo.one_calls[0]
|
|
|
+ assert "metadata = acquisition_jobs.metadata || EXCLUDED.metadata" in sql
|
|
|
+ assert params[0] == run_id
|
|
|
+ assert params[1] == query_id
|
|
|
+ assert job.metadata["pagination"]["pages"][0]["page_index"] == 1
|
|
|
+
|
|
|
+
|
|
|
def test_postgres_upsert_candidate_item_prefers_unique_key_for_existing_rows():
|
|
|
item_id = uuid4()
|
|
|
repo = RecordingPostgresRepo()
|