Exemplo n.º 1
0
    def test_get_channels_sort_rating(self):
        """
        Passing sort='rating' to get_channels should sort the channels by
        their rating.
        """
        new = self.make_channel(self.owner, state='A')
        for i in range(6):
            # make some fake ratings so that all the channels have 6 ratings
            fake = self.make_user('fake%i' % i)
            fake.get_profile().approved = True
            fake.get_profile().save()
            for channel in self.channels:
                rating, created = Rating.objects.get_or_create(channel=channel,
                                                               user=fake)
                rating.rating = 3
                rating.save()
            rating, created = Rating.objects.get_or_create(channel=new,
                                                           user=fake)
            rating.rating = 3
            rating.save()
        self.owner.get_profile().approved = True
        self.owner.get_profile().save()
        rating, created = Rating.objects.get_or_create(channel=new,
                                                       user=self.owner)
        rating.rating = 5
        rating.save()

        objs = utils.get_channels(self.make_request(), 'name', '',
                                  sort='rating')
        self.assertEquals(objs[-1].id, new.id)

        objs = utils.get_channels(self.make_request(), 'name', '',
                                  sort='-rating')
        self.assertEquals(objs[0].id, new.id)
Exemplo n.º 2
0
    def test_get_channels_filter_language(self):
        """
        utils.get_channels('language', 'language name') should
        return a list of Channels that belong to that category.
        """
        objs = utils.get_channels(self.make_request(), 'language', 'language0')
        self.assertEquals(len(objs), 1)
        self.assertEquals(objs[0].id, self.channels[0].id)

        objs3 = utils.get_channels(self.make_request(), 'language', 'unknown')
        self.assertEquals(len(objs3), 0)
Exemplo n.º 3
0
    def test_get_channels_filter_language(self):
        """
        utils.get_channels('language', 'language name') should
        return a list of Channels that belong to that category.
        """
        objs = utils.get_channels(self.make_request(), 'language', 'language0')
        self.assertEquals(len(objs), 1)
        self.assertEquals(objs[0].id, self.channels[0].id)

        objs3 = utils.get_channels(self.make_request(), 'language', 'unknown')
        self.assertEquals(len(objs3), 0)
Exemplo n.º 4
0
    def test_get_channels_filter_feed(self):
        """
        utils.get_channels('feed', True) should return Channels
        that have a feed.  False should return a list of Channels that do not.
        """
        self.channels[1].url = None
        self.channels[1].save()
        objs = utils.get_channels(self.make_request(), 'feed', False)
        self.assertEquals(len(objs), 1)
        self.assertEquals(objs[0].id, self.channels[1].id)

        objs2 = utils.get_channels(self.make_request(), 'feed', True)
        self.assertEquals(len(objs2), 1)
        self.assertEquals(objs2[0].id, self.channels[0].id)
Exemplo n.º 5
0
    def test_get_channels_filter_feed(self):
        """
        utils.get_channels('feed', True) should return Channels
        that have a feed.  False should return a list of Channels that do not.
        """
        self.channels[1].url = None
        self.channels[1].save()
        objs = utils.get_channels(self.make_request(), 'feed', False)
        self.assertEquals(len(objs), 1)
        self.assertEquals(objs[0].id, self.channels[1].id)

        objs2 = utils.get_channels(self.make_request(), 'feed', True)
        self.assertEquals(len(objs2), 1)
        self.assertEquals(objs2[0].id, self.channels[0].id)
Exemplo n.º 6
0
    def test_get_channels_filter_audio(self):
        """
        api.get_channels('audio', True) should return Channels that are marked
        as audio.  False should return a list of Channels that are not.
        """
        self.channels[1].state = self.channels[1].AUDIO
        self.channels[1].save()
        objs = utils.get_channels(self.make_request(), 'audio', True)
        self.assertEquals(len(objs), 1)
        self.assertEquals(objs[0].id, self.channels[1].id)

        objs2 = utils.get_channels(self.make_request(), 'audio', False)
        self.assertEquals(len(objs2), 1)
        self.assertEquals(objs2[0].id, self.channels[0].id)
Exemplo n.º 7
0
    def test_get_channels_sort_id(self):
        """
        Passing sort='id' to get_channels should sort the channels by their
        id.
        """
        new = self.make_channel(self.owner, state='A')
        new.name = 'AAA'
        new.save()

        objs = utils.get_channels(self.make_request(), 'name', '', sort='id')
        self.assertSameChannels(objs, self.channels + [new])

        objs = utils.get_channels(self.make_request(), 'name', '', sort='-id')
        self.assertSameChannels(objs, reversed(self.channels + [new]))
Exemplo n.º 8
0
    def test_get_channels_sort_age(self):
        """
        Passing sort='age' to get_channels should sort the channels by their
        approval date.
        """
        new = self.make_channel(self.owner, state='A')
        new.approved_at = datetime.min.replace(year=1900)
        new.save()

        objs = utils.get_channels(self.make_request(), 'name', '', sort='age')
        self.assertEquals(objs[-1].id, new.id)

        objs = utils.get_channels(self.make_request(), 'name', '', sort='-age')
        self.assertEquals(objs[0].id, new.id)
Exemplo n.º 9
0
    def test_get_channels_filter_audio(self):
        """
        api.get_channels('audio', True) should return Channels that are marked
        as audio.  False should return a list of Channels that are not.
        """
        self.channels[1].state = self.channels[1].AUDIO
        self.channels[1].save()
        objs = utils.get_channels(self.make_request(), 'audio', True)
        self.assertEquals(len(objs), 1)
        self.assertEquals(objs[0].id, self.channels[1].id)

        objs2 = utils.get_channels(self.make_request(), 'audio', False)
        self.assertEquals(len(objs2), 1)
        self.assertEquals(objs2[0].id, self.channels[0].id)
Exemplo n.º 10
0
    def test_get_channels_sort_id(self):
        """
        Passing sort='id' to get_channels should sort the channels by their
        id.
        """
        new = self.make_channel(self.owner, state='A')
        new.name = 'AAA'
        new.save()

        objs = utils.get_channels(self.make_request(), 'name', '', sort='id')
        self.assertSameChannels(objs, self.channels + [new])

        objs = utils.get_channels(self.make_request(), 'name', '', sort='-id')
        self.assertSameChannels(objs, reversed(self.channels + [new]))
Exemplo n.º 11
0
    def test_get_channels_sort_age(self):
        """
        Passing sort='age' to get_channels should sort the channels by their
        approval date.
        """
        new = self.make_channel(self.owner, state='A')
        new.approved_at = datetime.min.replace(year=1900)
        new.save()

        objs = utils.get_channels(self.make_request(), 'name', '', sort='age')
        self.assertEquals(objs[-1].id, new.id)

        objs = utils.get_channels(self.make_request(), 'name', '', sort='-age')
        self.assertEquals(objs[0].id, new.id)
Exemplo n.º 12
0
    def test_get_channels_filter_hd(self):
        """
        utils.get_channels('hd', True) should return a list of
        Channels that are high-def.  False should return a list of Channels
        that are not high-def.
        """
        self.channels[1].hi_def = True
        self.channels[1].save()
        objs = utils.get_channels(self.make_request(), 'hd', True)
        self.assertEquals(len(objs), 1)
        self.assertEquals(objs[0].id, self.channels[1].id)

        objs2 = utils.get_channels(self.make_request(), 'hd', False)
        self.assertEquals(len(objs2), 1)
        self.assertEquals(objs2[0].id, self.channels[0].id)
Exemplo n.º 13
0
    def test_get_channels_filter_hd(self):
        """
        utils.get_channels('hd', True) should return a list of
        Channels that are high-def.  False should return a list of Channels
        that are not high-def.
        """
        self.channels[1].hi_def = True
        self.channels[1].save()
        objs = utils.get_channels(self.make_request(), 'hd', True)
        self.assertEquals(len(objs), 1)
        self.assertEquals(objs[0].id, self.channels[1].id)

        objs2 = utils.get_channels(self.make_request(), 'hd', False)
        self.assertEquals(len(objs2), 1)
        self.assertEquals(objs2[0].id, self.channels[0].id)
Exemplo n.º 14
0
    def test_get_channels_archived_sorted_last(self):
        """
        Regardless of any sorting options, archived channels should be sorted
        after all non-archived channels.
        """
        new = self.make_channel(self.owner, state='A')
        new.name = 'AAA'
        new.archived = True
        new.save()

        objs = utils.get_channels(self.make_request(), 'name', '', sort='name')
        self.assertSameChannels(objs, self.channels + [new])

        objs = utils.get_channels(self.make_request(), 'name', '',
                                  sort='-name')
        self.assertSameChannels(objs, list(reversed(self.channels)) + [new])
Exemplo n.º 15
0
 def test_get_channels_filter_search(self):
     self.channels[1].change_state(self.owner, 'N', )
     for channel in self.channels:
         ChannelSearchData.objects.update(channel)
     objs = utils.get_channels(self.make_request(), 'search', 'Channel')
     self.assertEquals(len(objs), 1)
     self.assertEquals(objs[0].id, self.channels[0].id)
Exemplo n.º 16
0
 def test_get_channels_limit(self):
     """
     Passing a limit kwarg to get_channels should limit the number of
     channels that are returned.
     """
     objs = utils.get_channels(self.make_request(), 'name', '', limit=1)
     self.assertEquals(len(objs), 1)
     self.assertEquals(objs[0].id, self.channels[0].id)
Exemplo n.º 17
0
 def test_get_channels_offset(self):
     """
     Passing an offset kwarg to get_channels should skip that number of
     channels.
     """
     objs = utils.get_channels(self.make_request(), 'name', '', offset=1)
     self.assertEquals(len(objs), 1)
     self.assertEquals(objs[0].id, self.channels[1].id)
Exemplo n.º 18
0
 def test_get_channels_offset(self):
     """
     Passing an offset kwarg to get_channels should skip that number of
     channels.
     """
     objs = utils.get_channels(self.make_request(), 'name', '', offset=1)
     self.assertEquals(len(objs), 1)
     self.assertEquals(objs[0].id, self.channels[1].id)
Exemplo n.º 19
0
    def test_get_channels_filter_multiple(self):
        self.channels.append(self.make_channel(self.owner, state='A'))
        self.channels[1].name = 'Testing Testing'
        self.channels[1].url = None
        self.channels[1].save()
        self.channels[2].name = 'Testing Testing'
        self.channels[2].save()

        objs = utils.get_channels(self.make_request(), 'feed', True)
        self.assertEquals(len(objs), 2)
        self.assertEquals(objs[0].id, self.channels[0].id)
        self.assertEquals(objs[1].id, self.channels[2].id)

        objs2 = utils.get_channels(self.make_request(), ('feed', 'name'),
                                (True, self.channels[2].name))
        self.assertEquals(len(objs2), 1)
        self.assertEquals(objs2[0].id, self.channels[2].id)
Exemplo n.º 20
0
 def test_get_channels_filter_search_unicode(self):
     unicode_name = u'\u6771\u68ee\u65b0\u805e'
     self.channels[0].name = unicode_name
     self.channels[0].save()
     ChannelSearchData.objects.update(self.channels[0])
     objs = utils.get_channels(self.make_request(), 'search', unicode_name)
     self.assertEquals(len(objs), 1)
     self.assertEquals(objs[0].id, self.channels[0].id)
Exemplo n.º 21
0
 def test_get_channels_filter_hide_unapproved(self):
     """
     The default should be to only show approved channels.
     """
     self.channels[1].change_state(self.owner, 'N')
     objs = utils.get_channels(self.make_request(), 'name',
                               self.channels[1].name)
     self.assertEquals(len(objs), 0)
Exemplo n.º 22
0
    def test_get_channels_filter_multiple(self):
        self.channels.append(self.make_channel(self.owner, state='A'))
        self.channels[1].name = 'Testing Testing'
        self.channels[1].url = None
        self.channels[1].save()
        self.channels[2].name = 'Testing Testing'
        self.channels[2].save()

        objs = utils.get_channels(self.make_request(), 'feed', True)
        self.assertEquals(len(objs), 2)
        self.assertEquals(objs[0].id, self.channels[0].id)
        self.assertEquals(objs[1].id, self.channels[2].id)

        objs2 = utils.get_channels(self.make_request(), ('feed', 'name'),
                                   (True, self.channels[2].name))
        self.assertEquals(len(objs2), 1)
        self.assertEquals(objs2[0].id, self.channels[2].id)
Exemplo n.º 23
0
 def test_get_channels_limit(self):
     """
     Passing a limit kwarg to get_channels should limit the number of
     channels that are returned.
     """
     objs = utils.get_channels(self.make_request(), 'name', '', limit=1)
     self.assertEquals(len(objs), 1)
     self.assertEquals(objs[0].id, self.channels[0].id)
Exemplo n.º 24
0
 def test_get_channels_filter_hide_unapproved(self):
     """
     The default should be to only show approved channels.
     """
     self.channels[1].change_state(self.owner, 'N')
     objs = utils.get_channels(self.make_request(), 'name',
                               self.channels[1].name)
     self.assertEquals(len(objs), 0)
Exemplo n.º 25
0
 def test_get_channels_filter_search_unicode(self):
     unicode_name = u'\u6771\u68ee\u65b0\u805e'
     self.channels[0].name = unicode_name
     self.channels[0].save()
     ChannelSearchData.objects.update(self.channels[0])
     objs = utils.get_channels(self.make_request(), 'search', unicode_name)
     self.assertEquals(len(objs), 1)
     self.assertEquals(objs[0].id, self.channels[0].id)
Exemplo n.º 26
0
    def test_get_channels_filter_featured(self):
        """
        utils.get_channels('featured', True) should return a list
        of Channels that are currently featured.  False should return a list of
        Channels that are not featured.

        XXX: What should this do about the queue?
        """
        self.channels[1].featured = True
        self.channels[1].featured_by = self.owner
        self.channels[1].save()
        objs = utils.get_channels(self.make_request(), 'featured', True)
        self.assertEquals(len(objs), 1)
        self.assertEquals(objs[0].id, self.channels[1].id)

        objs2 = utils.get_channels(self.make_request(), 'featured', False)
        self.assertEquals(len(objs2), 1)
        self.assertEquals(objs2[0].id, self.channels[0].id)
Exemplo n.º 27
0
    def test_get_channels_archived_sorted_last(self):
        """
        Regardless of any sorting options, archived channels should be sorted
        after all non-archived channels.
        """
        new = self.make_channel(self.owner, state='A')
        new.name = 'AAA'
        new.archived = True
        new.save()

        objs = utils.get_channels(self.make_request(), 'name', '', sort='name')
        self.assertSameChannels(objs, self.channels + [new])

        objs = utils.get_channels(self.make_request(),
                                  'name',
                                  '',
                                  sort='-name')
        self.assertSameChannels(objs, list(reversed(self.channels)) + [new])
Exemplo n.º 28
0
    def test_get_channels_filter_featured(self):
        """
        utils.get_channels('featured', True) should return a list
        of Channels that are currently featured.  False should return a list of
        Channels that are not featured.

        XXX: What should this do about the queue?
        """
        self.channels[1].featured = True
        self.channels[1].featured_by = self.owner
        self.channels[1].save()
        objs = utils.get_channels(self.make_request(), 'featured', True)
        self.assertEquals(len(objs), 1)
        self.assertEquals(objs[0].id, self.channels[1].id)

        objs2 = utils.get_channels(self.make_request(), 'featured', False)
        self.assertEquals(len(objs2), 1)
        self.assertEquals(objs2[0].id, self.channels[0].id)
Exemplo n.º 29
0
    def test_get_channels_sort_popular(self):
        """
        Passing sort='popular' to get_channels should sort the channels by
        their popularity.
        """
        new = self.make_channel(self.owner, state='A')
        Subscription.objects.add(new, '2.2.2.2',
                                 datetime.now() - timedelta(seconds=5))
        Subscription.objects.add(new, '1.1.1.1')

        call_command('refresh_stats_table')

        objs = utils.get_channels(self.make_request(), 'name', '',
                                  sort='popular')
        self.assertEquals(objs[-1].id, new.id)

        objs = utils.get_channels(self.make_request(), 'name', '',
                                  sort='-popular')
        self.assertEquals(objs[0].id, new.id)
Exemplo n.º 30
0
 def test_get_channels_filter_search(self):
     self.channels[1].change_state(
         self.owner,
         'N',
     )
     for channel in self.channels:
         ChannelSearchData.objects.update(channel)
     objs = utils.get_channels(self.make_request(), 'search', 'Channel')
     self.assertEquals(len(objs), 1)
     self.assertEquals(objs[0].id, self.channels[0].id)
Exemplo n.º 31
0
    def test_get_channels_sort_name(self):
        """
        Passing sort='name' to get_channels should sort the channels by their
        name.  Also, if no sort is specified, it should be sorted by name.
        """
        new = self.make_channel(self.owner, state='A')
        new.name = 'AAA'
        new.save()

        objs = utils.get_channels(self.make_request(), 'name', '', sort='name')
        self.assertSameChannels(objs, [new] + self.channels)

        objs = utils.get_channels(self.make_request(), 'name', '',
                                  sort='-name')
        self.assertSameChannels(objs, reversed([new] + self.channels))

        objs = utils.get_channels(self.make_request(), 'name', '')
        self.assertSameChannels(objs, [new] + self.channels)

        objs = utils.get_channels(self.make_request(), 'name', None)
        self.assertSameChannels(objs, [new] + self.channels)
Exemplo n.º 32
0
    def test_get_channels_sort_rating(self):
        """
        Passing sort='rating' to get_channels should sort the channels by
        their rating.
        """
        new = self.make_channel(self.owner, state='A')
        for i in range(6):
            # make some fake ratings so that all the channels have 6 ratings
            fake = self.make_user('fake%i' % i)
            fake.get_profile().approved = True
            fake.get_profile().save()
            for channel in self.channels:
                rating, created = Rating.objects.get_or_create(channel=channel,
                                                               user=fake)
                rating.rating = 3
                rating.save()
            rating, created = Rating.objects.get_or_create(channel=new,
                                                           user=fake)
            rating.rating = 3
            rating.save()
        self.owner.get_profile().approved = True
        self.owner.get_profile().save()
        rating, created = Rating.objects.get_or_create(channel=new,
                                                       user=self.owner)
        rating.rating = 5
        rating.save()

        objs = utils.get_channels(self.make_request(),
                                  'name',
                                  '',
                                  sort='rating')
        self.assertEquals(objs[-1].id, new.id)

        objs = utils.get_channels(self.make_request(),
                                  'name',
                                  '',
                                  sort='-rating')
        self.assertEquals(objs[0].id, new.id)
Exemplo n.º 33
0
    def test_get_channels_sort_popular(self):
        """
        Passing sort='popular' to get_channels should sort the channels by
        their popularity.
        """
        new = self.make_channel(self.owner, state='A')
        Subscription.objects.add(new, '2.2.2.2',
                                 datetime.now() - timedelta(seconds=5))
        Subscription.objects.add(new, '1.1.1.1')

        call_command('refresh_stats_table')

        objs = utils.get_channels(self.make_request(),
                                  'name',
                                  '',
                                  sort='popular')
        self.assertEquals(objs[-1].id, new.id)

        objs = utils.get_channels(self.make_request(),
                                  'name',
                                  '',
                                  sort='-popular')
        self.assertEquals(objs[0].id, new.id)
Exemplo n.º 34
0
    def test_get_channels_sort_name(self):
        """
        Passing sort='name' to get_channels should sort the channels by their
        name.  Also, if no sort is specified, it should be sorted by name.
        """
        new = self.make_channel(self.owner, state='A')
        new.name = 'AAA'
        new.save()

        objs = utils.get_channels(self.make_request(), 'name', '', sort='name')
        self.assertSameChannels(objs, [new] + self.channels)

        objs = utils.get_channels(self.make_request(),
                                  'name',
                                  '',
                                  sort='-name')
        self.assertSameChannels(objs, reversed([new] + self.channels))

        objs = utils.get_channels(self.make_request(), 'name', '')
        self.assertSameChannels(objs, [new] + self.channels)

        objs = utils.get_channels(self.make_request(), 'name', None)
        self.assertSameChannels(objs, [new] + self.channels)