Beispiel #1
0
    def test_sitemap(self):
        """Test for the sitemap.xml"""
        category(save=True)
        speaker(save=True)
        video(save=True)

        resp = self.client.get('/sitemap.xml')
        eq_(resp.status_code, 200)
Beispiel #2
0
    def test_sitemap(self):
        """Test for the sitemap.xml"""
        category(save=True)
        speaker(save=True)
        video(save=True)

        resp = self.client.get('/sitemap.xml')
        eq_(resp.status_code, 200)
Beispiel #3
0
    def test_all_videos_for_admins(self):
        """Test that admins can see all videos."""
        video(state=Video.STATE_LIVE, title=u"Foo", save=True)
        video(state=Video.STATE_DRAFT, title=u"Bar", save=True)

        resp = self.auth_get("/api/v2/video/", content_type="application/json")

        data = json.loads(resp.content)
        eq_(len(data["results"]), 2)
Beispiel #4
0
    def test_all_videos_for_admins(self):
        """Test that admins can see all videos."""
        video(state=Video.STATE_LIVE, title=u'Foo', save=True)
        video(state=Video.STATE_DRAFT, title=u'Bar', save=True)

        resp = self.auth_get('/api/v1/video/',
                             content_type='application/json')

        data = json.loads(resp.content)
        eq_(len(data['objects']), 2)
Beispiel #5
0
    def test_all_videos_for_admins(self):
        """Test that admins can see all videos."""
        video(state=Video.STATE_LIVE, title=u'Foo', save=True)
        video(state=Video.STATE_DRAFT, title=u'Bar', save=True)

        resp = self.auth_get('/api/v2/video/',
                             content_type='application/json')

        data = json.loads(smart_text(resp.content))
        eq_(len(data['results']), 2)
Beispiel #6
0
    def test_only_live_videos_for_anonymous_users(self):
        """Test that not authenticated users can't see draft videos."""
        vid_live = video(state=Video.STATE_LIVE, title=u"Foo", save=True)
        video(state=Video.STATE_DRAFT, title=u"Bar", save=True)

        resp = self.client.get("/api/v2/video/", content_type="application/json")

        data = json.loads(resp.content)
        eq_(len(data["results"]), 1)
        eq_(data["results"][0]["title"], vid_live.title)
Beispiel #7
0
    def test_only_live_videos_for_anonymous_users(self):
        """Test that not authenticated users can't see draft videos."""
        vid_live = video(state=Video.STATE_LIVE, title=u'Foo', save=True)
        video(state=Video.STATE_DRAFT, title=u'Bar', save=True)

        resp = self.client.get('/api/v2/video/',
                               content_type='application/json')

        data = json.loads(smart_text(resp.content))
        eq_(len(data['results']), 1)
        eq_(data['results'][0]['title'], vid_live.title)
Beispiel #8
0
    def test_only_live_videos_for_anonymous_users(self):
        """Test that not authenticated users can't see draft videos."""
        vid_live = video(state=Video.STATE_LIVE, title=u'Foo', save=True)
        video(state=Video.STATE_DRAFT, title=u'Bar', save=True)

        resp = self.client.get('/api/v1/video/',
                               content_type='application/json')

        data = json.loads(resp.content)
        eq_(len(data['objects']), 1)
        eq_(data['objects'][0]['title'], vid_live.title)
Beispiel #9
0
    def test_post_with_used_slug(self):
        """Test that an already used slug kicks up a 400."""
        cat = category(save=True)
        video(title='test1', slug='test1', save=True)

        data = {'title': 'test1',
                'category': '/api/v1/category/%d/' % cat.pk,
                'state': Video.STATE_DRAFT,
                'slug': 'test1'}

        resp = self.auth_post('/api/v1/video/', json.dumps(data),
                                content_type='application/json')
        eq_(resp.status_code, 400)
Beispiel #10
0
    def test_post_with_used_slug(self):
        """Test that an already used slug kicks up a 400."""
        cat = category(save=True)
        video(title='test1', slug='test1', save=True)

        data = {'title': 'test1',
                'category': '/api/v1/category/%d/' % cat.pk,
                'state': Video.STATE_DRAFT,
                'slug': 'test1'}

        resp = self.auth_post('/api/v1/video/', json.dumps(data),
                              content_type='application/json')
        eq_(resp.status_code, 400)
Beispiel #11
0
    def test_post_with_used_slug(self):
        """Test that an already used slug kicks up a 400."""
        cat = category(save=True)
        video(title="test1", slug="test1", save=True)

        data = {
            "title": "test1",
            "category": "/api/v1/category/%d/" % cat.pk,
            "state": Video.STATE_DRAFT,
            "slug": "test1",
        }

        resp = self.auth_post("/api/v1/video/", json.dumps(data), content_type="application/json")
        eq_(resp.status_code, 400)
Beispiel #12
0
    def test_videos_by_tag(self):
        tag1 = tag(tag="boat", save=True)
        v1 = video(state=Video.STATE_LIVE, title=u"Foo1", save=True)
        v1.tags = [tag1]
        v1.save()
        v2 = video(state=Video.STATE_LIVE, title=u"Foo2", save=True)
        v2.tags = [tag1]
        v2.save()
        video(state=Video.STATE_LIVE, title=u"Foo3", save=True)

        resp = self.auth_get("/api/v2/video/?tag=boat", content_type="application/json")

        data = json.loads(resp.content)
        eq_(len(data["results"]), 2)
Beispiel #13
0
    def test_videos_by_tag(self):
        tag1 = tag(tag='boat', save=True)
        v1 = video(state=Video.STATE_LIVE, title=u'Foo1', save=True)
        v1.tags = [tag1]
        v1.save()
        v2 = video(state=Video.STATE_LIVE, title=u'Foo2', save=True)
        v2.tags = [tag1]
        v2.save()
        video(state=Video.STATE_LIVE, title=u'Foo3', save=True)

        resp = self.auth_get('/api/v1/video/?tag=boat',
                             content_type='application/json')

        data = json.loads(resp.content)
        eq_(len(data['objects']), 2)
Beispiel #14
0
    def test_post_with_used_slug(self):
        """Test that already used slug creates second video with new slug."""
        cat = category(save=True)
        lang = language(save=True)
        video(title='test1', slug='test1', save=True)

        data = {'title': 'test1',
                'category': cat.title,
                'language': lang.name,
                'state': Video.STATE_DRAFT,
                'slug': 'test1'}

        resp = self.auth_post('/api/v2/video/', json.dumps(data),
                              content_type='application/json')
        eq_(resp.status_code, 201)
Beispiel #15
0
    def test_post_with_used_slug(self):
        """Test that already used slug creates second video with new slug."""
        cat = category(save=True)
        lang = language(save=True)
        video(title='test1', slug='test1', save=True)

        data = {'title': 'test1',
                'category': cat.title,
                'language': lang.name,
                'state': Video.STATE_DRAFT,
                'slug': 'test1'}

        resp = self.auth_post('/api/v2/video/', json.dumps(data),
                              content_type='application/json')
        eq_(resp.status_code, 201)
Beispiel #16
0
    def test_videos_by_tag(self):
        tag1 = tag(tag='boat', save=True)
        v1 = video(state=Video.STATE_LIVE, title=u'Foo1', save=True)
        v1.tags = [tag1]
        v1.save()
        v2 = video(state=Video.STATE_LIVE, title=u'Foo2', save=True)
        v2.tags = [tag1]
        v2.save()
        video(state=Video.STATE_LIVE, title=u'Foo3', save=True)

        resp = self.auth_get('/api/v2/video/?tag=boat',
                             content_type='application/json')

        data = json.loads(smart_text(resp.content))
        eq_(len(data['results']), 2)
Beispiel #17
0
    def test_post_with_used_slug(self):
        """Test that already used slug creates second video with new slug."""
        cat = category(save=True)
        lang = language(save=True)
        video(title="test1", slug="test1", save=True)

        data = {
            "title": "test1",
            "category": cat.title,
            "language": lang.name,
            "state": Video.STATE_DRAFT,
            "slug": "test1",
        }

        resp = self.auth_post("/api/v2/video/", json.dumps(data), content_type="application/json")
        eq_(resp.status_code, 201)
Beispiel #18
0
    def test_put(self):
        """Test that passing in an id, but no slug with a PUT works."""
        cat = category(save=True)
        lang = language(save=True)
        vid = video(title='test1', save=True)

        data = {'id': vid.pk,
                'title': vid.title,
                'category': cat.title,
                'language': lang.name,
                'speakers': ['Guido'],
                'tags': ['foo'],
                'state': Video.STATE_DRAFT}

        resp = self.auth_put('/api/v2/video/%d/' % vid.pk,
                             json.dumps(data),
                             content_type='application/json')
        eq_(resp.status_code, 200)

        # Get the video from the db and compare data.
        vid = Video.objects.get(pk=vid.pk)
        eq_(vid.title, u'test1')
        eq_(vid.slug, u'test1')
        eq_(list(vid.speakers.values_list('name', flat=True)), ['Guido'])
        eq_(list(vid.tags.values_list('tag', flat=True)), ['foo'])
Beispiel #19
0
 def test_bad_video(self):
     with HTTMock(self.ok_200), HTTMock(self.bad_404), HTTMock(
             self.bad_500):
         vid = video(title=u'Foo', source_url='http://400.com')
         vid.save()
         result = models.VideoUrlStatus.objects.create_for_video(vid)
     eq_(result, {404: 1})
Beispiel #20
0
    def test_put(self):
        """Test that passing in an id, but no slug with a PUT works."""
        cat = category(save=True)
        lang = language(save=True)
        vid = video(title='test1', save=True)

        data = {'id': vid.pk,
                'title': vid.title,
                'category': cat.title,
                'language': lang.name,
                'speakers': ['Guido'],
                'tags': ['foo'],
                'state': Video.STATE_DRAFT}

        resp = self.auth_put('/api/v2/video/%d/' % vid.pk,
                             json.dumps(data),
                             content_type='application/json')
        eq_(resp.status_code, 200)

        # Get the video from the db and compare data.
        vid = Video.objects.get(pk=vid.pk)
        eq_(vid.title, u'test1')
        eq_(vid.slug, u'test1')
        eq_(list(vid.speakers.values_list('name', flat=True)), ['Guido'])
        eq_(list(vid.tags.values_list('tag', flat=True)), ['foo'])
Beispiel #21
0
    def test_put(self):
        """Test that passing in an id, but no slug with a PUT works."""
        cat = category(save=True)
        lang = language(save=True)
        vid = video(title="test1", save=True)

        data = {
            "id": vid.pk,
            "title": vid.title,
            "category": cat.title,
            "language": lang.name,
            "speakers": ["Guido"],
            "tags": ["foo"],
            "state": Video.STATE_DRAFT,
        }

        resp = self.auth_put("/api/v2/video/%d/" % vid.pk, json.dumps(data), content_type="application/json")
        eq_(resp.status_code, 200)

        # Get the video from the db and compare data.
        vid = Video.objects.get(pk=vid.pk)
        eq_(vid.title, u"test1")
        eq_(vid.slug, u"test1")
        eq_(list(vid.speakers.values_list("name", flat=True)), ["Guido"])
        eq_(list(vid.tags.values_list("tag", flat=True)), ["foo"])
Beispiel #22
0
    def test_category_feed(self):
        """Tests for Category rss feed"""

        # Test that only categories with live videos are included.
        feed = CategoryFeed()

        cat = category(save=True)
        video(category=cat, save=True)
        v2 = video(category=cat, save=True)

        # No live videos, no category in feed
        eq_(len(feed.items()), 0)

        # At least one video is live, category is included
        v2.state = Video.STATE_LIVE
        v2.save()
        eq_([x.pk for x in feed.items()], [cat.pk])

        # Category feed description_template exists.
        found_tpl = True
        try:
            get_template(feed.description_template)
        except TemplateDoesNotExist:
            found_tpl = False
        eq_(found_tpl, True)

        # Category list feeds is accessible.
        resp = self.client.get(reverse('videos-category-feed'))
        eq_(resp.status_code, 200)

        # Category videos feed is accessible.
        resp = self.client.get(
            reverse('videos-category-videos-feed',
                    kwargs={
                        'category_id': cat.id,
                        'slug': cat.slug
                    }))
        eq_(resp.status_code, 200)

        # Category videos feed returns 404, invalid category_id.
        resp = self.client.get(
            reverse('videos-category-videos-feed',
                    kwargs={
                        'category_id': 50,
                        'slug': 'fake-slug'
                    }))
        eq_(resp.status_code, 404)
Beispiel #23
0
    def test_inactive_video_category_page(self):
        """Inactive video should not show up on category page."""
        vid = video(save=True)

        category_url = vid.category.get_absolute_url()

        resp = self.client.get(category_url)
        self.assertNotContains(resp, vid.title)
Beispiel #24
0
    def test_inactive_video_category_page(self):
        """Inactive video should not show up on category page."""
        vid = video(save=True)

        category_url = vid.category.get_absolute_url()

        resp = self.client.get(category_url)
        assert vid.title not in resp.content
Beispiel #25
0
    def test_active_video_category_page(self):
        """Active video should shows up on category page."""
        vid = video(state=Video.STATE_LIVE, save=True)

        category_url = vid.category.get_absolute_url()

        resp = self.client.get(category_url)
        assert vid.title in resp.content
Beispiel #26
0
    def test_inactive_video_category_page(self):
        """Inactive video should not show up on category page."""
        vid = video(save=True)

        category_url = vid.category.get_absolute_url()

        resp = self.client.get(category_url)
        assert vid.title not in resp.content
Beispiel #27
0
    def test_active_video_category_page(self):
        """Active video should shows up on category page."""
        vid = video(state=Video.STATE_LIVE, save=True)

        category_url = vid.category.get_absolute_url()

        resp = self.client.get(category_url)
        assert vid.title in resp.content
Beispiel #28
0
    def test_related_url(self):
        """Related urls should show up on the page."""
        v = video(save=True)
        rurl = related_url(video_id=v.id, url=u'http://example.com/foo',
                           description=u'Example related url',
                           save=True)

        resp = self.client.get(v.get_absolute_url())
        self.assertContains(resp, rurl.description)
Beispiel #29
0
    def test_related_url(self):
        """Related urls should show up on the page."""
        v = video(save=True)
        rurl = related_url(video_id=v.id, url=u'http://example.com/foo',
                           description=u'Example related url',
                           save=True)

        resp = self.client.get(v.get_absolute_url())
        assert rurl.description in resp.content
Beispiel #30
0
    def test_api_disabled(self):
        """Test that disabled api kicks up 404"""
        if settings.API:
            raise SkipTest

        vid = video(state=Video.STATE_LIVE, save=True)

        # anonymous user
        resp = self.client.get('/api/v1/video/%d/' % vid.pk, {'format': 'json'})
        eq_(resp.status_code, 404)
Beispiel #31
0
    def test_active_video_speaker_page(self):
        """Active video should show up on it's speaker's page."""
        s = speaker(save=True)
        vid = video(state=Video.STATE_LIVE, save=True)
        vid.speakers.add(s)

        speaker_url = s.get_absolute_url()

        resp = self.client.get(speaker_url)
        assert vid.title in resp.content
Beispiel #32
0
    def test_inactive_video_speaker_page(self):
        """Inactive video should not show up on it's speaker's page."""
        s = speaker(save=True)
        vid = video(save=True)
        vid.speakers.add(s)

        speaker_url = s.get_absolute_url()

        resp = self.client.get(speaker_url)
        assert vid.title not in resp.content
Beispiel #33
0
    def test_active_video_speaker_page(self):
        """Active video should show up on it's speaker's page."""
        s = speaker(save=True)
        vid = video(state=Video.STATE_LIVE, save=True)
        vid.speakers.add(s)

        speaker_url = s.get_absolute_url()

        resp = self.client.get(speaker_url)
        assert vid.title in resp.content
Beispiel #34
0
    def test_category_feed(self):
        """Tests for Category rss feed"""

        # Test that only categories with live videos are included.
        feed = CategoryFeed()

        cat = category(save=True)
        video(category=cat, save=True)
        v2 = video(category=cat, save=True)

        # No live videos, no category in feed
        eq_(len(feed.items()), 0)

        # At least one video is live, category is included
        v2.state = Video.STATE_LIVE
        v2.save()
        eq_([x.pk for x in feed.items()], [cat.pk])

        # Category feed description_template exists.
        found_tpl = True
        try:
            get_template(feed.description_template)
        except TemplateDoesNotExist:
            found_tpl = False
        eq_(found_tpl, True)

        # Category list feeds is accessible.
        resp = self.client.get(reverse('videos-category-feed'))
        eq_(resp.status_code, 200)

        # Category videos feed is accessible.
        resp = self.client.get(
            reverse(
                'videos-category-videos-feed',
                kwargs={'category_id': cat.id, 'slug': cat.slug}))
        eq_(resp.status_code, 200)

        # Category videos feed returns 404, invalid category_id.
        resp = self.client.get(
            reverse(
                'videos-category-videos-feed',
                kwargs={'category_id': 50, 'slug': 'fake-slug'}))
        eq_(resp.status_code, 404)
Beispiel #35
0
    def test_inactive_video_speaker_page(self):
        """Inactive video should not show up on it's speaker's page."""
        s = speaker(save=True)
        vid = video(save=True)
        vid.speakers.add(s)

        speaker_url = s.get_absolute_url()

        resp = self.client.get(speaker_url)
        assert vid.title not in resp.content
Beispiel #36
0
    def test_api_disabled(self):
        """Test that disabled api kicks up 404"""
        if settings.API:
            raise SkipTest

        vid = video(state=Video.STATE_LIVE, save=True)

        # anonymous user
        resp = self.client.get('/api/v1/video/%d/' % vid.pk,
                               {'format': 'json'})
        eq_(resp.status_code, 404)
Beispiel #37
0
    def test_api_disabled(self):
        """Test that disabled api kicks up 404"""
        with self.settings(API=False):
            reload(video_urls_module)
            vid = video(state=Video.STATE_LIVE, save=True)

            # anonymous user
            resp = self.client.get("/api/v2/video/%d/" % vid.pk, {"format": "json"})
            eq_(resp.status_code, 404)

        reload(video_urls_module)
Beispiel #38
0
    def test_videos_by_speaker(self):
        speaker1 = speaker(name="webber", save=True)
        v1 = video(state=Video.STATE_LIVE, title=u"Foo1", save=True)
        v1.speakers = [speaker1]
        v1.save()
        v2 = video(state=Video.STATE_LIVE, title=u"Foo2", save=True)
        v2.speakers = [speaker1]
        v2.save()
        video(state=Video.STATE_LIVE, title=u"Foo3", save=True)

        # Filter by full name.
        resp = self.auth_get("/api/v2/video/?speaker=webber", content_type="application/json")

        data = json.loads(resp.content)
        eq_(len(data["results"]), 2)

        # Filter by partial name.
        resp = self.auth_get("/api/v2/video/?speaker=web", content_type="application/json")

        data = json.loads(resp.content)
        eq_(len(data["results"]), 2)
Beispiel #39
0
    def test_api_disabled(self):
        """Test that disabled api kicks up 404"""
        with self.settings(API=False):
            reload(video_urls_module)
            vid = video(state=Video.STATE_LIVE, save=True)

            # anonymous user
            resp = self.client.get('/api/v2/video/%d/' % vid.pk,
                                   {'format': 'json'})
            eq_(resp.status_code, 404)

        reload(video_urls_module)
Beispiel #40
0
 def test_bad_video_multiple_links(self):
     with HTTMock(self.ok_200), HTTMock(self.bad_404), HTTMock(self.bad_500):
         vid = video(title=u'Foo',
                     source_url='http://400.com',
                     thumbnail_url='http://500.com',
                     video_ogv_url='http://200.com',
                     video_mp4_url='http://400.com',
                     video_flv_url='http://400.com',
                     )
         vid.save()
         result = models.VideoUrlStatus.objects.create_for_video(vid)
     eq_(result, {404: 3,
                  500: 1})
Beispiel #41
0
    def test_download_only(self):
        """Video urls marked as download-only shouldn't be in video tag."""
        v = video(video_ogv_url='http://example.com/OGV_VIDEO',
                  video_ogv_download_only=False,
                  video_mp4_url='http://example.com/MP4_VIDEO',
                  video_mp4_download_only=True,
                  save=True)

        resp = self.client.get(v.get_absolute_url())
        # This shows up in video tag and in downloads area
        eq_(resp.content.count('OGV_VIDEO'), 2)
        # This only shows up in downloads area
        eq_(resp.content.count('MP4_VIDEO'), 1)
Beispiel #42
0
    def test_download_only(self):
        """Video urls marked as download-only shouldn't be in video tag."""
        v = video(video_ogv_url='http://example.com/OGV_VIDEO',
                  video_ogv_download_only=False,
                  video_mp4_url='http://example.com/MP4_VIDEO',
                  video_mp4_download_only=True,
                  save=True)

        resp = self.client.get(v.get_absolute_url())
        # This shows up in video tag and in downloads area
        eq_(resp.content.count('OGV_VIDEO'), 2)
        # This only shows up in downloads area
        eq_(resp.content.count('MP4_VIDEO'), 1)
Beispiel #43
0
    def test_get_video(self):
        """Test that a video can be retrieved."""
        vid = video(state=Video.STATE_LIVE, save=True)

        # anonymous user
        resp = self.client.get('/api/v1/video/%d/' % vid.pk, {'format': 'json'})
        eq_(resp.status_code, 200)
        eq_(json.loads(resp.content)['title'], vid.title)

        # authenticated user
        resp = self.auth_get('/api/v1/video/%d/' % vid.pk, {'format': 'json'})
        eq_(resp.status_code, 200)
        eq_(json.loads(resp.content)['title'], vid.title)
Beispiel #44
0
    def test_get_video(self):
        """Test that a video can be retrieved."""
        vid = video(state=Video.STATE_LIVE, save=True)

        # anonymous user
        resp = self.client.get("/api/v2/video/%d/" % vid.pk, {"format": "json"})
        eq_(resp.status_code, 200)
        eq_(json.loads(resp.content)["title"], vid.title)

        # authenticated user
        resp = self.auth_get("/api/v2/video/%d/" % vid.pk, {"format": "json"})
        eq_(resp.status_code, 200)
        eq_(json.loads(resp.content)["title"], vid.title)
Beispiel #45
0
    def test_put_with_slug_and_no_id(self):
        """Test that a slug but no id with a PUT fails."""
        cat = category(save=True)
        v = video(title='test1', slug='test1', save=True)

        data = {'slug': v.slug,
                'title': 'test1',
                'category': '/api/v1/category/%d/' % cat.pk,
                'state': Video.STATE_DRAFT}

        resp = self.auth_put('/api/v1/video/%d/' % v.pk,
                             json.dumps(data),
                             content_type='application/json')
        eq_(resp.status_code, 400)
Beispiel #46
0
    def test_get_video(self):
        """Test that a video can be retrieved."""
        vid = video(state=Video.STATE_LIVE, save=True)

        # anonymous user
        resp = self.client.get('/api/v1/video/%d/' % vid.pk,
                               {'format': 'json'})
        eq_(resp.status_code, 200)
        eq_(json.loads(resp.content)['title'], vid.title)

        # authenticated user
        resp = self.auth_get('/api/v1/video/%d/' % vid.pk, {'format': 'json'})
        eq_(resp.status_code, 200)
        eq_(json.loads(resp.content)['title'], vid.title)
Beispiel #47
0
    def test_opensearch_suggestions(self):
        """Test the opensearch suggestions view."""
        video(title='introduction to pypy', save=True)
        video(title='django testing', save=True)
        video(title='pycon 2012 keynote', save=True)
        video(title='Speedily Practical Large-Scale Tests', save=True)
        management.call_command('rebuild_index', interactive=False)

        url = reverse('videos-opensearch-suggestions')

        response = self.client.get(url, {'q': 'test'})
        eq_(response.status_code, 200)
        data = json.loads(response.content)
        eq_(data[0], 'test')
        eq_(set(data[1]),
            set(['django testing', 'Speedily Practical Large-Scale Tests']))
Beispiel #48
0
    def test_videos_by_speaker(self):
        speaker1 = speaker(name='webber', save=True)
        v1 = video(state=Video.STATE_LIVE, title=u'Foo1', save=True)
        v1.speakers = [speaker1]
        v1.save()
        v2 = video(state=Video.STATE_LIVE, title=u'Foo2', save=True)
        v2.speakers = [speaker1]
        v2.save()
        video(state=Video.STATE_LIVE, title=u'Foo3', save=True)

        # Filter by full name.
        resp = self.auth_get('/api/v1/video/?speaker=webber',
                             content_type='application/json')

        data = json.loads(resp.content)
        eq_(len(data['objects']), 2)

        # Filter by partial name.
        resp = self.auth_get('/api/v1/video/?speaker=web',
                             content_type='application/json')

        data = json.loads(resp.content)
        eq_(len(data['objects']), 2)
Beispiel #49
0
    def test_put_with_slug_and_no_id(self):
        """Test that a slug but no id with a PUT fails."""
        cat = category(save=True)
        v = video(title='test1', slug='test1', save=True)

        data = {'slug': v.slug,
                'title': 'test1',
                'category': '/api/v1/category/%d/' % cat.pk,
                'state': Video.STATE_DRAFT}

        resp = self.auth_put('/api/v1/video/%d/' % v.pk,
                             json.dumps(data),
                             content_type='application/json')
        eq_(resp.status_code, 400)
Beispiel #50
0
    def test_videos_by_speaker(self):
        speaker1 = speaker(name='webber', save=True)
        v1 = video(state=Video.STATE_LIVE, title=u'Foo1', save=True)
        v1.speakers = [speaker1]
        v1.save()
        v2 = video(state=Video.STATE_LIVE, title=u'Foo2', save=True)
        v2.speakers = [speaker1]
        v2.save()
        video(state=Video.STATE_LIVE, title=u'Foo3', save=True)

        # Filter by full name.
        resp = self.auth_get('/api/v2/video/?speaker=webber',
                             content_type='application/json')

        data = json.loads(smart_text(resp.content))
        eq_(len(data['results']), 2)

        # Filter by partial name.
        resp = self.auth_get('/api/v2/video/?speaker=web',
                             content_type='application/json')

        data = json.loads(smart_text(resp.content))
        eq_(len(data['results']), 2)
Beispiel #51
0
    def test_opensearch_suggestions(self):
        """Test the opensearch suggestions view."""
        video(title='introduction to pypy', save=True)
        video(title='django testing', save=True)
        video(title='pycon 2012 keynote', save=True)
        video(title='Speedily Practical Large-Scale Tests', save=True)
        management.call_command('rebuild_index', interactive=False)

        url = reverse('videos-opensearch-suggestions')

        response = self.client.get(url, {'q': 'test'})
        eq_(response.status_code, 200)
        data = json.loads(response.content)
        eq_(data[0], 'test')
        eq_(set(data[1]),
            set(['django testing', 'Speedily Practical Large-Scale Tests']))
Beispiel #52
0
 def test_bad_video_multiple_links(self):
     with HTTMock(self.ok_200), HTTMock(self.bad_404), HTTMock(
             self.bad_500):
         vid = video(
             title=u'Foo',
             source_url='http://400.com',
             thumbnail_url='http://500.com',
             video_ogv_url='http://200.com',
             video_mp4_url='http://400.com',
             video_flv_url='http://400.com',
         )
         vid.save()
         result = models.VideoUrlStatus.objects.create_for_video(vid)
     eq_(result, {404: 3, 500: 1})
Beispiel #53
0
    def test_video_urls(self):
        """Test the view of a video."""
        vid = video(save=True)

        cases = [
            vid.get_absolute_url(),
            u'/video/%s/%s/' % (vid.id, vid.slug),  # with slug and /
            u'/video/%s/%s' % (vid.id, vid.slug),  # with slug and no /
            u'/video/%s/' % vid.id,  # no slug and /
            u'/video/%s' % vid.id,  # no slug and no /
        ]

        for url in cases:
            resp = self.client.get(url)
            eq_(resp.status_code, 200)
            self.assertTemplateUsed(resp, 'videos/video.html')
Beispiel #54
0
    def test_video_feed_enclosures(self):
        """Test for encolures of video feeds"""

        # Since video feeds that has enclosure enabled are inherited from the
        # same base feed class ``BaseVideoFeed``, we only need to create a
        # general enclosure test for it.

        # Note: Feed content tests will be applied against `newly posted video`
        # feeds, for the sake of simplicity.
        feeds_url = reverse('videos-new-feed')

        example_url = 'http://example.com/123456'
        youtube_source_url = 'http://www.youtube.com/watch?v=123456'

        vid = video(state=Video.STATE_LIVE, save=True)

        # No video & source urls specified, no enclosures available in feeds.
        resp = self.client.get(feeds_url)
        self.assertNotContains(resp, 'enclosure')

        # `source_url` specified, but not a youtube url.
        vid.source_url = example_url
        vid.save()
        resp = self.client.get(feeds_url)
        self.assertNotContains(resp, 'enclosure')

        # `source_url` specified, this time a youtube url. Enclosure available.
        vid.source_url = youtube_source_url
        vid.save()
        resp = self.client.get(feeds_url)
        self.assertContains(resp, 'enclosure')
        self.assertContains(resp, youtube_source_url)

        # video urls available, correct urls displayed in feeds.
        vid.video_ogv_url = example_url + '.ogv'
        vid.video_webm_url = example_url + '.webm'
        vid.video_mp4_url = example_url + '.mp4'
        vid.video_flv_url = example_url + '.flv'
        vid.save()
        resp = self.client.get(feeds_url)
        self.assertContains(resp, vid.video_ogv_url)
        self.assertContains(resp, vid.video_webm_url)
        self.assertContains(resp, vid.video_mp4_url)
        self.assertContains(resp, vid.video_flv_url)
Beispiel #55
0
    def test_get_video_data(self):
        cat = category(title=u'Foo Title', save=True)
        vid = video(title=u'Foo Bar', category=cat, state=Video.STATE_LIVE,
                    save=True)
        t = tag(tag=u'tag', save=True)
        vid.tags = [t]
        s = speaker(name=u'Jim', save=True)
        vid.speakers = [s]

        resp = self.client.get('/api/v1/video/%d/' % vid.pk,
                               {'format': 'json'})
        eq_(resp.status_code, 200)
        content = json.loads(resp.content)
        eq_(content['title'], vid.title)
        eq_(content['slug'], 'foo-bar')
        # This should be the category title--not api url
        eq_(content['category'], cat.title)
        # This should be the tag--not api url
        eq_(content['tags'], [t.tag])
        # This should be the speaker name--not api url
        eq_(content['speakers'], [s.name])
Beispiel #56
0
    def test_put_fails_with_live_videos(self):
        """Test that passing in an id, but no slug with a PUT works."""
        cat = category(save=True)
        lang = language(save=True)
        vid = video(
            title='test1',
            category=cat,
            language=lang,
            state=Video.STATE_LIVE,
            save=True)

        data = {'id': vid.pk,
                'title': 'new title',
                'category': cat.title,
                'language': lang.name,
                'speakers': ['Guido'],
                'tags': ['foo'],
                'state': Video.STATE_DRAFT}

        resp = self.auth_put('/api/v2/video/%d/' % vid.pk,
                             json.dumps(data),
                             content_type='application/json')
        eq_(resp.status_code, 403)
Beispiel #57
0
 def test_slug_creation(self):
     """Slug is based on title."""
     v = video(title=u'Foo Bar')
     eq_(generate_unique_slug(v, u'title', u'slug'), u'foo-bar')
Beispiel #58
0
 def test_unicode_title(self):
     v = video(title=u'Nebenläufige Programme mit Python')
     eq_(generate_unique_slug(v, u'title', u'slug'),
         u'nebenlaufige-programme-mit-python')
Beispiel #59
0
    def test_unique_slug(self):
        """Generate unique slug using incrementing ending."""
        # These all have the same title, so they get increasingly
        # lame slugs.
        video(title=u'Foo', save=True)
        video(title=u'Foo', save=True)
        video(title=u'Foo', save=True)
        video(title=u'Foo', save=True)
        video(title=u'Foo', save=True)

        v2 = video(title=u'Foo')
        eq_(generate_unique_slug(v2, u'title', u'slug'), u'foo-4')