Skip to content

Commit eb48448

Browse files
glenscCopilot
andcommitted
Add tests for get_watched_movies pagination and invalid param validation
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 3b51e01 commit eb48448

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

tests/mock_data/users.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,15 @@
612612
}
613613
]
614614
},
615+
"users/sean/watched/movies?page=1&limit=1": {
616+
"GET": [
617+
{
618+
"plays":4,
619+
"last_watched_at":"2014-10-11T17:00:54.000Z",
620+
"movie":{"title":"Batman Begins","year":2005,"ids":{"trakt":6,"slug":"batman-begins-2005","imdb":"tt0372784","tmdb":272}}
621+
}
622+
]
623+
},
615624
"users/sean/watched/shows": {
616625
"GET": [
617626
{

tests/test_users.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
import pytest
23
from trakt.movies import Movie
34
from trakt.people import Person
45
from trakt.tv import TVEpisode, TVSeason, TVShow
@@ -132,6 +133,35 @@ def test_get_watched_movies():
132133
assert all([isinstance(m, Movie) for m in watched_movies])
133134

134135

136+
def test_get_watched_movies_with_pagination():
137+
sean = User('sean')
138+
watched_movies = sean.get_watched_movies(page=1, limit=1)
139+
assert isinstance(watched_movies, list)
140+
assert len(watched_movies) == 1
141+
assert isinstance(watched_movies[0], Movie)
142+
assert watched_movies[0].title == 'Batman Begins'
143+
144+
145+
def test_get_watched_movies_invalid_page():
146+
sean = User('sean')
147+
with pytest.raises(ValueError):
148+
sean.get_watched_movies(page='bad')
149+
with pytest.raises(ValueError):
150+
sean.get_watched_movies(page=0)
151+
with pytest.raises(ValueError):
152+
sean.get_watched_movies(page=True)
153+
154+
155+
def test_get_watched_movies_invalid_limit():
156+
sean = User('sean')
157+
with pytest.raises(ValueError):
158+
sean.get_watched_movies(limit='bad')
159+
with pytest.raises(ValueError):
160+
sean.get_watched_movies(limit=-1)
161+
with pytest.raises(ValueError):
162+
sean.get_watched_movies(limit=False)
163+
164+
135165
def test_stats():
136166
sean = User('sean')
137167
assert isinstance(sean.get_stats(), dict)

0 commit comments

Comments
 (0)