@@ -39,6 +39,13 @@ def locale_variables(country, language):
3939 }
4040
4141
42+ def list_variables (min_year , max_year , object_types ):
43+ return {
44+ "objectTypes" : object_types ,
45+ "releaseYear" : {"min" : min_year , "max" : max_year },
46+ }
47+
48+
4249@patch ("simplejustwatchapi.query.GRAPHQL_SEARCH_QUERY" , DUMMY_SEARCH_QUERY )
4350@mark .parametrize (
4451 argnames = (
@@ -49,13 +56,38 @@ def locale_variables(country, language):
4956 "best_only" ,
5057 "offset" ,
5158 "providers" ,
59+ "min_year" ,
60+ "max_year" ,
61+ "object_types" ,
5262 ),
5363 argvalues = [
54- ("TITLE 1" , "US" , "en" , 5 , True , 0 , "" ),
55- ("TITLE 2" , "gb" , "fr" , 10 , False , 20 , ["provider1" , "provider2" ]),
56- ("TITLE 3" , "fr" , "de-SWITZ123" , 20 , True , 20 , "provider3" ),
57- ("TITLE 4" , "it" , "ro-HELLO123" , 30 , True , 30 , []),
58- ("TITLE 5" , "dk" , "us" , 40 , True , 40 , None ),
64+ ("TITLE 1" , "US" , "en" , 5 , True , 0 , "" , 1990 , 2000 , ["SHOW" , "MOVIE" ]),
65+ (
66+ "TITLE 2" ,
67+ "gb" ,
68+ "fr" ,
69+ 10 ,
70+ False ,
71+ 20 ,
72+ ["provider1" , "provider2" ],
73+ 2000 ,
74+ None ,
75+ "MOVIE" ,
76+ ),
77+ (
78+ "TITLE 3" ,
79+ "fr" ,
80+ "de-SWITZ123" ,
81+ 20 ,
82+ True ,
83+ 20 ,
84+ "provider3" ,
85+ None ,
86+ 2020 ,
87+ ["SHOW" ],
88+ ),
89+ ("TITLE 4" , "it" , "ro-HELLO123" , 30 , True , 30 , [], None , None , "SHOW" ),
90+ ("TITLE 5" , "dk" , "us" , 40 , True , 40 , None , 2030 , 2040 , ["MOVIE" ]),
5991 ],
6092)
6193def test_prepare_search_request (
@@ -66,33 +98,59 @@ def test_prepare_search_request(
6698 best_only ,
6799 offset ,
68100 providers ,
101+ min_year ,
102+ max_year ,
103+ object_types ,
69104):
70105 expected_request = {
71106 "operationName" : "GetSearchTitles" ,
72107 "variables" : {
73108 "first" : count ,
74- "searchTitlesFilter" : {"searchQuery" : title , "packages" : providers },
109+ "searchTitlesFilter" : {
110+ "searchQuery" : title ,
111+ "packages" : providers ,
112+ ** list_variables (min_year , max_year , object_types ),
113+ },
75114 ** common_variables (best_only ),
76115 ** locale_variables (country , language ),
77116 "offset" : offset or None ,
78117 },
79118 "query" : DUMMY_SEARCH_QUERY ,
80119 }
81120 request = prepare_search_request (
82- title , country , language , count , best_only , offset , providers
121+ title ,
122+ country ,
123+ language ,
124+ count ,
125+ best_only ,
126+ offset ,
127+ providers ,
128+ min_year ,
129+ max_year ,
130+ object_types ,
83131 )
84132 assert expected_request == request
85133
86134
87135@patch ("simplejustwatchapi.query.GRAPHQL_POPULAR_QUERY" , DUMMY_POPULAR_QUERY )
88136@mark .parametrize (
89- argnames = ("country" , "language" , "count" , "best_only" , "offset" , "providers" ),
137+ argnames = (
138+ "country" ,
139+ "language" ,
140+ "count" ,
141+ "best_only" ,
142+ "offset" ,
143+ "providers" ,
144+ "min_year" ,
145+ "max_year" ,
146+ "object_types" ,
147+ ),
90148 argvalues = [
91- ("US" , "en-123ASD" , 5 , True , 0 , "" ),
92- ("gb" , "fr" , 10 , False , 20 , ["provider1" , "provider2" ]),
93- ("fr" , "de-FGH76" , 20 , True , 20 , "provider3" ),
94- ("it" , "ro" , 30 , True , 30 , []),
95- ("dk" , "us" , 40 , True , 40 , None ),
149+ ("US" , "en-123ASD" , 5 , True , 0 , "" , 1990 , 2000 , [ "SHOW" , "MOVIE" ] ),
150+ ("gb" , "fr" , 10 , False , 20 , ["provider1" , "provider2" ], 2000 , 2010 , "MOVIE" ),
151+ ("fr" , "de-FGH76" , 20 , True , 20 , "provider3" , None , 2020 , [ "SHOW" ] ),
152+ ("it" , "ro" , 30 , True , 30 , [], 2020 , None , "SHOW" ),
153+ ("dk" , "us" , 40 , True , 40 , None , None , None , [ "MOVIE" ] ),
96154 ],
97155)
98156def test_prepare_popular_request (
@@ -102,20 +160,34 @@ def test_prepare_popular_request(
102160 best_only ,
103161 offset ,
104162 providers ,
163+ min_year ,
164+ max_year ,
165+ object_types ,
105166):
106167 expected_request = {
107168 "operationName" : "GetPopularTitles" ,
108169 "variables" : {
109170 "first" : count ,
110- "popularTitlesFilter" : {"packages" : providers },
171+ "popularTitlesFilter" : {
172+ "packages" : providers ,
173+ ** list_variables (min_year , max_year , object_types ),
174+ },
111175 ** common_variables (best_only ),
112176 ** locale_variables (country , language ),
113177 "offset" : offset or None ,
114178 },
115179 "query" : DUMMY_POPULAR_QUERY ,
116180 }
117181 request = prepare_popular_request (
118- country , language , count , best_only , offset , providers
182+ country ,
183+ language ,
184+ count ,
185+ best_only ,
186+ offset ,
187+ providers ,
188+ min_year ,
189+ max_year ,
190+ object_types ,
119191 )
120192 assert expected_request == request
121193
0 commit comments