Example #1
0
    def test_video_controller(self):
        """Should output html strings with the information included"""

        data_1 = {
            'id': '1234',
            'title': 'Test title',
            'caption': 'Test caption',
            'credit': 'Test credit'
        }
        data_2 = {
            'id': '1234',
            'title': 'Test title',
            'caption': 'Test caption',
        }
        data_3 = {'id': '1234', 'title': 'Test title', 'credit': 'Test credit'}
        data_4 = {
            'id': '1234',
            'title': 'Test title',
        }
        data_5 = {'id': '', 'title': ''}

        result_1 = embeds.render('video', data_1)
        result_2 = embeds.render('video', data_2)
        result_3 = embeds.render('video', data_3)
        result_4 = embeds.render('video', data_4)
        result_5 = embeds.render('video', data_5)

        prefix = ('<iframe\n'
                  'allowfullscreen="allowfullscreen"\n'
                  'mozallowfullscreen="mozallowfullscreen"\n'
                  'msallowfullscreen="msallowfullscreen"\n'
                  'oallowfullscreen="oallowfullscreen"\n'
                  'webkitallowfullscreen="webkitallowfullscreen"\n'
                  'src=')

        self.assertEqual(
            result_1.strip().replace(" ", ""), prefix +
            '"https://www.youtube.com/watch?v=1234"></iframe>\n<h1>Testtitle</h1>\n<divclass="caption">\nTestcaption<spanclass="credit">Testcredit</span>\n</div>'
        )
        self.assertEqual(
            result_2.strip().replace(" ", ""), prefix +
            '"https://www.youtube.com/watch?v=1234"></iframe>\n<h1>Testtitle</h1>\n<divclass="caption">\nTestcaption<spanclass="credit"></span>\n</div>'
        )
        self.assertEqual(
            result_3.strip().replace(" ", ""), prefix +
            '"https://www.youtube.com/watch?v=1234"></iframe>\n<h1>Testtitle</h1>\n<divclass="caption">\n<spanclass="credit">Testcredit</span>\n</div>'
        )
        self.assertEqual(
            result_4.strip().replace(" ", ""), prefix +
            '"https://www.youtube.com/watch?v=1234"></iframe>\n<h1>Testtitle</h1>'
        )
        self.assertEqual(
            result_5.strip().replace(" ", ""),
            prefix + '"https://www.youtube.com/watch?v="></iframe>\n<h1></h1>')
Example #2
0
    def test_advertisement_controller(self):
        """Should output id of ad and alignment in html"""

        data_1 = {'id': 'ad-1', 'alignment': 'right'}

        data_2 = {'id': '', 'alignment': ''}

        result_1 = embeds.render('advertisement', data_1)
        result_2 = embeds.render('advertisement', data_2)

        self.assertEqual(
            result_1.strip(),
            '<div class="ad"><span>ad-1</span><span>right</span></div>')
        self.assertEqual(result_2.strip(),
                         '<div class="ad"><span></span><span></span></div>')
Example #3
0
    def render_node(html, node, index):
        """Renders node as HTML"""
        if node['type'] == 'paragraph':
            return html + '<p>%s</p>' % node['data']
        else:

            if node['type'] == 'ad':
                id = 'div-gpt-ad-1443288719995-' + str(10 + index) + '-' + str(article_id)
                dfp_type = 'Intra_Article_' + str(index + 1)
                size = 'banner'
                if node['data'] == 'mobile':
                    size = 'box'
                newString = '<div class="o-article-embed__advertisement"><div class="o-advertisement o-advertisment--banner o-advertisement--center"><div class="adslot" id="' + id + '" data-size="' + size + '" data-dfp="' + dfp_type + '"></div></div></div>'
                return html + '<div class="o-article-embed o-article-embed--advertisement">%s</div>\n' % newString
            try:
                if node['type'] == 'poll':
                    node['type'] = 'widget'
                    node['data']['data'] = node['data']

                if node['type'] == 'interactive map':
                    return html + node['data']['svg'] + node['data']['initScript']
                    
                return html + embeds.render(node['type'], node['data'])
            except EmbedException:
                return html
Example #4
0
    def test_video_controller(self):
        """Should output html strings with the information included"""

        data_1 = {
            'id': '1234',
            'title': 'Test title',
            'caption': 'Test caption',
            'credit': 'Test credit'
        }
        data_2 = {
            'id': '1234',
            'title': 'Test title',
            'caption': 'Test caption',
        }
        data_3 = {'id': '1234', 'title': 'Test title', 'credit': 'Test credit'}
        data_4 = {
            'id': '1234',
            'title': 'Test title',
        }
        data_5 = {'id': '', 'title': ''}

        result_1 = embeds.render('video', data_1)
        result_2 = embeds.render('video', data_2)
        result_3 = embeds.render('video', data_3)
        result_4 = embeds.render('video', data_4)
        result_5 = embeds.render('video', data_5)

        self.assertEqual(
            result_1.strip(),
            '<iframe src="https://www.youtube.com/watch?v=1234"></iframe>\n<h1>Test title</h1>\n<div class="caption">\n    Test caption <span class="credit">Test credit</span>\n</div>'
        )
        self.assertEqual(
            result_2.strip(),
            '<iframe src="https://www.youtube.com/watch?v=1234"></iframe>\n<h1>Test title</h1>\n<div class="caption">\n    Test caption <span class="credit"></span>\n</div>'
        )
        self.assertEqual(
            result_3.strip(),
            '<iframe src="https://www.youtube.com/watch?v=1234"></iframe>\n<h1>Test title</h1>\n<div class="caption">\n     <span class="credit">Test credit</span>\n</div>'
        )
        self.assertEqual(
            result_4.strip(),
            '<iframe src="https://www.youtube.com/watch?v=1234"></iframe>\n<h1>Test title</h1>'
        )
        self.assertEqual(
            result_5.strip(),
            '<iframe src="https://www.youtube.com/watch?v="></iframe>\n<h1></h1>'
        )
Example #5
0
    def test_register_existing_type(self):
        """Should overwrite previous type"""

        data_1 = {'size': 'h1', 'content': 'Header text'}

        embeds.register('quote', HeaderEmbed)

        result = embeds.render('quote', data_1)

        self.assertEqual(result, '<h1>Header text</h1>')
Example #6
0
    def test_not_in_embedlib(self):
        """Should raise EmbedException"""

        data = {'id': '123'}

        try:
            result = embeds.render('test', data)
            self.fail('EmbedDoesNotExist exception should have been raised')
        except EmbedException:
            pass
Example #7
0
    def test_pull_quote_controller(self):
        """Gives quote and source"""

        data_1 = {'content': 'This is a quote', 'source': 'This is the source'}

        data_2 = {'content': 'This is a quote'}

        data_3 = {'content': ''}

        result_1 = embeds.render('quote', data_1)
        result_2 = embeds.render('quote', data_2)
        result_3 = embeds.render('quote', data_3)

        self.assertEqual(
            result_1.strip(),
            '<p class="quote">This is a quote</p>\n  <p class="source">&mdash; This is the source</p>'
        )
        self.assertEqual(result_2.strip(),
                         '<p class="quote">This is a quote</p>')
        self.assertEqual(result_3.strip(), '<p class="quote"></p>')
Example #8
0
    def test_gallery_controller_render(self):
        """Test "render" with gallery controller, uses "get_gallery" and "prepare_data"""

        gallery, img_1, img_2 = DispatchTestHelpers.create_gallery(
            0, self.client)

        result = embeds.render('gallery', gallery.data)

        html_str = '<div class="gallery-attachment">\n    <div class="images">\n        \n        <img src="%s" />\n        \n        <img src="%s" />\n        \n    </div>\n</div>\n' % (
            img_1.data['url'], img_2.data['url'])

        self.assertEqual(result, html_str)
Example #9
0
    def test_image_controller_render(self):
        """Should output html string"""

        image = DispatchTestHelpers.create_image(self.client)

        data = {
            'image_id': image.data['id'],
            'caption': 'This is a test caption',
            'credit': 'This is a test credit'
        }

        html_str = u'<div class="image-embed">\n    <img class="image" src="%s" alt="This is a test caption" />\n    <div class="caption">This is a test caption</div>\n    <div class="credit">This is a test credit</div>\n</div>\n' % image.data[
            'url']

        result = embeds.render('image', data)

        self.assertEqual(result, html_str)