11from unittest .mock import MagicMock , patch
22
3- from pytest import fixture
3+ from pytest import fixture , mark
44
5- from simplejustwatchapi .justwatch import details , offers_for_countries , search
5+ from simplejustwatchapi .justwatch import details , episodes , offers_for_countries , search , seasons
66
77JUSTWATCH_GRAPHQL_URL = "https://apis.justwatch.com/graphql"
88
1616DUMMY_ENTRIES = [MagicMock (), MagicMock (), None ]
1717
1818
19- @fixture
19+ @fixture ( autouse = True )
2020def httpx_post_mock (mocker ):
2121 post_mock = mocker .patch ("simplejustwatchapi.justwatch.post" )
2222 post_mock .return_value .json .return_value = DUMMY_RESPONSE
@@ -27,20 +27,44 @@ def httpx_post_mock(mocker):
2727
2828@patch ("simplejustwatchapi.justwatch.parse_search_response" , return_value = DUMMY_ENTRIES )
2929@patch ("simplejustwatchapi.justwatch.prepare_search_request" , return_value = DUMMY_REQUEST )
30- def test_search (requests_mock , parser_mock , httpx_post_mock ):
30+ def test_search (requests_mock , parser_mock ):
3131 results = search (* SEARCH_INPUT )
3232 requests_mock .assert_called_with (* SEARCH_INPUT )
3333 parser_mock .assert_called_with (DUMMY_RESPONSE )
3434 assert results == DUMMY_ENTRIES
3535
3636
37- @patch ("simplejustwatchapi.justwatch.parse_details_response" , return_value = DUMMY_ENTRIES )
37+ @patch ("simplejustwatchapi.justwatch.parse_details_response" )
3838@patch ("simplejustwatchapi.justwatch.prepare_details_request" , return_value = DUMMY_REQUEST )
39- def test_details (requests_mock , parser_mock , httpx_post_mock ):
39+ @mark .parametrize ("parse_results" , [DUMMY_ENTRIES , None ])
40+ def test_details (requests_mock , parser_mock , parse_results ):
41+ parser_mock .return_value = parse_results
4042 results = details (* DETAILS_INPUT )
4143 requests_mock .assert_called_with (* DETAILS_INPUT )
4244 parser_mock .assert_called_with (DUMMY_RESPONSE )
43- assert results == DUMMY_ENTRIES
45+ assert results == parse_results
46+
47+
48+ @patch ("simplejustwatchapi.justwatch.parse_seasons_response" )
49+ @patch ("simplejustwatchapi.justwatch.prepare_seasons_request" , return_value = DUMMY_REQUEST )
50+ @mark .parametrize ("parse_results" , [DUMMY_ENTRIES , None ])
51+ def test_seasons (requests_mock , parser_mock , parse_results ):
52+ parser_mock .return_value = parse_results
53+ results = seasons (* DETAILS_INPUT )
54+ requests_mock .assert_called_with (* DETAILS_INPUT )
55+ parser_mock .assert_called_with (DUMMY_RESPONSE )
56+ assert results == parse_results
57+
58+
59+ @patch ("simplejustwatchapi.justwatch.parse_episodes_response" )
60+ @patch ("simplejustwatchapi.justwatch.prepare_episodes_request" , return_value = DUMMY_REQUEST )
61+ @mark .parametrize ("parse_results" , [DUMMY_ENTRIES , None ])
62+ def test_episodes (requests_mock , parser_mock , parse_results ):
63+ parser_mock .return_value = parse_results
64+ results = episodes (* DETAILS_INPUT )
65+ requests_mock .assert_called_with (* DETAILS_INPUT )
66+ parser_mock .assert_called_with (DUMMY_RESPONSE )
67+ assert results == parse_results
4468
4569
4670@patch (
@@ -49,7 +73,7 @@ def test_details(requests_mock, parser_mock, httpx_post_mock):
4973@patch (
5074 "simplejustwatchapi.justwatch.prepare_offers_for_countries_request" , return_value = DUMMY_REQUEST
5175)
52- def test_offers_for_countries (requests_mock , parser_mock , httpx_post_mock ):
76+ def test_offers_for_countries (requests_mock , parser_mock ):
5377 results = offers_for_countries (* OFFERS_INPUT )
5478 requests_mock .assert_called_with (* OFFERS_INPUT )
5579 parser_mock .assert_called_with (DUMMY_RESPONSE , OFFERS_COUNTRIES_INPUT )
0 commit comments