Beispiel #1
0
def test_video_block_get_api_representation():
    video = make_test_video(transcript='Test transcript',
                            subtitles='test subtitle')
    video.save()
    block = GreatMediaBlock()

    block_response = block.get_api_representation(value=video)
    assert block_response == {
        'title':
        'Test file',
        'transcript':
        'Test transcript',
        'sources': [{
            'src': video.url,
            'type': 'video/mp4',
            'transcript': 'Test transcript'
        }],
        'url':
        video.url,
        'thumbnail':
        None,
        'subtitles': [{
            'default': False,
            'label': 'English',
            'srclang': 'en',
            'url': '/subtitles/1/en/content.vtt'
        }]
    }
    # for empty video
    block_response = block.get_api_representation(value=None)
    assert block_response == {}
Beispiel #2
0
def test_serve_subtitles__none_available(client):
    media = make_test_video()
    media.save()

    dest = reverse('subtitles-serve', args=[media.id, 'en'])

    resp = client.get(dest, follow=False)

    assert resp.status_code == 404
Beispiel #3
0
def test_serve_subtitles(client):
    media = make_test_video()

    media.subtitles_en = 'Dummy subtitles content'
    media.save()

    dest = reverse('subtitles-serve', args=[media.id, 'en'])

    resp = client.get(dest, follow=False)

    assert resp.status_code == 200
    assert resp.content == b'Dummy subtitles content'
Beispiel #4
0
 def test_sources_mp4_with_no_transcript(self):
     media = make_test_video()
     self.assertEqual(
         media.sources,
         [
             {
                 'src': '/media/movie.mp4',
                 'type': 'video/mp4',
                 'transcript': None,
             }
         ],
     )
Beispiel #5
0
    def test_sources_mp4_with_transcript(self):
        media = make_test_video(transcript='A test transcript text')

        self.assertEqual(
            media.sources,
            [
                {
                    'src': '/media/movie.mp4',
                    'type': 'video/mp4',
                    'transcript': 'A test transcript text',
                }
            ],
        )
Beispiel #6
0
 def test_subtitles__present(self):
     media = make_test_video()
     media.subtitles_en = 'Dummy subtitles content'
     media.save()
     self.assertTrue(media.subtitles_en)
     expected = [
         {
             'srclang': 'en',
             'label': 'English',
             'url': reverse('subtitles-serve', args=[media.id, 'en']),
             'default': False,
         },
     ]
     self.assertEqual(media.subtitles, expected)
def test_international_homepage_serializer(rf, international_root_page, image):
    home_page = InternationalHomePageFactory(
        slug='international',
        parent=
        international_root_page,  # This is tautological, but irrelevant here
    )
    home_page.hero_subtitle = "THIS LEGACY FIELD SHOULD NOT BE USED"
    fake_video = make_test_video(duration=70,
                                 transcript='Test transcript note')
    with NamedTemporaryFile(delete=True) as img_tmp:
        fake_video.thumbnail.save('test.jpg', File(img_tmp))
        fake_video.save()
    home_page.hero_video = fake_video
    home_page.hero_video.save()

    home_page.homepage_link_panels = [
        (
            'link_panel',
            {
                'title': 'panel one',
                'supporting_text': 'panel one supporting text',
                'link': {
                    'internal_link':
                    home_page,  # Circular link but doesn't matter in this test
                }
            }),
        ('link_panel', {
            'title': 'panel two',
            'supporting_text': 'panel two supporting text',
            'link': {
                'external_link': 'http://example.com/two/',
            }
        }),
    ]
    home_page.save()

    assert home_page.hero_subtitle is not None

    serializer = InternationalHomePageSerializer(
        instance=home_page, context={'request': rf.get('/')})

    assert serializer.data['hero_title'] == home_page.hero_title
    homepage_link_panels = serializer.data['homepage_link_panels']
    assert homepage_link_panels[0]['type'] == 'link_panel'
    assert homepage_link_panels[0]['value'] == {
        'title': 'panel one',
        'supporting_text': 'panel one supporting text',
        'link': home_page.url,
    }
    assert homepage_link_panels[1]['type'] == 'link_panel'
    assert homepage_link_panels[1]['value'] == {
        'title': 'panel two',
        'supporting_text': 'panel two supporting text',
        'link': 'http://example.com/two/',
    }
    assert serializer.data['hero_video']['title'] == 'Test file'
    assert serializer.data['hero_video'][
        'transcript'] == 'Test transcript note'
    assert serializer.data['hero_video'][
        'thumbnail'] == fake_video.thumbnail.url
    assert serializer.data['hero_video']['sources'][0]['src'] == fake_video.url

    # confirm the legacy fields are not exposed:
    for example_field_name in [
            'hero_subtitle',
            'hero_cta_text',
            'hero_cta_link',
            'hero_image',
            'brexit_banner_text',
            'invest_title',
            'invest_content',
            'invest_image',
            # there are more, but these are useful smoke tests
            'case_study_image',
            'case_study_title',
            'case_study_text',
            'case_study_cta_text',
            'case_study_cta_link',
    ]:
        assert example_field_name not in serializer.data
Beispiel #8
0
 def test_subtitles__not_present(self):
     media = make_test_video()
     self.assertFalse(media.subtitles_en)
     self.assertEqual(media.subtitles, [])