From 5e389b46fc3e0caa8904ff611b9c9445b5c7a5a6 Mon Sep 17 00:00:00 2001 From: James McKinney <26463+jpmckinney@users.noreply.github.com> Date: Thu, 7 Nov 2024 09:32:32 -0500 Subject: [PATCH] chore: Simplify logic, because either both or neither of date_from and date_to are set --- data_registry/views.py | 6 ++---- tests/data_registry/test_views.py | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/data_registry/views.py b/data_registry/views.py index fa94c56..7d3554a 100644 --- a/data_registry/views.py +++ b/data_registry/views.py @@ -213,10 +213,8 @@ def detail(request, pk): "dateModified": collection.modified.isoformat(), } - if job and (job.date_from or job.date_to): - dataset["temporalCoverage"] = "/".join( - date.strftime("%Y-%m-%d") if date else ".." for date in (job.date_from, job.date_to) - ) + if job and job.date_from and job.date_to: + dataset["temporalCoverage"] = f"{job.date_from.strftime('%Y-%m-%d')}/{job.date_to.strftime('%Y-%m-%d')}" if language := collection.language: dataset["inLanguage"] = language diff --git a/tests/data_registry/test_views.py b/tests/data_registry/test_views.py index 58e7e85..de510b7 100644 --- a/tests/data_registry/test_views.py +++ b/tests/data_registry/test_views.py @@ -68,7 +68,7 @@ def setUpTestData(cls): public=True, ) cls.collection2.active_job = cls.collection2.job_set.create( - date_from=datetime.date(2010, 2, 1), + date_from=None, date_to=None, ) cls.collection2.save() @@ -104,7 +104,7 @@ def test_detail_missing_date(self): response = Client().get(f"/en/publication/{self.collection2.id}") self.assertTemplateUsed("detail.html") - self.assertContains(response, '"temporalCoverage": "2010-02-01/..",') + self.assertNotContains(response, "temporalCoverage") def test_collection_not_found(self): with self.assertNumQueries(1): @@ -205,7 +205,7 @@ def test_publications_api(self): "retrieval_frequency": "MONTHLY", "last_retrieved": "2001-02-03", "frozen": False, - "date_from": "2010-02-01", + "date_from": None, "date_to": None, }, {