Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
tbmc committed May 17, 2024
1 parent e6e73f9 commit b0b9183
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 2 deletions.
53 changes: 53 additions & 0 deletions test/data/expected_calendar_with_links.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Sporteasy Calendar Connector
CALSCALE:GREGORIAN
METHOD:PUBLISH
REFRESH-INTERVAL;VALUE=DURATION:PT8H
SUMMARY:SportEasyCalendar
VTIMEZONE:UTC
X-PUBLISHED-TTL:PT8H
X-WR-CALDESC:SportEasy Calendar | Last sync: 2024-12-25 10:45:00
X-WR-CALNAME:SportEasy Calendar
X-WR-TIMEZONE:Europe/Paris
BEGIN:VEVENT
SUMMARY:Equipe 1 - Tournoi 1 - En attente
DTSTART:20240123T070000Z
DTEND:20240123T160000Z
DTSTAMP:20240123T070000Z
UID:[email protected]
SEQUENCE:173512350
CLASS:PUBLIC
CREATED:20200101T010101Z
DESCRIPTION:Présents: 8\, En attente: 7\, Non retenu: 0\, Absents: 2\n<a
href="http://localhost:5000/api/change_my_presence?team_id=1&event_id=1&us
er_id=2&token=d120bf5afba2cd0efe3bad87db2b349b44a2b4d8170c38d2169d863b4967
a103&presence=yes">Present</a> | <a href="http://localhost:5000/api/change
_my_presence?team_id=1&event_id=1&user_id=2&token=affc58a209c0d658156dbbd7
0a18817174fc3157340bc70ba77be30a9af01b61&presence=no">Absent</a>\n\nLast s
ync: 2024-12-25 10:45:00
LAST-MODIFIED:20200101T010101Z
LOCATION:rue de la Paix\, 75000 Paris\, France
STATUS:TENTATIVE
TRANSP:OPAQUE
END:VEVENT
BEGIN:VEVENT
SUMMARY:Equipe 1 - Entrainement 2
DTSTART:20240126T180000Z
DTEND:20240126T200000Z
DTSTAMP:20240126T180000Z
UID:[email protected]
SEQUENCE:173512350
CLASS:PUBLIC
CREATED:20200101T010101Z
DESCRIPTION:<a href="http://localhost:5000/api/change_my_presence?team_id=
1&event_id=2&user_id=2&token=e70ae1a5687d0c254c22d9e26ba5507667fa8c6fcd7da
4d9b2726ac28e85f5bf&presence=yes">Present</a> | <a href="http://localhost:
5000/api/change_my_presence?team_id=1&event_id=2&user_id=2&token=fa117c23c
862e22187c409a995d5c8ed7a563cc486068b96eb5cdcabd73c5db2&presence=no">Absen
t</a>\n\nLast sync: 2024-12-25 10:45:00
LAST-MODIFIED:20200101T010101Z
LOCATION:rue de la Paix\, 75000 Paris\, France
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
File renamed without changes.
45 changes: 43 additions & 2 deletions test/test_get_calendar_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"calendar_connector.datetime_utils.get_current_datetime",
return_value=datetime.datetime(2024, 12, 25, 10, 45, 0),
)
def test_get_calendar_text(
def test_get_calendar_text_without_links(
timestamp_mock: MagicMock,
datetime_mock: MagicMock,
) -> None:
Expand All @@ -31,7 +31,7 @@ def test_get_calendar_text(
mocked_response_events = read_text_by_name("list_events.json")

expected_calendar = replace_unwanted_lines(
read_text_by_name("expected_calendar.ics")
read_text_by_name("expected_calendar_without_links.ics")
)

with requests_mock.Mocker() as request_mocker:
Expand All @@ -52,3 +52,44 @@ def test_get_calendar_text(

result = replace_unwanted_lines(calendar_text)
assert result == expected_calendar


@patch(
"calendar_connector.datetime_utils.get_current_timestamp", return_value=173512350
)
@patch(
"calendar_connector.datetime_utils.get_current_datetime",
return_value=datetime.datetime(2024, 12, 25, 10, 45, 0),
)
def test_get_calendar_text_with_links(
timestamp_mock: MagicMock,
datetime_mock: MagicMock,
) -> None:
importlib.reload(calendar_connector.calendar_converter)
importlib.reload(calendar_connector.event_convertor)

mocked_response_teams = read_text_by_name("list_teams.json")
mocked_response_events = read_text_by_name("list_events.json")

expected_calendar = replace_unwanted_lines(
read_text_by_name("expected_calendar_with_links.ics")
)

with requests_mock.Mocker() as request_mocker:
request_mocker.post(
url_authenticate,
status_code=200,
cookies={"sporteasy": "token test calendar"},
)
request_mocker.get(url_list_teams, text=mocked_response_teams)
request_mocker.get(
url_list_events.format(team_id=1), text=mocked_response_events
)

converter = calendar_connector.calendar_converter.CalendarConverter()
calendar_text = converter.get_calendar_text(
"username", "password", True, "http://localhost:5000/", "1"
)

result = replace_unwanted_lines(calendar_text)
assert result == expected_calendar

0 comments on commit b0b9183

Please sign in to comment.