|
1 | 1 | from unittest.mock import MagicMock, patch |
| 2 | +from pytest import fixture |
2 | 3 |
|
3 | | -from simplejustwatchapi.justwatch import search |
| 4 | +from simplejustwatchapi.justwatch import search, details |
4 | 5 |
|
5 | 6 | JUSTWATCH_GRAPHQL_URL = "https://apis.justwatch.com/graphql" |
6 | 7 | SEARCH_INPUT = ("TITLE", "COUNTRY", "LANGUAGE", 5, True) |
| 8 | +DETAILS_INPUT = ("NODE ID", "COUNTRY", "LANGUAGE", False) |
7 | 9 | DUMMY_REQUEST = {"dummy": "request"} |
8 | 10 | DUMMY_RESPONSE = {"dummy": "response"} |
9 | 11 | DUMMY_ENTRIES = [MagicMock(), MagicMock(), None] |
10 | 12 |
|
11 | 13 |
|
12 | | -@patch("simplejustwatchapi.justwatch.post") |
| 14 | +@fixture() |
| 15 | +def httpx_post_mock(mocker): |
| 16 | + post_mock = mocker.patch("simplejustwatchapi.justwatch.post") |
| 17 | + post_mock.return_value.json.return_value = DUMMY_RESPONSE |
| 18 | + yield post_mock |
| 19 | + post_mock.assert_called_with(JUSTWATCH_GRAPHQL_URL, json=DUMMY_REQUEST) |
| 20 | + post_mock.return_value.raise_for_status.assert_called() |
| 21 | + |
| 22 | + |
13 | 23 | @patch("simplejustwatchapi.justwatch.parse_search_response", return_value=DUMMY_ENTRIES) |
14 | 24 | @patch("simplejustwatchapi.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 | | - |
| 25 | +def test_search(requests_mock, parser_mock, httpx_post_mock) -> None: |
18 | 26 | results = search(*SEARCH_INPUT) |
19 | | - |
20 | 27 | 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() |
| 28 | + parser_mock.assert_called_with(DUMMY_RESPONSE) |
| 29 | + assert results == DUMMY_ENTRIES |
| 30 | + |
| 31 | + |
| 32 | +@patch("simplejustwatchapi.justwatch.parse_details_response", return_value=DUMMY_ENTRIES) |
| 33 | +@patch("simplejustwatchapi.justwatch.prepare_details_request", return_value=DUMMY_REQUEST) |
| 34 | +def test_details(requests_mock, parser_mock, httpx_post_mock) -> None: |
| 35 | + results = details(*DETAILS_INPUT) |
| 36 | + requests_mock.assert_called_with(*DETAILS_INPUT) |
23 | 37 | parser_mock.assert_called_with(DUMMY_RESPONSE) |
24 | 38 | assert results == DUMMY_ENTRIES |
0 commit comments