From d2afc67f0e1fad4720fd4a89ad10c5a70560e6a2 Mon Sep 17 00:00:00 2001 From: Reid Hewitt Date: Thu, 25 Apr 2024 12:01:29 -0600 Subject: [PATCH 1/2] add get source by jobid method and test --- app/interface.py | 7 +++++++ tests/database/test_db.py | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/interface.py b/app/interface.py index b85f5173..025e016c 100644 --- a/app/interface.py +++ b/app/interface.py @@ -287,6 +287,13 @@ def get_harvest_record_by_source(self, source_id): HarvesterDBInterface._to_dict(rcd) for rcd in harvest_records] return harvest_records_data + def get_source_by_jobid(self, jobid): + harvest_job = self.db.query(HarvestJob).filter_by(id=jobid).first() + if harvest_job is None: + return None + else: + return HarvesterDBInterface._to_dict(harvest_job.source) + def close(self): if hasattr(self.db, "remove"): self.db.remove() diff --git a/tests/database/test_db.py b/tests/database/test_db.py index e14020ca..c72bb921 100644 --- a/tests/database/test_db.py +++ b/tests/database/test_db.py @@ -110,3 +110,18 @@ def test_delete_harvest_source(interface, source_data): deleted_source = interface.get_harvest_source(source.id) assert deleted_source is None + +@pytest.fixture +def job_data(source_data): + return {"status": "new"} + + +def test_harvest_source_by_jobid(interface, source_data, job_data): + + source = interface.add_harvest_source(source_data) + job_data["harvest_source_id"] = source.id + + harvest_job = interface.add_harvest_job(job_data) + harvest_source = interface.get_source_by_jobid(harvest_job.id) + + assert source.id == harvest_source["id"] \ No newline at end of file From d64acc17bc69c39bd966065053fcbe8646d72753 Mon Sep 17 00:00:00 2001 From: Reid Hewitt Date: Thu, 25 Apr 2024 12:02:55 -0600 Subject: [PATCH 2/2] bump --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index da451749..1cca4817 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "datagov-harvesting-logic" -version = "0.3.8" +version = "0.3.9" description = "" # authors = [ # {name = "Jin Sun", email = "jin.sun@gsa.gov"},