remember-remember-bot/tests/test_util.py

56 lines
1.5 KiB
Python
Raw Normal View History

2023-09-01 15:01:03 +00:00
from remember_remember_bot.util import (
check_new_day,
update_day,
chat_is_active,
get_file_path,
)
import pytest
def test_update_day():
current_day = 0
assert check_new_day(current_day)
current_day = update_day()
assert not check_new_day(current_day)
@pytest.mark.parametrize(
("messages", "active"),
[
(["/start"], True),
(["/start", "/stop"], False),
(["/start", "/stop", "Let's get this party started"], False),
2023-09-01 21:58:54 +00:00
(
[
"/start",
"Message deletion timer is set to 1 day by",
"Message deletion timer is disabled by",
"I will stop sending you messages now.",
],
False,
),
2023-09-01 15:01:03 +00:00
(["/start", "/stop", "/start"], True),
],
)
def test_chat_is_active(messages, active):
assert chat_is_active(messages) == active
@pytest.mark.parametrize(
2023-09-01 21:58:54 +00:00
"messages, tmp_file_path",
2023-09-01 15:01:03 +00:00
[
2023-09-01 21:58:54 +00:00
(["/file %file_path%"], "test1"),
(["/file %file_path%", "/stop"], "test2"),
(["I stored your reminders at the file %file_path%"], "test3"),
2023-09-01 15:01:03 +00:00
(["/start", "/stop", "/start"], None),
],
2023-09-01 21:58:54 +00:00
indirect=["tmp_file_path"],
2023-09-01 15:01:03 +00:00
)
2023-09-01 21:58:54 +00:00
def test_get_file_path(messages: [], tmp_file_path: str):
if tmp_file_path:
for listitem in range(len(messages)):
messages[listitem] = messages[listitem].replace(
"%file_path%", tmp_file_path
)
assert get_file_path(messages) == tmp_file_path