|
1
|
|
|
""" |
|
2
|
|
|
Tests for the Marvin BBQ action |
|
3
|
|
|
""" |
|
4
|
|
|
|
|
5
|
|
|
from unittest import mock |
|
6
|
|
|
|
|
7
|
|
|
from datetime import date |
|
8
|
|
|
from test_action import ActionTest |
|
9
|
|
|
from irc2phpbb import marvin_actions |
|
10
|
|
|
|
|
11
|
|
|
class BBQTest(ActionTest): |
|
12
|
|
|
"""Tests for the Marvin BBQ action""" |
|
13
|
|
|
def assertBBQResponse(self, todaysDate, bbqDate, expectedMessageKey): |
|
14
|
|
|
"""Assert that the proper bbq message is returned, given a date""" |
|
15
|
|
|
url = self.strings.get("barbecue").get("url") |
|
16
|
|
|
message = self.strings.get("barbecue").get(expectedMessageKey) |
|
17
|
|
|
if isinstance(message, list): |
|
18
|
|
|
message = message[1] |
|
19
|
|
|
if expectedMessageKey in ["base", "week", "eternity"]: |
|
20
|
|
|
message = message % bbqDate |
|
21
|
|
|
|
|
22
|
|
|
with mock.patch("irc2phpbb.marvin_actions.datetime") as d, mock.patch("irc2phpbb.marvin_actions.random") as r: |
|
23
|
|
|
d.date.today.return_value = todaysDate |
|
24
|
|
|
r.randint.return_value = 1 |
|
25
|
|
|
expected = f"{url}. {message}" |
|
26
|
|
|
self.assertActionOutput(marvin_actions.marvinTimeToBBQ, "dags att grilla", expected) |
|
27
|
|
|
|
|
28
|
|
|
def testTimeToBBQSpring(self): |
|
29
|
|
|
"""Test each different output possible for spring dates""" |
|
30
|
|
|
self.assertBBQResponse(date(2024, 5, 17), date(2024, 5, 17), "today") |
|
31
|
|
|
self.assertBBQResponse(date(2024, 5, 16), date(2024, 5, 17), "tomorrow") |
|
32
|
|
|
self.assertBBQResponse(date(2024, 5, 10), date(2024, 5, 17), "week") |
|
33
|
|
|
self.assertBBQResponse(date(2024, 5, 1), date(2024, 5, 17), "base") |
|
34
|
|
|
self.assertBBQResponse(date(2023, 10, 17), date(2024, 5, 17), "eternity") |
|
35
|
|
|
|
|
36
|
|
|
def testTimeToBBQAutumn(self): |
|
37
|
|
|
"""Test each different output possible for autumn dates""" |
|
38
|
|
|
self.assertBBQResponse(date(2024, 9, 20), date(2024, 9, 20), "today") |
|
39
|
|
|
self.assertBBQResponse(date(2024, 9, 19), date(2024, 9, 20), "tomorrow") |
|
40
|
|
|
self.assertBBQResponse(date(2024, 9, 13), date(2024, 9, 20), "week") |
|
41
|
|
|
self.assertBBQResponse(date(2024, 9, 4), date(2024, 9, 20), "base") |
|
42
|
|
|
|