Skip to content

Commit ad842c5

Browse files
Add unit tests to "justwatch" module
1 parent 7670488 commit ad842c5

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from unittest.mock import MagicMock, patch
2+
3+
from simplejustwatchpythonapi.justwatch import search
4+
5+
JUSTWATCH_GRAPHQL_URL = "https://apis.justwatch.com/graphql"
6+
SEARCH_INPUT = ("TITLE", "COUNTRY", "LANGUAGE", 5, True)
7+
DUMMY_REQUEST = {"dummy": "request"}
8+
DUMMY_RESPONSE = {"dummy": "response"}
9+
DUMMY_ENTRIES = [MagicMock(), MagicMock(), None]
10+
11+
12+
@patch("simplejustwatchpythonapi.justwatch.post")
13+
@patch("simplejustwatchpythonapi.justwatch.parse_search_response", return_value=DUMMY_ENTRIES)
14+
@patch("simplejustwatchpythonapi.justwatch.prepare_search_request", return_value=DUMMY_REQUEST)
15+
def test_search(requests_mock, parser_mock, httpx_mock) -> None:
16+
httpx_mock().json.return_value = DUMMY_RESPONSE
17+
18+
results = search(*SEARCH_INPUT)
19+
20+
requests_mock.assert_called_with(*SEARCH_INPUT)
21+
httpx_mock.assert_called_with(JUSTWATCH_GRAPHQL_URL, json=DUMMY_REQUEST)
22+
httpx_mock().raise_for_status.assert_called()
23+
parser_mock.assert_called_with(DUMMY_RESPONSE)
24+
assert results == DUMMY_ENTRIES

0 commit comments

Comments
 (0)