Skip to content

Commit

Permalink
Add test day check
Browse files Browse the repository at this point in the history
  • Loading branch information
erikh360 committed May 7, 2024
1 parent cfa39eb commit 4078257
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions rp_yal/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@ def test_get_ordered_content_set_weekend(self, mock_search_ocs):
self.assertIsNone(contentset_id)
mock_search_ocs.assert_not_called()

@freeze_time("2024-05-05 01:30:00")
@patch("rp_yal.utils.search_ordered_content_sets")
@patch("rp_yal.utils.get_first_matching_content_set")
def test_get_ordered_content_set_weekend_and_override(
self, mock_first_mcs, mock_search_ocs
):
"""
On the weekend we can override to Monday using the test_day field.
"""
mock_search_ocs.return_value = TEST_CONTENT_SETS
mock_first_mcs.return_value = 1

fields = {"test_day": 1}
contentset_id = utils.get_ordered_content_set(self.org, fields)

self.assertEqual(contentset_id, 1)
mock_search_ocs.assert_called_with(self.org, "low lit")
mock_first_mcs.assert_called_with(TEST_CONTENT_SETS, fields)

@freeze_time("2024-05-06 01:30:00")
@patch("rp_yal.utils.search_ordered_content_sets")
@patch("rp_yal.utils.get_first_matching_content_set")
Expand Down
6 changes: 6 additions & 0 deletions rp_yal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def get_ordered_content_set(org, fields):

weekday = datetime.today().weekday()

if fields.get("test_day"):
try:
weekday = int(fields.get("test_day")) - 1
except ValueError:
pass

if weekday == 0:
# Monday
if "low" in fields.get("sexual_health_lit_risk", ""):
Expand Down

0 comments on commit 4078257

Please sign in to comment.