Exemple #1
0
def test_oneliners():
    s1 = TVSeason('Game of Thrones')
    functions = [
        s1.add_to_library, s1.add_to_collection, s1.remove_from_library,
        s1.remove_from_collection
    ]
    for fn in functions:
        r = fn()
        assert r is None
 def show_collection(self):
     """All :class:`TVShow`'s in this :class:`User`'s library collection.
     Collection items might include blu-rays, dvds, and digital downloads.
     Protected users won't return any data unless you are friends.
     """
     if self._show_collection is None:
         ext = 'users/{username}/collection/shows?extended=metadata'
         data = yield ext.format(username=self.username)
         self._show_collection = []
         for show in data:
             s = show.pop('show')
             extract_ids(s)
             sh = TVShow(**s)
             sh._seasons = [TVSeason(show=sh.title, **sea)
                            for sea in show.pop('seasons')]
             self._show_collection.append(sh)
     yield self._show_collection
Exemple #3
0
    def get_items(self):
        """A list of the list items using class instances
        instance types: movie, show, season, episode, person

        """

        data = yield 'users/{user}/lists/{id}/items'.format(user=slugify(
            self.creator),
                                                            id=self.slug)

        for item in data:
            # match list item type
            if 'type' not in item:
                continue
            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
Exemple #4
0
def test_season_to_json():
    s1 = TVSeason('Game of Thrones')
    assert isinstance(s1.to_json(), dict)
Exemple #5
0
def test_episodes_getter():
    s1 = TVSeason('Game of Thrones')
    s1._episodes = None
    for _ in range(2):
        assert all([isinstance(e, TVEpisode) for e in s1.episodes])
Exemple #6
0
def test_get_episodes():
    s1 = TVSeason('Game of Thrones', season=1)
    assert all([isinstance(e, TVEpisode) for e in s1.episodes])
Exemple #7
0
def test_season_magic_methods():
    s1 = TVSeason('Game of Thrones')
    assert str(s1) == '<TVSeason>: %s Season %d' % (s1.show, s1.season)
    assert str(s1) == repr(s1)
    assert len(s1) == len(s1.episodes)
Exemple #8
0
def test_season_to_json():
    s1 = TVSeason('Game of Thrones')
    assert isinstance(s1.to_json(), dict)
Exemple #9
0
def test_episodes_getter():
    s1 = TVSeason('Game of Thrones')
    s1._episodes = None
    for _ in range(2):
        assert all([isinstance(e, TVEpisode) for e in s1.episodes])
Exemple #10
0
def test_season_watching_now():
    s1 = TVSeason('Game of Thrones')
    assert all([isinstance(u, User) for u in s1.watching_now])
Exemple #11
0
def test_season_ratings():
    s1 = TVSeason('Game of Thrones')
    assert isinstance(s1.ratings, dict)
Exemple #12
0
def test_season_comments():
    s1 = TVSeason('Game of Thrones')
    assert all([isinstance(c, Comment) for c in s1.comments])
Exemple #13
0
def test_get_season():
    s1 = TVSeason('Game of Thrones', season=1)
    assert isinstance(s1, TVSeason)
    assert len(s1) == 10
Exemple #14
0
    def get_items(self):
        """A list of the list items using class instances
        instance types: movie, show, season, episode, person

        """

        data = yield 'users/{user}/lists/{id}/items'.format(user=self.creator,
                                                            id=self.slug)

        for item in data:
            # match list item type
            if 'type' not in item:
                continue
            item_type = item['type']
            item_data = item.pop(item_type)
            extract_ids(item_data)
            if item_type == 'movie':
                movie = Movie(item_data.pop('title'), item_data.pop('year'),
                              item_data.pop('slug'), **item_data)
                self._items.append(movie)
            elif item_type == 'show':
                show = TVShow(item_data.pop('title'),
                              slug=item_data.pop('slug'),
                              **item_data)
                seasons = show.seasons
                show._seasons = []
                for season in seasons:
                    season._episodes = []
                    show._seasons.append(season)
                self._items.append(show)
            elif item_type == 'season':
                show_data = item.pop('show')
                extract_ids(show_data)
                show = TVShow(show_data.pop('title'),
                              slug=show_data.pop('slug'),
                              **show_data)
                _season = TVSeason(show=show.title,
                                   season=item_data.pop('number'),
                                   slug=show.slug,
                                   **item_data)
                for season in show.seasons:
                    if season.trakt != _season.trakt:
                        continue
                    season._episodes = []
                    show._seasons = [season]
                    self._items.append(show)
                    break
                # season._episodes = []
                # show._seasons = [season]
                # self._items.append(show)

                # extract_ids(show_data)
                # show=TVShow(show_data['title'], show_data['slug'])
                # season = TVSeason(
                #     show=show.title,
                #     season=item_data['number'],
                #     slug=show.slug,
                #     **item_data
                # )
                # self._items.append(self.__class__.ListTVSeason(show=show, season=season))
            elif item_type == 'episode':
                show_data = item.pop('show')
                extract_ids(show_data)
                show = TVShow(show_data.pop('title'),
                              slug=show_data.pop('slug'),
                              **show_data)
                episode = TVEpisode(show=show.title,
                                    season=item_data.pop('season'),
                                    slug=show.slug,
                                    **item_data)
                for season in show.seasons:
                    if season.season != episode.season:
                        continue
                    season._episodes = [episode]
                    show._seasons = [season]
                    self._items.append(show)
                    break

                # show=TVShow(show_data['title'], show_data['slug'])
                # show._seasons = None
                # for season in show.seasons:
                #     if season.season != item_data['number']:
                #         continue
                #     episode = TVEpisode(show.title, season.season, item_data['number'], show.slug)
                #     self._items.append(self.__class__.ListTVEpisode(show=show, season=season, episode=episode))
                #     break
            elif item_type == 'person':
                self._items.append(Person(item_data['name'],
                                          item_data['slug']))

        yield self._items