-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: change test method for test_get_calendar_text
- Loading branch information
Showing
6 changed files
with
40 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ on: | |
|
||
jobs: | ||
build_and_publish_image: | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,48 @@ | ||
import datetime | ||
import importlib | ||
from unittest.mock import patch, MagicMock | ||
|
||
import requests_mock | ||
|
||
import utils.calendar_converter | ||
from utils.consts import url_list_events, url_list_teams, url_authenticate | ||
from .test_utils import ( | ||
read_text_by_name, | ||
replace_unwanted_lines, | ||
replace_last_sync_and_sequence, | ||
) | ||
from utils.calendar_converter import CalendarConverter | ||
from utils.consts import url_list_events, url_list_teams, url_authenticate | ||
|
||
|
||
def test_get_calendar_text() -> None: | ||
@patch("utils.datetime_utils.get_current_timestamp", return_value=173512350) | ||
@patch( | ||
"utils.datetime_utils.get_current_datetime", | ||
return_value=datetime.datetime(2024, 12, 25, 10, 45, 0), | ||
) | ||
def test_get_calendar_text( | ||
timestamp_mock: MagicMock, | ||
datetime_mock: MagicMock, | ||
) -> None: | ||
importlib.reload(utils.calendar_converter) | ||
|
||
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.ics") | ||
) | ||
|
||
with requests_mock.Mocker() as m: | ||
m.post( | ||
with requests_mock.Mocker() as request_mocker: | ||
request_mocker.post( | ||
url_authenticate, | ||
status_code=200, | ||
cookies={"sporteasy": "token test calendar"}, | ||
) | ||
m.get(url_list_teams, text=mocked_response_teams) | ||
m.get(url_list_events.format(team_id=1), text=mocked_response_events) | ||
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 = CalendarConverter() | ||
converter = utils.calendar_converter.CalendarConverter() | ||
calendar_text = converter.get_calendar_text("username", "password", "1") | ||
|
||
result = replace_last_sync_and_sequence(replace_unwanted_lines(calendar_text)) | ||
result = replace_unwanted_lines(calendar_text) | ||
assert result == expected_calendar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import time | ||
import datetime | ||
|
||
|
||
def get_current_timestamp() -> int: | ||
return int(time.time() / 10) | ||
|
||
|
||
def get_current_datetime() -> datetime.datetime: | ||
return datetime.datetime.now() |