|
1 | 1 | # -*- coding: utf-8 -*- |
2 | | -from copy import deepcopy |
3 | | -from urllib.parse import parse_qs, urlsplit |
4 | | - |
5 | | -import pytest |
6 | | -import trakt |
7 | 2 | from trakt.movies import Movie |
8 | 3 | from trakt.people import Person |
9 | 4 | from trakt.tv import TVEpisode, TVSeason, TVShow |
@@ -130,67 +125,6 @@ def test_watched(): |
130 | 125 | assert all([isinstance(s, TVShow) for s in sean.watched_shows]) |
131 | 126 |
|
132 | 127 |
|
133 | | -def test_watched_movies_pagination(): |
134 | | - sean = User('sean') |
135 | | - client = trakt.core.api() |
136 | | - request_calls = [] |
137 | | - original_request = client.request |
138 | | - |
139 | | - def request(method, uri, data=None): |
140 | | - request_calls.append((method, uri, data)) |
141 | | - if uri.startswith('users/sean/watched/movies?'): |
142 | | - query = parse_qs(urlsplit(f'https://api.trakt.tv/{uri}').query) |
143 | | - if query.get('limit') == ['1']: |
144 | | - response = original_request('GET', 'users/sean/watched/movies') |
145 | | - return deepcopy(response[:1]) |
146 | | - if uri == 'users/sean/watched/movies': |
147 | | - response = original_request('GET', 'users/sean/watched/movies') |
148 | | - return deepcopy(response) |
149 | | - return original_request(method, uri, data) |
150 | | - |
151 | | - client.request = request |
152 | | - try: |
153 | | - expected_uri = 'users/sean/watched/movies?page=2&limit=1' |
154 | | - watched_movies = sean.get_watched_movies(page=2, limit=1) |
155 | | - assert request_calls[-1] == ('get', expected_uri, None) |
156 | | - assert len(watched_movies) == 1 |
157 | | - assert all([isinstance(movie, Movie) for movie in watched_movies]) |
158 | | - |
159 | | - watched_movies = sean.get_watched_movies(limit=1) |
160 | | - assert request_calls[-1] == ('get', 'users/sean/watched/movies?limit=1', |
161 | | - None) |
162 | | - assert len(watched_movies) == 1 |
163 | | - assert all([isinstance(movie, Movie) for movie in watched_movies]) |
164 | | - |
165 | | - watched_movies = sean.watched_movies |
166 | | - assert request_calls[-1] == ('get', 'users/sean/watched/movies', None) |
167 | | - assert all([isinstance(movie, Movie) for movie in watched_movies]) |
168 | | - finally: |
169 | | - client.request = original_request |
170 | | - |
171 | | - |
172 | | -def test_watched_movies_pagination_validation(): |
173 | | - sean = User('sean') |
174 | | - |
175 | | - with pytest.raises(ValueError, match='page must be a positive integer'): |
176 | | - sean.get_watched_movies(page=0) |
177 | | - |
178 | | - with pytest.raises(ValueError, match='page must be a positive integer'): |
179 | | - sean.get_watched_movies(page=-1) |
180 | | - |
181 | | - with pytest.raises(ValueError, match='page must be a valid integer'): |
182 | | - sean.get_watched_movies(page='invalid') |
183 | | - |
184 | | - with pytest.raises(ValueError, match='limit must be a positive integer'): |
185 | | - sean.get_watched_movies(limit=0) |
186 | | - |
187 | | - with pytest.raises(ValueError, match='limit must be a positive integer'): |
188 | | - sean.get_watched_movies(limit=-1) |
189 | | - |
190 | | - with pytest.raises(ValueError, match='limit must be a valid integer'): |
191 | | - sean.get_watched_movies(limit='invalid') |
192 | | - |
193 | | - |
194 | 128 | def test_stats(): |
195 | 129 | sean = User('sean') |
196 | 130 | assert isinstance(sean.get_stats(), dict) |
|
0 commit comments