Skip to content

Commit

Permalink
Merge pull request #902 from betagouv/feat/only_public_projects_check…
Browse files Browse the repository at this point in the history
…_embargo

feat: make public project qs embargo date aware
  • Loading branch information
wiwski authored Apr 17, 2024
2 parents f15f057 + 36b6952 commit 559191b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lab/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions lab/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)


Expand Down
22 changes: 21 additions & 1 deletion lab/tests/managers/test_project_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 559191b

Please sign in to comment.