Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_basic():
with HTTMock(mock.fixtures, mock.unknown):
with Trakt.configuration.auth('mock', 'mock'):
history = Trakt['sync/history'].shows(pagination=True, per_page=5)
# Ensure collection is valid
assert_that(history, not_none())
# Resolve all pages
items = list(history)
# Ensure all items have been returned
assert_that(items, has_length(25))
# Verify item identifiers
assert_that(
[item.id for item in items],
equal_to(list(xrange(1, 26)))
)
ev = Event()
@httmock.all_requests
def handler(url, request):
if ev.is_set():
return httmock.response(201, request=request)
# Set event
ev.set()
# Raise error
raise ConnectionError('Example')
with HTTMock(handler):
with pytest.raises(ConnectionError):
Trakt.http.get('/test')
def test_progress_collection():
with HTTMock(mock.fixtures, mock.unknown):
with Trakt.configuration.auth('mock', 'mock'):
progress = Trakt['shows'].progress_collection(1390)
assert progress is not None
assert progress.reset_at is None
assert progress.last_progress_change is not None
assert progress.seasons[1].episodes[1].progress_timestamp is not None
# Next Episode
assert progress.next_episode is not None
assert progress.next_episode.pk == (1, 7)
assert progress.next_episode.keys == [
(1, 7),
('tvdb', '3436461'),
('tmdb', '63062'),
def userWatchedMovies(username, *args, **argd):
data = Trakt.jsonRequest('POST', '/user/watched/movies.json/%%API_KEY%%/'+str(username), *args, **argd)
if data == None:
Debug("[Trakt] Error in request from 'userWatchedMovies()'")
return data
@staticmethod
def download(remoteId):
Debug("[Show] Downloading info for "+str(Show.devolveId(remoteId)))
local = Trakt.showSummary(Show.devolveId(remoteId))
if local is None:
show = Show(remoteId)
show._traktDbStatus = False
return movie
return Show.fromTrakt(local)
def testAll():
tests = [
{'f': Trakt.accountCreate, 'args': ["test@example.com"], 'argd': {'anon': True, 'username': "tester123456789", 'password': "password"}},
{'f': Trakt.accountTest, 'args': [], 'argd': {}},
{'f': Trakt.calendarPremieres, 'args': [], 'argd': {}},
{'f': Trakt.calendarPremieres, 'args': ["20110421"], 'argd': {}},
{'f': Trakt.calendarPremieres, 'args': ["20110421", 3], 'argd': {}},
{'f': Trakt.calendarShows, 'args': [], 'argd': {}},
{'f': Trakt.calendarShows, 'args': ["20110421"], 'argd': {}},
{'f': Trakt.calendarShows, 'args': ["20110421", 3], 'argd': {}},
{'f': Trakt.friendsAdd, 'args': ["justin"], 'argd': {}},
{'f': Trakt.friendsAll, 'args': [], 'argd': {}},
]
failsBasic = []
failsWithStatus = []
for test in tests:
if not Trakt.testBasic(test['f'], *test['args'], **test['argd']):
failsBasic.append(test)
if not Trakt.testWithStatus(test['f'], *test['args'], **test['argd']):
item.watched_at.strftime('%Y-%m-%d %H:%M:%S')
))
print('=' * 160)
# Retrieve history records for this year
for item in Trakt['sync/history'].get(pagination=True, per_page=25, start_at=datetime(now.year, 1, 1)):
print(' - %-120s (watched_at: %r)' % (
repr(item),
item.watched_at.strftime('%Y-%m-%d %H:%M:%S')
))
print('=' * 160)
# Retrieve all history records
for item in Trakt['sync/history'].get(pagination=True, per_page=25):
print(' - %-120s (watched_at: %r)' % (
repr(item),
item.watched_at.strftime('%Y-%m-%d %H:%M:%S')
))
def print_lookup(id, service):
print("Trakt['search'].lookup(%r, %r)" % (id, service))
item = Trakt['search'].lookup(id, service)
if type(item) is Episode and item.show:
sk, ek = item.pk
print('\t%s (%s) - S%02dE%02d %r' % (item.show.title, item.show.year, sk, ek, item.title))
else:
print('\t%s (%s)' % (item.title, item.year))