From 36b6952f9f086448ad08f73f25ca3fa7e2dbc29c Mon Sep 17 00:00:00 2001 From: witold Date: Wed, 17 Apr 2024 15:30:41 +0200 Subject: [PATCH] feat: make public project qs embargo date aware --- lab/models/project.py | 5 ++++- lab/tests/factories.py | 1 + lab/tests/managers/test_project_manager.py | 22 +++++++++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lab/models/project.py b/lab/models/project.py index 8efa14151..960758408 100644 --- a/lab/models/project.py +++ b/lab/models/project.py @@ -24,7 +24,10 @@ def only_finished(self): return self.filter(runs__end_date__lt=timezone.now()) def only_public(self): - return self.filter(confidential=False) + embargoed_projects = Run.objects.filter( + embargo_date__gt=timezone.now() + ).values_list("project_id", flat=True) + return self.filter(confidential=False).exclude(id__in=embargoed_projects) def filter_by_status(self, status: "Project.Status"): if status == Project.Status.TO_SCHEDULE: diff --git a/lab/tests/factories.py b/lab/tests/factories.py index 08a6d07b4..0443fd309 100644 --- a/lab/tests/factories.py +++ b/lab/tests/factories.py @@ -56,6 +56,7 @@ def runs(self, create, *args, **kwargs): project=self, start_date=NOW - timedelta(days=2), end_date=NOW - timedelta(days=1), + embargo_date=NOW - timedelta(days=1), ) diff --git a/lab/tests/managers/test_project_manager.py b/lab/tests/managers/test_project_manager.py index e1d53e156..6b41afd2d 100644 --- a/lab/tests/managers/test_project_manager.py +++ b/lab/tests/managers/test_project_manager.py @@ -19,11 +19,31 @@ def test_project_only_finished(self): ) self.assertEqual(Project.objects.only_finished().count(), 1) - def test_project_only_public(self): + def test_project_only_public_confidential(self): Project.objects.create(name="Public Project", confidential=False) Project.objects.create(name="Confidential Project", confidential=True) self.assertEqual(Project.objects.only_public().count(), 1) + def test_project_only_public_embargo(self): + public_project = Project.objects.create( + name="Public Project", confidential=False + ) + RunFactory( + project=public_project, + embargo_date=timezone.now() - timezone.timedelta(days=1), + ) + empbargoed_project = Project.objects.create( + name="Embargoes Project", confidential=False + ) + RunFactory( + project=empbargoed_project, + embargo_date=timezone.now() + timezone.timedelta(days=1), + ) + + qs = Project.objects.only_public() + self.assertEqual(qs.count(), 1) + self.assertEqual(qs.first().id, public_project.id) + def test_filter_by_status(self): to_schedule_ids = [ r.project.id for r in RunFactory.create_batch(5, start_date=None)