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_oneliners():
e1 = TVEpisode('Game of Thrones', season=1, number=1)
functions = [e1.add_to_library, e1.add_to_collection, e1.add_to_watchlist,
e1.mark_as_seen, e1.mark_as_unseen, e1.remove_from_library,
e1.remove_from_collection, e1.remove_from_watchlist]
for fn in functions:
r = fn()
assert r is None
def test_last_episode():
got = TVShow('Game of Thrones')
assert isinstance(got.last_episode, TVEpisode)
def test_episode_comment():
e1 = TVEpisode('Game of Thrones', season=1, number=1)
r = e1.comment('Test Comment')
assert r is None
def test_watching():
sean = User('sean')
sean.username = 'sean-movie'
assert isinstance(sean.watching, Movie)
sean.username = 'sean-episode'
assert isinstance(sean.watching, TVEpisode)
sean.username = 'sean-nothing'
assert sean.watching is None
def _build(self, data):
"""Build the calendar"""
self._calendar = []
for episode in data:
show = episode.get('show', {}).get('title')
season = episode.get('episode', {}).get('season')
ep = episode.get('episode', {}).get('number')
e_data = {'airs_at': airs_date(episode.get('first_aired')),
'ids': episode.get('episode').get('ids'),
'title': episode.get('episode', {}).get('title')}
self._calendar.append(TVEpisode(show, season, ep, **e_data))
self._calendar = sorted(self._calendar, key=lambda x: x.airs_at)
def _build(self, data):
"""Build this :class:`TVSeason` object with the data in *data*"""
# only try to build our episodes if we got a list of episodes, not a
# dict of season data
if isinstance(data, list):
self._episodes = [TVEpisode(show=self.show, **ep) for ep in data]
else:
for key, val in data.items():
try:
setattr(self, key, val)
except AttributeError:
setattr(self, '_'+key, val)
def _episode_getter(self, episode):
"""Recursive episode getter generator. Will attempt to get the
specified episode for this season, and if the requested episode wasn't
found, then we return :const:`None` to indicate to the `episodes`
property that we've already yielded all valid episodes for this season.
:param episode: An int corresponding to the number of the episode
we're trying to retrieve
"""
episode_extension = '/episodes/{}?extended=full'.format(episode)
try:
data = yield (self.ext + episode_extension)
yield TVEpisode(show=self.show, **data)
except NotFoundException:
yield None
# Need to do imports here to prevent circular imports with modules that
# need to import Scrobblers
results = []
for media_item in data:
extract_ids(media_item)
result = SearchResult(media_item['type'], media_item['score'])
if media_item['type'] == 'movie':
from trakt.movies import Movie
result.media = Movie(**media_item.pop('movie'))
elif media_item['type'] == 'show':
from trakt.tv import TVShow
result.media = TVShow(**media_item.pop('show'))
elif media_item['type'] == 'episode':
from trakt.tv import TVEpisode
show = media_item.pop('show')
result.media = TVEpisode(show.get('title', None),
**media_item.pop('episode'))
elif media_item['type'] == 'person':
from trakt.people import Person
result.media = Person(**media_item.pop('person'))
results.append(result)
yield results
item_type = item['type']
item_data = item.pop(item_type)
extract_ids(item_data)
if item_type == 'movie':
self._items.append(Movie(item_data['title'], item_data['year'], item_data['slug']))
elif item_type == 'show':
self._items.append(TVShow(item_data['title'], item_data['slug']))
elif item_type == 'season':
show_data = item.pop('show')
extract_ids(show_data)
season = TVSeason(show_data['title'], item_data['number'], show_data['slug'])
self._items.append(season)
elif item_type == 'episode':
show_data = item.pop('show')
extract_ids(show_data)
episode = TVEpisode(show_data['title'], item_data['season'], item_data['number'])
self._items.append(episode)
elif item_type == 'person':
self._items.append(Person(item_data['name'], item_data['slug']))
yield self._items
# if a user isn't watching anything, trakt returns a 204
if data is None or data == '':
yield None
media_type = data.pop('type')
if media_type == 'movie':
movie_data = data.pop('movie')
extract_ids(movie_data)
movie_data.update(data)
yield Movie(**movie_data)
else: # media_type == 'episode'
ep_data = data.pop('episode')
extract_ids(ep_data)
sh_data = data.pop('show')
ep_data.update(data, show=sh_data.get('title'))
yield TVEpisode(**ep_data)