def test_list_remove(): responses.add_callback( responses.GET, 'http://mock/users/me/lists/movies', callback=authenticated_response('fixtures/users/me/lists/movies.json'), content_type='application/json' ) responses.add_callback( responses.POST, 'http://mock/users/me/lists/123456/items/remove', callback=authenticated_response(data='{"mock": "mock"}'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): movies_list = Trakt['users/me/lists/movies'].get() result = movies_list.remove({ 'shows': [ {'ids': {'tvdb': 121361}} ] }) assert result is not None
def test_watched(): responses.add_callback( responses.GET, 'http://mock/sync/watched/shows', callback=authenticated_response('fixtures/sync/watched/shows.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): watched = Trakt['sync/watched'].shows() assert watched is not None assert len(watched) == 9 # Validate `Show` show = watched[('tvdb', '80348')] assert show.title == 'Chuck' assert show.year == 2007 assert len(show.seasons) == 1 assert len(show.seasons[1].episodes) == 4 # Validate `Episode` episode = show.seasons[1].episodes[2] assert episode.is_watched assert episode.last_watched_at == datetime(2015, 3, 10, 5, 21, 51) assert episode.plays == 9
def test_create(): responses.add_callback( responses.POST, 'http://mock/users/me/lists', callback=authenticated_response('fixtures/users/me/lists/movies.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): movies_list = Trakt['users/me/lists'].create(name="Movies") # Validate movies list assert movies_list.name == 'Movies' assert movies_list.description is None assert movies_list.likes == 0 assert movies_list.allow_comments is True assert movies_list.display_numbers is False assert movies_list.updated_at == datetime(2015, 6, 22, 2, 25, tzinfo=tzutc()) assert movies_list.comment_count == 0 assert movies_list.item_count == 2 assert movies_list.privacy == 'private'
def test_playback(): responses.add_callback( responses.GET, 'http://mock/sync/playback/episodes', callback=authenticated_response('fixtures/sync/playback/episodes.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): playback = Trakt['sync/playback'].episodes() assert playback is not None # Validate `Show` show = playback[('tvdb', '80348')] assert show.title == 'Chuck' assert show.year == 2007 assert len(show.seasons) == 1 # Validate `Season` season = show.seasons[1] assert season.show == show assert len(season.episodes) == 2 # Validate `Episode` episode = season.episodes[3] assert episode.show == show assert episode.season == season assert episode.paused_at == datetime(2015, 3, 9, 0, 10, 15, tzinfo=tzutc()) assert episode.progress == 4.99 # Validate `Episode.to_dict()` assert episode.to_dict() == { 'progress': 4.99, 'paused_at': '2015-03-09T00:10:15.000-00:00', 'number': 3, 'title': 'Chuck Versus the Tango', 'ids': { 'tvdb': '336271', 'tmdb': '63434', 'tvrage': '595113', 'trakt': '74043' }, 'last_watched_at': None, 'watched': 0, 'plays': 0, 'collected_at': None, 'collected': 0 }
def test_playback(): responses.add_callback( responses.GET, 'http://mock/sync/playback/episodes', callback=authenticated_response('fixtures/sync/playback/episodes.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): playback = Trakt['sync/playback'].episodes() assert playback is not None # Validate `Show` show = playback[('tvdb', '80348')] assert show.title == 'Chuck' assert show.year == 2007 assert len(show.seasons) == 1 # Validate `Season` season = show.seasons[1] assert season.show == show assert len(season.episodes) == 2 # Validate `Episode` episode = season.episodes[3] assert episode.show == show assert episode.season == season assert episode.paused_at == datetime(2015, 3, 9, 0, 10, 15) assert episode.progress == 4.99 # Validate `Episode.to_dict()` assert episode.to_dict() == { 'progress': 4.99, 'paused_at': '2015-03-09T00:10:15.000-00:00', 'number': 3, 'title': 'Chuck Versus the Tango', 'ids': { 'tvdb': '336271', 'tmdb': '63434', 'tvrage': '595113', 'trakt': '74043' }, 'last_watched_at': None, 'watched': 0, 'plays': 0, 'collected_at': None, 'collected': 0 }
def test_rating_filter(): responses.add_callback( responses.GET, 'http://mock/sync/ratings/movies/8', callback=authenticated_response('fixtures/sync/ratings/movies/8.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): collection = Trakt['sync/ratings'].movies(rating=8) # Ensure collection is valid assert_that(collection, not_none()) assert_that(collection, has_length(1)) # 100 Bloody Acres (2012) assert_that(collection[('imdb', 'tt2290065')], has_properties({ 'pk': ('imdb', 'tt2290065'), 'title': '100 Bloody Acres', 'year': 2012, 'rating': has_properties({ 'value': 8, 'timestamp': datetime(2015, 1, 28, 2, 26, 37, tzinfo=tzutc()) }), # Keys 'keys': [ ('imdb', 'tt2290065'), ('tmdb', '126757'), ('slug', '100-bloody-acres-2012'), ('trakt', '86920') ] }))
def test_watched(): responses.add_callback( responses.GET, 'http://mock/sync/watched/shows', callback=authenticated_response('fixtures/sync/watched/shows.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): watched = Trakt['sync/watched'].shows() assert watched is not None assert len(watched) == 9 # Validate `Show` show = watched[('tvdb', '80348')] assert show.title == 'Chuck' assert show.year == 2007 assert len(show.seasons) == 1 assert len(show.seasons[1].episodes) == 4 # Validate `Episode` episode = show.seasons[1].episodes[2] assert episode.is_watched assert episode.last_watched_at == datetime(2015, 3, 10, 5, 21, 51, tzinfo=tzutc()) assert episode.plays == 9
def test_create(): responses.add_callback( responses.POST, 'http://mock/users/me/lists', callback=authenticated_response('fixtures/users/me/lists/movies.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): movies_list = Trakt['users/me/lists'].create(name="Movies") # Validate movies list assert movies_list.name == 'Movies' assert movies_list.description is None assert movies_list.likes == 0 assert movies_list.allow_comments is True assert movies_list.display_numbers is False assert movies_list.updated_at == datetime(2015, 6, 22, 2, 25, tzinfo=tzutc()) assert movies_list.comment_count == 0 assert movies_list.item_count == 2 assert movies_list.privacy == 'private'
def test_shows(): responses.add_callback( responses.GET, 'http://mock/users/me/lists/shows', callback=authenticated_response('fixtures/users/me/lists/shows.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): value = Trakt['users/me/lists/shows'].get() # Validate shows list assert_that( value, has_properties({ 'name': 'Shows', 'description': None, 'likes': 0, 'allow_comments': True, 'display_numbers': False, 'updated_at': datetime(2015, 6, 22, 2, 25, tzinfo=tzutc()), 'comment_count': 0, 'item_count': 3, 'privacy': 'private' }))
def test_watched(): responses.add_callback(responses.GET, 'http://mock/users/me/lists/shows/items', callback=authenticated_response( 'fixtures/users/me/lists/shows/items.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): items = Trakt['users/me/lists/shows'].items() # Ensure collection is valid assert_that(items, not_none()) assert_that(items, has_length(3)) # Validate items assert_that( items, contains( # Game of Thrones (2011) all_of( instance_of(Show), has_properties({ 'pk': ('tvdb', '121361'), 'title': 'Game of Thrones', 'year': 2011, # Keys 'keys': [('tvdb', '121361'), ('tmdb', '1399'), ('imdb', 'tt0944947'), ('tvrage', '24493'), ('slug', 'game-of-thrones'), ('trakt', '1390')] })), # Game of Thrones (2011) - S05 all_of( instance_of(Season), has_properties({ 'pk': 5, # Keys 'keys': [5, ('tmdb', '62090'), ('trakt', '3967')] })), # Game of Thrones (2011) - S05E04 all_of( instance_of(Episode), has_properties({ 'pk': (5, 4), # Keys 'keys': [(5, 4), ('tvdb', '5150183'), ('tmdb', '1045553'), ('imdb', 'tt3866838'), ('tvrage', '1065765456'), ('trakt', '1782362')] }))))
def test_watched(): responses.add_callback( responses.GET, 'http://mock/sync/watched/movies', callback=authenticated_response('fixtures/sync/watched/movies.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): watched = Trakt['sync/watched'].movies() assert watched is not None # 100 Bloody Acres (2012) assert watched[('imdb', 'tt2290065')].title == '100 Bloody Acres' assert watched[('imdb', 'tt2290065')].year == 2012 assert watched[('imdb', 'tt2290065')].pk == ('imdb', 'tt2290065') assert watched[('imdb', 'tt2290065')].keys == [ ('imdb', 'tt2290065'), ('tmdb', '126757'), ('slug', '100-bloody-acres-2012'), ('trakt', '86920') ] assert watched[('imdb', 'tt2290065')].plays == 2 assert watched[('imdb', 'tt2290065')].last_watched_at == datetime(2014, 4, 27, 13, 43, 59, tzinfo=tzutc()) # The Hobbit: The Desolation of Smaug (2013) assert watched[('imdb', 'tt1170358')].title == 'The Hobbit: The Desolation of Smaug' assert watched[('imdb', 'tt1170358')].year == 2013 assert watched[('imdb', 'tt1170358')].pk == ('imdb', 'tt1170358') assert watched[('imdb', 'tt1170358')].keys == [ ('imdb', 'tt1170358'), ('tmdb', '57158'), ('slug', 'the-hobbit-the-desolation-of-smaug-2013'), ('trakt', '40808') ] assert watched[('imdb', 'tt1170358')].plays == 1 assert watched[('imdb', 'tt1170358')].last_watched_at == datetime(2014, 4, 20, 12, 32, 59, tzinfo=tzutc()) # TRON: Legacy (2010) assert watched[('imdb', 'tt1104001')].title == 'TRON: Legacy' assert watched[('imdb', 'tt1104001')].year == 2010 assert watched[('imdb', 'tt1104001')].pk == ('imdb', 'tt1104001') assert watched[('imdb', 'tt1104001')].keys == [ ('imdb', 'tt1104001'), ('tmdb', '20526'), ('slug', 'tron-legacy-2010'), ('trakt', '12601') ] assert watched[('imdb', 'tt1104001')].plays == 1 assert watched[('imdb', 'tt1104001')].last_watched_at == datetime(2015, 1, 27, 23, 30, 16, tzinfo=tzutc())
def test_watched(): responses.add_callback( responses.GET, 'http://mock/sync/watched/movies', callback=authenticated_response('fixtures/sync/watched/movies.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): watched = Trakt['sync/watched'].movies() assert watched is not None # 100 Bloody Acres (2012) assert watched[('imdb', 'tt2290065')].title == '100 Bloody Acres' assert watched[('imdb', 'tt2290065')].year == 2012 assert watched[('imdb', 'tt2290065')].pk == ('imdb', 'tt2290065') assert watched[('imdb', 'tt2290065')].keys == [('imdb', 'tt2290065'), ('tmdb', '126757'), ('slug', '100-bloody-acres-2012'), ('trakt', '86920')] assert watched[('imdb', 'tt2290065')].plays == 2 assert watched[('imdb', 'tt2290065')].last_watched_at == datetime( 2014, 4, 27, 13, 43, 59) # The Hobbit: The Desolation of Smaug (2013) assert watched[( 'imdb', 'tt1170358')].title == 'The Hobbit: The Desolation of Smaug' assert watched[('imdb', 'tt1170358')].year == 2013 assert watched[('imdb', 'tt1170358')].pk == ('imdb', 'tt1170358') assert watched[('imdb', 'tt1170358')].keys == [ ('imdb', 'tt1170358'), ('tmdb', '57158'), ('slug', 'the-hobbit-the-desolation-of-smaug-2013'), ('trakt', '40808') ] assert watched[('imdb', 'tt1170358')].plays == 1 assert watched[('imdb', 'tt1170358')].last_watched_at == datetime( 2014, 4, 20, 12, 32, 59) # TRON: Legacy (2010) assert watched[('imdb', 'tt1104001')].title == 'TRON: Legacy' assert watched[('imdb', 'tt1104001')].year == 2010 assert watched[('imdb', 'tt1104001')].pk == ('imdb', 'tt1104001') assert watched[('imdb', 'tt1104001')].keys == [('imdb', 'tt1104001'), ('tmdb', '20526'), ('slug', 'tron-legacy-2010'), ('trakt', '12601')] assert watched[('imdb', 'tt1104001')].plays == 1 assert watched[('imdb', 'tt1104001')].last_watched_at == datetime( 2015, 1, 27, 23, 30, 16)
def test_basic(): responses.add_callback(responses.GET, 'http://mock/users/me/lists/movies/items', callback=authenticated_response( 'fixtures/users/me/lists/movies/items.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): items = Trakt['users/me/lists/movies'].items() # Ensure collection is valid assert_that(items, not_none()) # Validate items assert_that( items, contains( # Mad Max: Fury Road all_of( instance_of(Movie), has_properties({ 'pk': ('imdb', 'tt1392190'), 'title': 'Mad Max: Fury Road', 'year': 2015, # Timestamps 'listed_at': datetime(2015, 6, 24, 5, 50, 21, tzinfo=tzutc()), # Keys 'keys': [('imdb', 'tt1392190'), ('tmdb', '76341'), ('slug', 'mad-max-fury-road-2015'), ('trakt', '56360')] })), # Maggie (2015) all_of( instance_of(Movie), has_properties({ 'pk': ('imdb', 'tt1881002'), 'title': 'Maggie', 'year': 2015, # Timestamps 'listed_at': datetime(2015, 6, 24, 5, 50, 21, tzinfo=tzutc()), # Keys 'keys': [('imdb', 'tt1881002'), ('tmdb', '287424'), ('slug', 'maggie-1969'), ('trakt', '184504')] }))))
def test_basic(): responses.add_callback( responses.GET, 'http://mock/sync/playback/movies', callback=authenticated_response('fixtures/sync/playback/movies.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): collection = Trakt['sync/playback'].movies() # Ensure collection is valid assert_that(collection, not_none()) # TRON: Legacy (2010) assert_that( collection[('imdb', 'tt1104001')], has_properties({ 'pk': ('imdb', 'tt1104001'), 'title': 'TRON: Legacy', 'year': 2010, 'progress': 64.0, # Timestamps 'paused_at': datetime(2015, 2, 9, 5, 56, 58, tzinfo=tzutc()), # Keys 'keys': [('imdb', 'tt1104001'), ('tmdb', '20526'), ('slug', 'tron-legacy-2010'), ('trakt', '12601')] })) # 100 Bloody Acres (2012) assert_that( collection[('imdb', 'tt2290065')], has_properties({ 'pk': ('imdb', 'tt2290065'), 'title': '100 Bloody Acres', 'year': 2012, 'progress': 0.0, # Timestamps 'paused_at': datetime(2015, 1, 10, 6, 44, 9, tzinfo=tzutc()), # Keys 'keys': [('imdb', 'tt2290065'), ('tmdb', '126757'), ('slug', '100-bloody-acres-2012'), ('trakt', '86920')] }))
def test_request(): responses.add_callback(responses.GET, 'http://mock/sync/collection/movies', callback=authenticated_response( 'fixtures/sync/collection/movies.json'), content_type='application/json') def callback(request): return 200, {}, json.dumps({ "access_token": "mock", "token_type": "bearer", "created_at": calendar.timegm(datetime.datetime.utcnow().utctimetuple()), "expires_in": 7 * 24 * 60 * 60, "refresh_token": "mock-refresh_token", "scope": "public" }) responses.add_callback(responses.POST, 'http://mock/oauth/token', callback=callback, content_type='application/json') Trakt.base_url = 'http://mock' # Mock authorization authorization = { "access_token": "mock", "token_type": "bearer", "created_at": calendar.timegm(datetime.datetime.utcnow().utctimetuple()), "expires_in": 7 * 24 * 60 * 60, "refresh_token": "mock-refresh_token", "scope": "public" } # Test valid token with Trakt.configuration.oauth.from_response(authorization): assert Trakt['sync/collection'].movies() is not None # Test expired token authorization['expires_in'] = 0 with Trakt.configuration.oauth.from_response(authorization): assert Trakt['sync/collection'].movies() is None # Test token refreshing with Trakt.configuration\ .client('mock', 'mock')\ .oauth.from_response(authorization, refresh=True): assert Trakt['sync/collection'].movies() is not None
def test_basic(): responses.add_callback(responses.GET, 'http://mock/users/me/lists/people/items', callback=authenticated_response( 'fixtures/users/me/lists/people/items.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): items = Trakt['users/me/lists/people'].items() # Ensure collection is valid assert_that(items, not_none()) # Validate items assert_that( items, contains( # Bryan Cranston all_of( instance_of(Person), has_properties({ 'pk': ('tmdb', '17419'), 'name': 'Bryan Cranston', # Timestamps 'listed_at': datetime(2014, 6, 17, 6, 52, 3, tzinfo=tzutc()), # Keys 'keys': [('tmdb', '17419'), ('imdb', 'nm0186505'), ('tvrage', '1797'), ('slug', 'bryan-cranston'), ('trakt', '1')] })), # Aaron Paul all_of( instance_of(Person), has_properties({ 'pk': ('tmdb', '84497'), 'name': 'Aaron Paul', # Timestamps 'listed_at': datetime(2014, 6, 17, 6, 52, 3, tzinfo=tzutc()), # Keys 'keys': [('tmdb', '84497'), ('imdb', 'nm0666739'), ('tvrage', '1823'), ('slug', 'aaron-paul'), ('trakt', '415249')] }))))
def test_basic(): responses.add_callback( responses.GET, 'http://mock/sync/ratings/movies', callback=authenticated_response('fixtures/sync/ratings/movies.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): collection = Trakt['sync/ratings'].movies() # Ensure collection is valid assert_that(collection, not_none()) # 100 Bloody Acres (2012) assert_that(collection[('imdb', 'tt2290065')], has_properties({ 'pk': ('imdb', 'tt2290065'), 'title': '100 Bloody Acres', 'year': 2012, 'rating': has_properties({ 'value': 8, 'timestamp': datetime(2015, 1, 28, 2, 26, 37, tzinfo=tzutc()) }), # Keys 'keys': [ ('imdb', 'tt2290065'), ('tmdb', '126757'), ('slug', '100-bloody-acres-2012'), ('trakt', '86920') ] })) # The Hobbit: The Desolation of Smaug (2013) assert_that(collection[('imdb', 'tt1170358')], has_properties({ 'pk': ('imdb', 'tt1170358'), 'title': 'The Hobbit: The Desolation of Smaug', 'year': 2013, 'rating': has_properties({ 'value': 10, 'timestamp': datetime(2014, 11, 1, 0, 24, 54, tzinfo=tzutc()) }), # Keys 'keys': [ ('imdb', 'tt1170358'), ('tmdb', '57158'), ('slug', 'the-hobbit-the-desolation-of-smaug-2013'), ('trakt', '40808') ] }))
def test_start(): responses.add_callback( responses.POST, 'http://mock/scrobble/start', callback=authenticated_response(data='{"mock": "mock"}'), content_type='application/json') with Trakt.configuration.auth('mock', 'mock'): result = Trakt['scrobble'].start(movie={'ids': {'tmdb': 76341}}) assert result is not None
def test_list_remove(): responses.add_callback( responses.GET, 'http://mock/users/me/lists/movies', callback=authenticated_response('fixtures/users/me/lists/movies.json'), content_type='application/json') responses.add_callback( responses.POST, 'http://mock/users/me/lists/123456/items/remove', callback=authenticated_response(data='{"mock": "mock"}'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): movies_list = Trakt['users/me/lists/movies'].get() result = movies_list.remove({'shows': [{'ids': {'tvdb': 121361}}]}) assert result is not None
def test_list_update(): responses.add_callback( responses.GET, 'http://mock/users/me/lists/movies', callback=authenticated_response('fixtures/users/me/lists/movies.json'), content_type='application/json') responses.add_callback( responses.PUT, 'http://mock/users/me/lists/123456', callback=authenticated_response('fixtures/users/me/lists/shows.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): movies_list = Trakt['users/me/lists/movies'].get() result = movies_list.update(name="Shows (2)") assert result is not None
def test_list_delete(): responses.add_callback( responses.GET, 'http://mock/users/me/lists/movies', callback=authenticated_response('fixtures/users/me/lists/movies.json'), content_type='application/json') responses.add_callback( responses.DELETE, 'http://mock/users/me/lists/123456', callback=authenticated_response(data='{"mock": "mock"}'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): movies_list = Trakt['users/me/lists/movies'].get() success = movies_list.delete() assert success is True
def test_shows_items(): responses.add_callback( responses.GET, 'http://mock/users/me/lists/shows/items', callback=authenticated_response('fixtures/users/me/lists/shows/items.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): items = Trakt['users/me/lists/shows'].items() # Validate shows items assert len(items) == 3 # Game of Thrones (2011) assert items[0].title == 'Game of Thrones' assert items[0].year == 2011 assert items[0].pk == ('tvdb', '121361') assert items[0].keys == [ ('tvdb', '121361'), ('tmdb', '1399'), ('imdb', 'tt0944947'), ('tvrage', '24493'), ('slug', 'game-of-thrones'), ('trakt', '1390') ] # Game of Thrones (2011) - S05 assert items[1].pk == 5 assert items[1].keys == [ 5, ('tmdb', '62090'), ('trakt', '3967') ] assert items[1].show.title == 'Game of Thrones' assert items[1].show.year == 2011 # Game of Thrones (2011) - S05E04 assert items[2].pk == (5, 4) assert items[2].keys == [ (5, 4), ('tvdb', '5150183'), ('tmdb', '1045553'), ('imdb', 'tt3866838'), ('tvrage', '1065765456'), ('trakt', '1782362') ] assert items[2].show.title == 'Game of Thrones' assert items[2].show.year == 2011
def test_list_delete(): responses.add_callback( responses.GET, 'http://mock/users/me/lists/movies', callback=authenticated_response('fixtures/users/me/lists/movies.json'), content_type='application/json' ) responses.add_callback( responses.DELETE, 'http://mock/users/me/lists/123456', callback=authenticated_response(data='{"mock": "mock"}'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): movies_list = Trakt['users/me/lists/movies'].get() success = movies_list.delete() assert success is True
def test_unlike(): responses.add_callback( responses.DELETE, 'http://mock/users/me/lists/shows/like', callback=authenticated_response(data='{"mock": "mock"}'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): success = Trakt['users/me/lists/shows'].unlike() assert success is True
def test_start(): responses.add_callback( responses.POST, 'http://mock/scrobble/start', callback=authenticated_response(data='{"mock": "mock"}'), content_type='application/json' ) with Trakt.configuration.auth('mock', 'mock'): result = Trakt['scrobble'].start( movie={'ids': {'tmdb': 76341}} ) assert result is not None
def test_delete(): responses.add_callback( responses.DELETE, 'http://mock/users/me/lists/shows', callback=authenticated_response(data='{"mock": "mock"}'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): success = Trakt['users/me/lists/shows'].delete() assert success is True
def test_list_update(): responses.add_callback( responses.GET, 'http://mock/users/me/lists/movies', callback=authenticated_response('fixtures/users/me/lists/movies.json'), content_type='application/json' ) responses.add_callback( responses.PUT, 'http://mock/users/me/lists/123456', callback=authenticated_response('fixtures/users/me/lists/shows.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): movies_list = Trakt['users/me/lists/movies'].get() result = movies_list.update( name="Shows (2)" ) assert result is not None
def test_update_data(): responses.add_callback( responses.PUT, 'http://mock/users/me/lists/shows', callback=authenticated_response('fixtures/users/me/lists/shows.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): result = Trakt['users/me/lists/shows'].update(name="Shows (2)", return_type='data') assert result is not None
def test_request(): responses.add_callback( responses.GET, 'http://mock/sync/collection/movies', callback=authenticated_response('fixtures/sync/collection/movies.json'), content_type='application/json' ) def callback(request): return 200, {}, json.dumps({ "access_token": "mock", "token_type": "bearer", "created_at": calendar.timegm(datetime.datetime.utcnow().utctimetuple()), "expires_in": 7 * 24 * 60 * 60, "refresh_token": "mock-refresh_token", "scope": "public" }) responses.add_callback( responses.POST, 'http://mock/oauth/token', callback=callback, content_type='application/json' ) Trakt.base_url = 'http://mock' # Mock authorization authorization = { "access_token": "mock", "token_type": "bearer", "created_at": calendar.timegm(datetime.datetime.utcnow().utctimetuple()), "expires_in": 7 * 24 * 60 * 60, "refresh_token": "mock-refresh_token", "scope": "public" } # Test valid token with Trakt.configuration.oauth.from_response(authorization): assert Trakt['sync/collection'].movies() is not None # Test expired token authorization['expires_in'] = 0 with Trakt.configuration.oauth.from_response(authorization): assert Trakt['sync/collection'].movies() is None # Test token refreshing with Trakt.configuration\ .client('mock', 'mock')\ .oauth.from_response(authorization, refresh=True): assert Trakt['sync/collection'].movies() is not None
def test_collection(): responses.add_callback( responses.GET, 'http://mock/sync/collection/shows', callback=authenticated_response('fixtures/sync/collection/shows.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): collection = Trakt['sync/collection'].shows() assert collection is not None assert len(collection) == 4 # Validate `Show` show = collection[('tvdb', '80348')] assert show.title == 'Chuck' assert show.year == 2007 assert show.pk == ('tvdb', '80348') assert show.keys == [('tvdb', '80348'), ('tmdb', '1404'), ('imdb', 'tt0934814'), ('tvrage', '15614'), ('slug', 'chuck'), ('trakt', '1395')] assert len(show.seasons) == 1 # Validate `Season` season = show.seasons[1] assert season.show == show assert len(season.episodes) == 4 # Validate `Episode` episode = season.episodes[2] assert episode.show == show assert episode.season == season assert episode.is_collected assert episode.collected_at == datetime(2013, 10, 11, 1, 59, 5, tzinfo=tzutc())
def test_collection(): responses.add_callback( responses.GET, 'http://mock/sync/collection/shows', callback=authenticated_response('fixtures/sync/collection/shows.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): collection = Trakt['sync/collection'].shows() assert collection is not None assert len(collection) == 4 # Validate `Show` show = collection[('tvdb', '80348')] assert show.title == 'Chuck' assert show.year == 2007 assert show.pk == ('tvdb', '80348') assert show.keys == [ ('tvdb', '80348'), ('tmdb', '1404'), ('imdb', 'tt0934814'), ('tvrage', '15614'), ('slug', 'chuck'), ('trakt', '1395') ] assert len(show.seasons) == 1 # Validate `Season` season = show.seasons[1] assert season.show == show assert len(season.episodes) == 4 # Validate `Episode` episode = season.episodes[2] assert episode.show == show assert episode.season == season assert episode.is_collected assert episode.collected_at == datetime(2013, 10, 11, 1, 59, 5, tzinfo=tzutc())
def test_update_data(): responses.add_callback( responses.PUT, 'http://mock/users/me/lists/shows', callback=authenticated_response('fixtures/users/me/lists/shows.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): result = Trakt['users/me/lists/shows'].update( name="Shows (2)", return_type='data' ) assert result is not None
def test_movies_items(): responses.add_callback(responses.GET, 'http://mock/users/me/lists/movies/items', callback=authenticated_response( 'fixtures/users/me/lists/movies/items.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): items = Trakt['users/me/lists/movies'].items() # Validate movies items assert len(items) == 2 # Mad Max: Fury Road (2015) assert items[0].title == 'Mad Max: Fury Road' assert items[0].year == 2015 assert items[0].pk == ('imdb', 'tt1392190') assert items[0].keys == [('imdb', 'tt1392190'), ('tmdb', '76341'), ('slug', 'mad-max-fury-road-2015'), ('trakt', '56360')] assert items[1].listed_at == datetime(2015, 6, 24, 5, 50, 21, tzinfo=tzutc()) # Maggie (2015) assert items[1].title == 'Maggie' assert items[1].year == 2015 assert items[1].pk == ('imdb', 'tt1881002') assert items[1].keys == [('imdb', 'tt1881002'), ('tmdb', '287424'), ('slug', 'maggie-1969'), ('trakt', '184504')] assert items[1].listed_at == datetime(2015, 6, 24, 5, 50, 21, tzinfo=tzutc())
def test_add(): responses.add_callback( responses.POST, 'http://mock/users/me/lists/shows/items', callback=authenticated_response(data='{"mock": "mock"}'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): result = Trakt['users/me/lists/shows'].add({ 'shows': [ {'ids': {'tvdb': 121361}} ] }) assert result is not None
def test_ratings(): responses.add_callback( responses.GET, 'http://mock/sync/ratings/movies', callback=authenticated_response('fixtures/sync/ratings/movies.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): ratings = Trakt['sync/ratings'].movies() assert ratings is not None # 100 Bloody Acres (2012) assert ratings[('imdb', 'tt2290065')].title == '100 Bloody Acres' assert ratings[('imdb', 'tt2290065')].year == 2012 assert ratings[('imdb', 'tt2290065')].pk == ('imdb', 'tt2290065') assert ratings[('imdb', 'tt2290065')].keys == [ ('imdb', 'tt2290065'), ('tmdb', '126757'), ('slug', '100-bloody-acres-2012'), ('trakt', '86920') ] assert ratings[('imdb', 'tt2290065')].rating.value == 8 assert ratings[('imdb', 'tt2290065')].rating.timestamp == datetime(2015, 1, 28, 2, 26, 37, tzinfo=tzutc()) # The Hobbit: The Desolation of Smaug (2013) assert ratings[('imdb', 'tt1170358')].title == 'The Hobbit: The Desolation of Smaug' assert ratings[('imdb', 'tt1170358')].year == 2013 assert ratings[('imdb', 'tt1170358')].pk == ('imdb', 'tt1170358') assert ratings[('imdb', 'tt1170358')].keys == [ ('imdb', 'tt1170358'), ('tmdb', '57158'), ('slug', 'the-hobbit-the-desolation-of-smaug-2013'), ('trakt', '40808') ] assert ratings[('imdb', 'tt1170358')].rating.value == 10 assert ratings[('imdb', 'tt1170358')].rating.timestamp == datetime(2014, 11, 1, 0, 24, 54, tzinfo=tzutc())
def test_collection(): responses.add_callback( responses.GET, 'http://mock/sync/collection/movies', callback=authenticated_response('fixtures/sync/collection/movies.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): collection = Trakt['sync/collection'].movies() assert collection is not None # TRON: Legacy (2010) assert collection[('imdb', 'tt1104001')].title == 'TRON: Legacy' assert collection[('imdb', 'tt1104001')].year == 2010 assert collection[('imdb', 'tt1104001')].pk == ('imdb', 'tt1104001') assert collection[('imdb', 'tt1104001')].keys == [ ('imdb', 'tt1104001'), ('tmdb', '20526'), ('slug', 'tron-legacy-2010'), ('trakt', '12601') ] assert collection[('imdb', 'tt1104001')].is_collected assert collection[('imdb', 'tt1104001')].collected_at == datetime(2014, 9, 28, 22, 45, 23, tzinfo=tzutc()) # 100 Bloody Acres (2012) assert collection[('imdb', 'tt2290065')].title == '100 Bloody Acres' assert collection[('imdb', 'tt2290065')].year == 2012 assert collection[('imdb', 'tt2290065')].pk == ('imdb', 'tt2290065') assert collection[('imdb', 'tt2290065')].keys == [ ('imdb', 'tt2290065'), ('tmdb', '126757'), ('slug', '100-bloody-acres-2012'), ('trakt', '86920') ] assert collection[('imdb', 'tt2290065')].is_collected assert collection[('imdb', 'tt2290065')].collected_at == datetime(2014, 1, 20, 7, 4, 4, tzinfo=tzutc())
def test_playback(): responses.add_callback( responses.GET, 'http://mock/sync/playback/movies', callback=authenticated_response('fixtures/sync/playback/movies.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): playback = Trakt['sync/playback'].movies() assert playback is not None # TRON: Legacy (2010) assert playback[('imdb', 'tt1104001')].title == 'TRON: Legacy' assert playback[('imdb', 'tt1104001')].year == 2010 assert playback[('imdb', 'tt1104001')].pk == ('imdb', 'tt1104001') assert playback[('imdb', 'tt1104001')].keys == [ ('imdb', 'tt1104001'), ('tmdb', '20526'), ('slug', 'tron-legacy-2010'), ('trakt', '12601') ] assert playback[('imdb', 'tt1104001')].progress == 64.0 assert playback[('imdb', 'tt1104001')].paused_at == datetime(2015, 2, 9, 5, 56, 58, tzinfo=tzutc()) # 100 Bloody Acres (2012) assert playback[('imdb', 'tt2290065')].title == '100 Bloody Acres' assert playback[('imdb', 'tt2290065')].year == 2012 assert playback[('imdb', 'tt2290065')].pk == ('imdb', 'tt2290065') assert playback[('imdb', 'tt2290065')].keys == [ ('imdb', 'tt2290065'), ('tmdb', '126757'), ('slug', '100-bloody-acres-2012'), ('trakt', '86920') ] assert playback[('imdb', 'tt2290065')].progress == 0.0 assert playback[('imdb', 'tt2290065')].paused_at == datetime(2015, 1, 10, 6, 44, 9, tzinfo=tzutc())
def test_ratings(): responses.add_callback( responses.GET, 'http://mock/sync/ratings/movies', callback=authenticated_response('fixtures/sync/ratings/movies.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): ratings = Trakt['sync/ratings'].movies() assert ratings is not None # 100 Bloody Acres (2012) assert ratings[('imdb', 'tt2290065')].title == '100 Bloody Acres' assert ratings[('imdb', 'tt2290065')].year == 2012 assert ratings[('imdb', 'tt2290065')].pk == ('imdb', 'tt2290065') assert ratings[('imdb', 'tt2290065')].keys == [('imdb', 'tt2290065'), ('tmdb', '126757'), ('slug', '100-bloody-acres-2012'), ('trakt', '86920')] assert ratings[('imdb', 'tt2290065')].rating.value == 8 assert ratings[('imdb', 'tt2290065')].rating.timestamp == datetime( 2015, 1, 28, 2, 26, 37) # The Hobbit: The Desolation of Smaug (2013) assert ratings[( 'imdb', 'tt1170358')].title == 'The Hobbit: The Desolation of Smaug' assert ratings[('imdb', 'tt1170358')].year == 2013 assert ratings[('imdb', 'tt1170358')].pk == ('imdb', 'tt1170358') assert ratings[('imdb', 'tt1170358')].keys == [ ('imdb', 'tt1170358'), ('tmdb', '57158'), ('slug', 'the-hobbit-the-desolation-of-smaug-2013'), ('trakt', '40808') ] assert ratings[('imdb', 'tt1170358')].rating.value == 10 assert ratings[('imdb', 'tt1170358')].rating.timestamp == datetime( 2014, 11, 1, 0, 24, 54)
def test_playback(): responses.add_callback( responses.GET, 'http://mock/sync/playback/movies', callback=authenticated_response('fixtures/sync/playback/movies.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): playback = Trakt['sync/playback'].movies() assert playback is not None # TRON: Legacy (2010) assert playback[('imdb', 'tt1104001')].title == 'TRON: Legacy' assert playback[('imdb', 'tt1104001')].year == 2010 assert playback[('imdb', 'tt1104001')].pk == ('imdb', 'tt1104001') assert playback[('imdb', 'tt1104001')].keys == [('imdb', 'tt1104001'), ('tmdb', '20526'), ('slug', 'tron-legacy-2010'), ('trakt', '12601')] assert playback[('imdb', 'tt1104001')].progress == 64.0 assert playback[('imdb', 'tt1104001')].paused_at == datetime( 2015, 2, 9, 5, 56, 58) # 100 Bloody Acres (2012) assert playback[('imdb', 'tt2290065')].title == '100 Bloody Acres' assert playback[('imdb', 'tt2290065')].year == 2012 assert playback[('imdb', 'tt2290065')].pk == ('imdb', 'tt2290065') assert playback[('imdb', 'tt2290065')].keys == [('imdb', 'tt2290065'), ('tmdb', '126757'), ('slug', '100-bloody-acres-2012'), ('trakt', '86920')] assert playback[('imdb', 'tt2290065')].progress == 0.0 assert playback[('imdb', 'tt2290065')].paused_at == datetime( 2015, 1, 10, 6, 44, 9)
def test_movies_items(): responses.add_callback( responses.GET, 'http://mock/users/me/lists/movies/items', callback=authenticated_response('fixtures/users/me/lists/movies/items.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): items = Trakt['users/me/lists/movies'].items() # Validate movies items assert len(items) == 2 # Mad Max: Fury Road (2015) assert items[0].title == 'Mad Max: Fury Road' assert items[0].year == 2015 assert items[0].pk == ('imdb', 'tt1392190') assert items[0].keys == [ ('imdb', 'tt1392190'), ('tmdb', '76341'), ('slug', 'mad-max-fury-road-2015'), ('trakt', '56360') ] assert items[1].listed_at == datetime(2015, 6, 24, 5, 50, 21, tzinfo=tzutc()) # Maggie (2015) assert items[1].title == 'Maggie' assert items[1].year == 2015 assert items[1].pk == ('imdb', 'tt1881002') assert items[1].keys == [ ('imdb', 'tt1881002'), ('tmdb', '287424'), ('slug', 'maggie-1969'), ('trakt', '184504') ] assert items[1].listed_at == datetime(2015, 6, 24, 5, 50, 21, tzinfo=tzutc())
def test_get(): responses.add_callback( responses.GET, 'http://mock/users/me/lists', callback=authenticated_response('fixtures/users/me/lists.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): lists = Trakt['users/me/lists'].get() assert lists is not None # Resolve lists lists = list(lists) # Validate list container assert len(lists) == 1 # Validate movies list movies_list = lists[0] assert movies_list.name == 'Movies' assert movies_list.description is None assert movies_list.likes == 0 assert movies_list.allow_comments is True assert movies_list.display_numbers is False assert movies_list.updated_at == datetime(2015, 6, 22, 2, 25, tzinfo=tzutc()) assert movies_list.comment_count == 0 assert movies_list.item_count == 2 assert movies_list.privacy == 'private'
def test_shows_items(): responses.add_callback(responses.GET, 'http://mock/users/me/lists/shows/items', callback=authenticated_response( 'fixtures/users/me/lists/shows/items.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): items = Trakt['users/me/lists/shows'].items() # Validate shows items assert len(items) == 3 # Game of Thrones (2011) assert items[0].title == 'Game of Thrones' assert items[0].year == 2011 assert items[0].pk == ('tvdb', '121361') assert items[0].keys == [('tvdb', '121361'), ('tmdb', '1399'), ('imdb', 'tt0944947'), ('tvrage', '24493'), ('slug', 'game-of-thrones'), ('trakt', '1390')] # Game of Thrones (2011) - S05 assert items[1].pk == 5 assert items[1].keys == [5, ('tmdb', '62090'), ('trakt', '3967')] assert items[1].show.title == 'Game of Thrones' assert items[1].show.year == 2011 # Game of Thrones (2011) - S05E04 assert items[2].pk == (5, 4) assert items[2].keys == [(5, 4), ('tvdb', '5150183'), ('tmdb', '1045553'), ('imdb', 'tt3866838'), ('tvrage', '1065765456'), ('trakt', '1782362')] assert items[2].show.title == 'Game of Thrones' assert items[2].show.year == 2011
def test_get(): responses.add_callback( responses.GET, 'http://mock/users/me/lists', callback=authenticated_response('fixtures/users/me/lists.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): lists = Trakt['users/me/lists'].get() assert lists is not None # Resolve lists lists = list(lists) # Validate list container assert len(lists) == 1 # Validate movies list movies_list = lists[0] assert movies_list.name == 'Movies' assert movies_list.description is None assert movies_list.likes == 0 assert movies_list.allow_comments is True assert movies_list.display_numbers is False assert movies_list.updated_at == datetime(2015, 6, 22, 2, 25, tzinfo=tzutc()) assert movies_list.comment_count == 0 assert movies_list.item_count == 2 assert movies_list.privacy == 'private'
def test_watched(): responses.add_callback( responses.GET, 'http://mock/sync/watched/shows', callback=authenticated_response('fixtures/sync/watched/shows.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): collection = Trakt['sync/watched'].shows() # Ensure collection is valid assert_that(collection, not_none()) assert_that(collection, has_length(9)) # Chuck (2007) assert_that( collection[('tvdb', '80348')], has_properties({ 'pk': ('tvdb', '80348'), 'title': 'Chuck', 'year': 2007, # Seasons 'seasons': all_of( has_length(1), has_entry( 1, has_properties({ # Episodes 'episodes': all_of( has_length(4), has_entry( 2, has_properties({ 'pk': (1, 2), 'plays': 9, # Timestamps 'last_watched_at': datetime(2015, 3, 10, 5, 21, 51, tzinfo=tzutc()), # Flags 'is_watched': True }))) }))), # Keys 'keys': [('tvdb', '80348'), ('tmdb', '1404'), ('imdb', 'tt0934814'), ('tvrage', '15614'), ('slug', 'chuck'), ('trakt', '1395')] }))
def test_basic(): responses.add_callback(responses.GET, 'http://mock/sync/playback/episodes', callback=authenticated_response( 'fixtures/sync/playback/episodes.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): collection = Trakt['sync/playback'].episodes() # Ensure collection is valid assert_that(collection, not_none()) # Chuck (2007) assert_that( collection[('tvdb', '80348')], has_properties({ 'pk': ('tvdb', '80348'), 'title': 'Chuck', 'year': 2007, # Seasons 'seasons': all_of( has_length(1), # Seasons has_entry( 1, has_properties({ 'episodes': all_of( has_length(2), # Episodes has_entry( 3, has_properties({ 'pk': (1, 3), 'title': 'Chuck Versus the Tango', 'progress': 4.99, # Timestamps 'paused_at': datetime(2015, 3, 9, 0, 10, 15, tzinfo=tzutc()), # Keys 'keys': [(1, 3), ('tvdb', '336271'), ('tmdb', '63434'), ('tvrage', '595113'), ('trakt', '74043')] }))) }))), # Keys 'keys': [('tvdb', '80348'), ('tmdb', '1404'), ('imdb', 'tt0934814'), ('tvrage', '15614'), ('slug', 'chuck'), ('trakt', '1395')] }))
def test_basic(): responses.add_callback(responses.GET, 'http://mock/sync/collection/movies', callback=authenticated_response( 'fixtures/sync/collection/movies.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): collection = Trakt['sync/collection'].movies() # Ensure collection is valid assert_that(collection, not_none()) # TRON: Legacy (2010) assert_that( collection[('imdb', 'tt1104001')], has_properties({ 'pk': ('imdb', 'tt1104001'), 'title': 'TRON: Legacy', 'year': 2010, # Timestamps 'collected_at': datetime(2014, 9, 28, 22, 45, 23, tzinfo=tzutc()), # Flags 'is_collected': True, # Keys 'keys': [('imdb', 'tt1104001'), ('tmdb', '20526'), ('slug', 'tron-legacy-2010'), ('trakt', '12601')] })) assert_that( collection[('imdb', 'tt1104001')].to_dict(), has_entries({ 'title': 'TRON: Legacy', 'year': 2010, # Timestamps 'collected_at': '2014-09-28T22:45:23.000-00:00', # Flags 'collected': 1, # Keys 'ids': { 'imdb': 'tt1104001', 'tmdb': '20526', 'slug': 'tron-legacy-2010', 'trakt': '12601' } })) # 100 Bloody Acres (2012) assert_that( collection[('imdb', 'tt2290065')], has_properties({ 'pk': ('imdb', 'tt2290065'), 'title': '100 Bloody Acres', 'year': 2012, # Timestamps 'collected_at': datetime(2014, 1, 20, 7, 4, 4, tzinfo=tzutc()), # Flags 'is_collected': True, # Keys 'keys': [('imdb', 'tt2290065'), ('tmdb', '126757'), ('slug', '100-bloody-acres-2012'), ('trakt', '86920')] })) assert_that( collection[('imdb', 'tt2290065')].to_dict(), has_entries({ 'title': '100 Bloody Acres', 'year': 2012, # Timestamps 'collected_at': '2014-01-20T07:04:04.000-00:00', # Flags 'collected': 1, # Keys 'ids': { 'imdb': 'tt2290065', 'tmdb': '126757', 'slug': '100-bloody-acres-2012', 'trakt': '86920' } }))
def test_basic(): responses.add_callback( responses.GET, 'http://mock/sync/collection/shows', callback=authenticated_response('fixtures/sync/collection/shows.json'), content_type='application/json') Trakt.base_url = 'http://mock' with Trakt.configuration.auth('mock', 'mock'): collection = Trakt['sync/collection'].shows() # Ensure collection is valid assert_that(collection, not_none()) assert_that(collection, has_length(4)) # Chuck (2007) assert_that( collection[('tvdb', '80348')], has_properties({ 'pk': ('tvdb', '80348'), 'title': 'Chuck', 'year': 2007, # Seasons 'seasons': all_of( has_length(1), has_entry( 1, has_properties({ # Episodes 'episodes': all_of( has_length(4), has_entry( 2, has_properties({ 'pk': (1, 2), # Timestamps 'collected_at': datetime(2013, 10, 11, 1, 59, 5, tzinfo=tzutc()), # Flags 'is_collected': True, }))) }))), # Keys 'keys': [('tvdb', '80348'), ('tmdb', '1404'), ('imdb', 'tt0934814'), ('tvrage', '15614'), ('slug', 'chuck'), ('trakt', '1395')] })) assert_that( collection[('tvdb', '80348')].to_dict(), has_entries({ 'title': 'Chuck', 'year': 2007, # Keys 'ids': { 'trakt': '1395', 'slug': 'chuck', 'tvdb': '80348', 'imdb': 'tt0934814', 'tmdb': '1404', 'tvrage': '15614' } })) assert_that( collection[('tvdb', '80348')].seasons[1].to_dict(), has_entries({ 'number': 1, # Episodes 'episodes': has_item( has_entries({ 'number': 2, # Timestamps 'collected_at': '2013-10-11T01:59:05.000-00:00', # Flags 'collected': 1, })), })) assert_that( collection[('tvdb', '80348')].seasons[1].episodes[2].to_dict(), has_entries({ 'number': 2, # Timestamps 'collected_at': '2013-10-11T01:59:05.000-00:00', # Flags 'collected': 1, }))
def test_ratings(): responses.add_callback( responses.GET, 'http://mock/sync/ratings/shows', callback=authenticated_response('fixtures/sync/ratings/shows.json'), content_type='application/json' ) responses.add_callback( responses.GET, 'http://mock/sync/ratings/seasons', callback=authenticated_response('fixtures/sync/ratings/seasons.json'), content_type='application/json' ) responses.add_callback( responses.GET, 'http://mock/sync/ratings/episodes', callback=authenticated_response('fixtures/sync/ratings/episodes.json'), content_type='application/json' ) Trakt.base_url = 'http://mock' ratings = {} with Trakt.configuration.auth('mock', 'mock'): Trakt['sync/ratings'].shows(ratings) Trakt['sync/ratings'].seasons(ratings) Trakt['sync/ratings'].episodes(ratings) assert len(ratings) == 6 # Validate `Show` show = ratings[('tvdb', '80348')] assert show.title == 'Chuck' assert show.year == 2007 assert show.rating.value == 10 assert show.rating.timestamp == datetime(2014, 10, 19, 23, 2, 23, tzinfo=tzutc()) # Validate `Season` season = show.seasons[1] assert season.show == show assert season.keys == [ 1, ('tvdb', '27985'), ('tmdb', '3650'), ('trakt', '3993') ] assert season.rating.value == 10 assert season.rating.timestamp == datetime(2015, 3, 11, 23, 29, 35, tzinfo=tzutc()) # Validate `Season.to_dict()` assert season.to_dict() == { 'number': 1, 'episodes': [ { 'progress': None, 'paused_at': None, 'number': 1, 'title': 'Chuck Versus the Intersect', 'ids': { 'tvdb': '332179', 'tmdb': '63425', 'tvrage': '579282', 'trakt': '74041' }, 'last_watched_at': None, 'watched': 0, 'plays': 0, 'collected_at': None, 'collected': 0, 'rating': 10, 'rated_at': '2014-10-19T23:02:24.000-00:00', 'in_watchlist': 0 } ], 'ids': { 'tvdb': '27985', 'tmdb': '3650', 'trakt': '3993' }, 'rating': 10, 'rated_at': '2015-03-11T23:29:35.000-00:00', 'in_watchlist': 0 } # Validate `Episode` episode = season.episodes[1] assert episode.show == show assert episode.season == season assert episode.rating.value == 10 assert episode.rating.timestamp == datetime(2014, 10, 19, 23, 2, 24, tzinfo=tzutc())