コード例 #1
0
    def test_video_id_not_required_if_block_is_not_required(self):
        block = VideoPlayer(required=False)
        value = block.to_python({'video_id': None})

        try:
            block.clean(value)
        except ValidationError as e:  # pragma: nocover
            self.fail('Optional VideoPlayers should not require sub-fields')
コード例 #2
0
    def test_valid_video_id(self):
        block = VideoPlayer(required=False)
        value = block.to_python({'video_id': '1V0Ax9OIc84'})

        try:
            block.clean(value)
        except ValidationError as e:  # pragma: nocover
            self.fail('VideoPlayer should support valid YouTube IDs')
コード例 #3
0
    def test_value_contains_thumbnail_url(self):
        block = VideoPlayer()
        value = block.to_python({
            'video_id': '1V0Ax9OIc84',
            'thumbnail_image': self.image.pk,
        })

        self.assertRegex(value.thumbnail_url,
                         r'^.*/images/test.*\.original\.png$')
コード例 #4
0
    def test_render(self):
        block = VideoPlayer()
        value = block.to_python({
            'video_id': '1V0Ax9OIc84',
            'thumbnail_image': self.image.pk,
        })

        request = RequestFactory().get('/')
        html = block.render(value, context={'request': request})

        self.assertIn('href="https://www.youtube.com/embed/1V0Ax9OIc84', html)
        self.assertRegex(html, r'src="/f/images/test.*\.original\.png"')
コード例 #5
0
    def test_render(self):
        block = VideoPlayer()
        value = block.to_python({'video_id': '1V0Ax9OIc84'})

        request = RequestFactory().get('/')
        html = block.render(value, context={'request': request})

        self.assertIn('href="https://www.youtube.com/embed/1V0Ax9OIc84', html)

        # Default no-JS image is used if no thumbnail is provided.
        self.assertIn('src="/static/img/cfpb_video_cover_card_1380x776.png"',
                      html)

        # Default behavior doesn't render as FCM.
        self.assertNotIn('o-featured-content-module_visual', html)
コード例 #6
0
    def test_thumbnail_image_without_video_id_fails_validation(self):
        block = VideoPlayer(required=False)
        value = block.to_python({'thumbnail_image': self.image.pk})

        with self.assertRaises(ValidationError):
            block.clean(value)
コード例 #7
0
    def test_invalid_video_id(self):
        block = VideoPlayer()
        value = block.to_python({'video_url': 'Invalid YouTube ID'})

        with self.assertRaises(ValidationError):
            block.clean(value)
コード例 #8
0
    def test_video_id_required_by_default(self):
        block = VideoPlayer()
        value = block.to_python({'video_id': None})

        with self.assertRaises(ValidationError):
            block.clean(value)