Ejemplo n.º 1
0
Archivo: tests.py Proyecto: Mic92/mygpo
class MergeTests(TestCase):

    def setUp(self):
        self.podcast1 = Podcast(urls=['http://example.com/feed.rss'])
        self.podcast2 = Podcast(urls=['http://test.org/podcast/'])
        self.podcast1.save()
        self.podcast2.save()

        self.episode1 = Episode(podcast=self.podcast1.get_id(),
                urls = ['http://example.com/episode1.mp3'])
        self.episode2 = Episode(podcast=self.podcast2.get_id(),
                urls = ['http://example.com/episode1.mp3'])

        self.episode1.save()
        self.episode2.save()

        self.user = User(username='******')
        self.user.email = '*****@*****.**'
        self.user.set_password('secret!')
        self.user.save()


    def test_merge_podcasts(self):

        state1 = self.episode1.get_user_state(self.user)
        state2 = self.episode2.get_user_state(self.user)

        action1 = EpisodeAction(action='play', timestamp=datetime.utcnow())
        action2 = EpisodeAction(action='download', timestamp=datetime.utcnow())

        state1.add_actions([action1])
        state2.add_actions([action2])

        state1.save()
        state2.save()

        pm = PodcastMerger([self.podcast1, self.podcast2])
        pm.merge()

        state1 = self.episode1.get_user_state(self.user)
        state2 = self.episode2.get_user_state(self.user)

        self.assertIn(action1, state1.actions)
        self.assertIn(action2, state1.actions)



    def tearDown(self):
        self.podcast1.delete()
        self.episode1.delete()

        try:
            self.podcast2.delete()
            self.episode2.delete()
        except:
            pass

        self.user.delete()
Ejemplo n.º 2
0
Archivo: tests.py Proyecto: fk-lx/mygpo
class MergeTests(TestCase):
    """ Tests merging of two podcasts, their episodes and states """

    def setUp(self):
        self.podcast1 = Podcast(urls=['http://example.com/feed.rss'])
        self.podcast2 = Podcast(urls=['http://test.org/podcast/'])
        self.podcast1.save()
        self.podcast2.save()

        self.episode1 = Episode(podcast=self.podcast1.get_id(),
                urls = ['http://example.com/episode1.mp3'])
        self.episode2 = Episode(podcast=self.podcast2.get_id(),
                urls = ['http://example.com/episode1.mp3'])

        self.episode1.save()
        self.episode2.save()

        self.user = User(username='******')
        self.user.email = '*****@*****.**'
        self.user.set_password('secret!')
        self.user.save()


    def test_merge_podcasts(self):

        # Create additional data that will be merged
        state1 = episode_state_for_user_episode(self.user, self.episode1)
        state2 = episode_state_for_user_episode(self.user, self.episode2)

        action1 = EpisodeAction(action='play',
                timestamp=datetime.utcnow(),
                upload_timestamp=get_timestamp(datetime.utcnow()))
        action2 = EpisodeAction(action='download',
                timestamp=datetime.utcnow(),
                upload_timestamp=get_timestamp(datetime.utcnow()))

        add_episode_actions(state1, [action1])
        add_episode_actions(state2, [action2])

        # copy of the object
        episode2 = episode_by_id(self.episode2._id)

        # decide which episodes to merge
        groups = [(0, [self.episode1, self.episode2])]
        counter = Counter()

        pm = PodcastMerger([self.podcast1, self.podcast2], counter, groups)
        pm.merge()

        state1 = episode_state_for_user_episode(self.user, self.episode1)
        state2 = episode_state_for_user_episode(self.user, episode2)

        self.assertIn(action1, state1.actions)
        self.assertIn(action2, state1.actions)
        self.assertEqual(state2._id, None)



    def tearDown(self):
        self.podcast1.delete()
        self.episode1.delete()

        #self.podcast2.delete()
        #self.episode2.delete()

        self.user.delete()
Ejemplo n.º 3
0
Archivo: tests.py Proyecto: fk-lx/mygpo
class MergeGroupTests(TestCase):
    """ Tests merging of two podcasts, one of which is part of a group """

    def setUp(self):
        self.podcast1 = Podcast(urls=['http://example.com/feed.rss'])
        self.podcast2 = Podcast(urls=['http://test.org/podcast/'])
        self.podcast3 = Podcast(urls=['http://test.org/feed/'])
        self.podcast1.save()
        self.podcast2.save()
        self.podcast3.save()

        self.episode1 = Episode(podcast=self.podcast1.get_id(),
                urls = ['http://example.com/episode1.mp3'])
        self.episode2 = Episode(podcast=self.podcast2.get_id(),
                urls = ['http://example.com/episode1.mp3'])
        self.episode3 = Episode(podcast=self.podcast3.get_id(),
                urls = ['http://example.com/media.mp3'])


        self.episode1.save()
        self.episode2.save()
        self.episode3.save()

        self.podcast2.group_with(self.podcast3, 'My Group', 'Feed1', 'Feed2')

        self.user = User(username='******')
        self.user.email = '*****@*****.**'
        self.user.set_password('secret!')
        self.user.save()


    def test_merge_podcasts(self):

        podcast1 = podcast_by_id(self.podcast1.get_id())
        podcast2 = podcast_by_id(self.podcast2.get_id())
        podcast3 = podcast_by_id(self.podcast3.get_id())

        # assert that the podcasts are actually grouped
        self.assertEqual(podcast2._id, podcast3._id)
        self.assertNotEqual(podcast2.get_id(), podcast2._id)
        self.assertNotEqual(podcast3.get_id(), podcast3._id)

        # Create additional data that will be merged
        state1 = episode_state_for_user_episode(self.user, self.episode1)
        state2 = episode_state_for_user_episode(self.user, self.episode2)

        action1 = EpisodeAction(action='play',
                timestamp=datetime.utcnow(),
                upload_timestamp=get_timestamp(datetime.utcnow()))
        action2 = EpisodeAction(action='download',
                timestamp=datetime.utcnow(),
                upload_timestamp=get_timestamp(datetime.utcnow()))

        add_episode_actions(state1, [action1])
        add_episode_actions(state2, [action2])

        # copy of the object
        episode2 = episode_by_id(self.episode2._id)

        # decide which episodes to merge
        groups = [(0, [self.episode1, self.episode2])]
        counter = Counter()

        pm = PodcastMerger([podcast2, podcast1], counter, groups)
        pm.merge()

        state1 = episode_state_for_user_episode(self.user, self.episode1)
        state2 = episode_state_for_user_episode(self.user, episode2)

        self.assertIn(action1, state1.actions)
        self.assertIn(action2, state1.actions)
        self.assertEqual(state2._id, None)

        episode1 = episode_by_id(self.episode1._id)

        # episode2 has been merged into episode1, so it must contain its
        # merged _id
        self.assertEqual(episode1.merged_ids, [episode2._id])



    def tearDown(self):
        self.podcast2.delete()
        self.episode1.delete()

        #self.podcast2.delete()
        #self.episode2.delete()

        self.user.delete()