Skip to content

Commit

Permalink
fix: date in class should be updated (#248)
Browse files Browse the repository at this point in the history
* fix: date in class should be updated
  • Loading branch information
mazzi authored Feb 3, 2023
1 parent 7958972 commit 70de794
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,22 +258,32 @@ class Today(DayCommand):

def __init__(self, http_client, service_url=None):
super().__init__(http_client, service_url)
self.no_shows_message = "No shows are scheduled for today 🤷."

def __call__(
self, update: Union[Update, None], context: Union[CallbackContext, None]
) -> str:
today = dt.date.today()
self.on_day = calendar.day_name[today.weekday()].lower()
self.no_shows_message = "No shows are scheduled for today 🤷."
return super().__call__(update, context)


class Tomorrow(DayCommand):
"""Displays the radio schedule for tomorrow"""

def __init__(self, http_client, service_url=None):
super().__init__(http_client, service_url)
self.no_shows_message = "No shows are scheduled for tomorrow 🤷."

def __call__(
self, update: Union[Update, None], context: Union[CallbackContext, None]
) -> str:
tomorrow = dt.date.today() + dt.timedelta(days=1)
self.on_day = calendar.day_name[tomorrow.weekday()].lower()
# if tomorrow is monday, fetches 'nextmonday' on the array
if self.on_day.lower() == calendar.day_name[calendar.firstweekday()].lower():
self.on_day = "next" + self.on_day
self.no_shows_message = "No shows are scheduled for tomorrow 🤷."
return super().__call__(update, context)


class Week(Command):
Expand Down
49 changes: 49 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import calendar
import datetime as dt
from unittest.mock import patch

import pytest
Expand Down Expand Up @@ -364,3 +366,50 @@ def test_week_with_empty_days(self, response_week_info_with_empty_days):
mock_send.assert_called_once_with(None, None, msg)

assert msg == expected

def test_fix_today_when_day_changes(self, response_week_info_with_empty_days):
expected_for_tuesday = (
"No shows are scheduled for today 🤷.\n"
"Check the weekly schedule with /week command."
)

expected_for_wednesday = (
"Shows for Wednesday _🇩🇪 time!_\n"
"(15:00 - 17:00) - *Actual Figures*\n"
"(18:00 - 20:00) - *Kraut Kontrol*\n"
"(20:00 - 23:00) - *The Broth*\n"
"(23:00 - 23:25) - *Hearse Case Scenario - Die Bestatterinnen*\n"
)

tuesday_dt = dt.datetime(year=2020, month=12, day=29) # Tuesday
wednesday_dt = dt.datetime(year=2020, month=12, day=30) # Wednesday

with freeze_time(tuesday_dt) as frozen_datetime:
today_command = Today(http_client=requests)

assert frozen_datetime() == tuesday_dt
assert calendar.day_name[tuesday_dt.weekday()].lower() == "tuesday"

with patch.object(Command, "send", return_value=None) as mock_send:
with patch("requests.get") as patched_get:
patched_get.return_value = response_week_info_with_empty_days
msg = today_command(update=None, context=None)

patched_get.assert_called_once()
mock_send.assert_called_once_with(None, None, msg)

assert msg == expected_for_tuesday

frozen_datetime.move_to(wednesday_dt)

assert frozen_datetime() == wednesday_dt

with patch.object(Command, "send", return_value=None) as mock_send:
with patch("requests.get") as patched_get:
patched_get.return_value = response_week_info_with_empty_days
msg = today_command(update=None, context=None)

patched_get.assert_called_once()
mock_send.assert_called_once_with(None, None, msg)

assert msg == expected_for_wednesday

0 comments on commit 70de794

Please sign in to comment.