Skip to content

Commit

Permalink
refactor: replace references to constants
Browse files Browse the repository at this point in the history
create a basic random sample of expired events with no end date
  • Loading branch information
alee committed Sep 11, 2023
1 parent 589b18b commit 975d763
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions django/core/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import random
from datetime import timedelta

from django.conf import settings
Expand Down Expand Up @@ -122,7 +123,7 @@ def setUp(self):
end_date=None,
title="No End Date Current Event",
)
for threshold in range(0, 2)
for threshold in range(Event.EXPIRED_EVENT_DAYS_THRESHOLD)
]

# expired events
Expand All @@ -131,13 +132,19 @@ def setUp(self):
end_date=now - timedelta(days=7),
title="Expired Event",
)
sample_expired_event_thresholds = set(
random.sample(range(Event.EXPIRED_EVENT_DAYS_THRESHOLD + 1, 365), 10)
)
sample_expired_event_thresholds.add(
Event.EXPIRED_EVENT_DAYS_THRESHOLD + 1
) # always test the edge
self.no_end_date_expired_events = [
self.event_factory.create(
start_date=now - timedelta(days=threshold),
end_date=None,
title="No End Date Expired Event",
)
for threshold in range(3, 20)
for threshold in sample_expired_event_thresholds
]

def test_with_expired(self):
Expand All @@ -150,11 +157,8 @@ def test_with_expired(self):

def test_upcoming(self):
events = Event.objects.upcoming()
for upcoming_event in (
[
self.upcoming_event,
self.current_event,
]
+ self.no_end_date_current_events
):
for upcoming_event in [
self.upcoming_event,
self.current_event,
] + self.no_end_date_current_events:
self.assertIn(upcoming_event, events)

0 comments on commit 975d763

Please sign in to comment.