def test_get_embed(self): embed = get_embed('www.test.com/1234', max_width=400, finder=self.dummy_finder) # Check that the embed is correct self.assertEqual(embed.title, "Test: www.test.com/1234") self.assertEqual(embed.type, 'video') self.assertEqual(embed.width, 400) # Check that there has only been one hit to the backend self.assertEqual(self.hit_count, 1) # Look for the same embed again and check the hit count hasn't increased embed = get_embed('www.test.com/1234', max_width=400, finder=self.dummy_finder) self.assertEqual(self.hit_count, 1) # Look for a different embed, hit count should increase embed = get_embed('www.test.com/4321', max_width=400, finder=self.dummy_finder) self.assertEqual(self.hit_count, 2) # Look for the same embed with a different width, this should also increase hit count embed = get_embed('www.test.com/4321', finder=self.dummy_finder) self.assertEqual(self.hit_count, 3)
def test_get_embed(self): embed = get_embed( 'www.test.com/1234', max_width=400, finder=self.dummy_finder) # Check that the embed is correct self.assertEqual(embed.title, "Test: www.test.com/1234") self.assertEqual(embed.type, 'video') self.assertEqual(embed.width, 400) # Check that there has only been one hit to the backend self.assertEqual(self.hit_count, 1) # Look for the same embed again and check the hit count hasn't increased embed = get_embed( 'www.test.com/1234', max_width=400, finder=self.dummy_finder) self.assertEqual(self.hit_count, 1) # Look for a different embed, hit count should increase embed = get_embed( 'www.test.com/4321', max_width=400, finder=self.dummy_finder) self.assertEqual(self.hit_count, 2) # Look for the same embed with a different width, this should also increase hit count embed = get_embed('www.test.com/4321', finder=self.dummy_finder) self.assertEqual(self.hit_count, 3)
def test_invalid_width(self): embed = get_embed('www.test.com/1234', max_width=400, finder=self.dummy_finder_invalid_width) # Width must be set to None self.assertEqual(embed.width, None)
def embed_to_editor_html(url): embed = get_embed(url) if embed is None: return return '<div class="embed-placeholder" contenteditable="false" data-embedtype="media" data-url="%s"><h3>%s</h3><p>%s</p><img src="%s"></div>' % ( url, escape(embed.title), url, embed.thumbnail_url)
def embed_to_editor_html(url): embed = get_embed(url) if embed is None: return # Render template return render_to_string("wagtailembeds/embed_editor.html", {"embed": embed})
def test_invalid_width(self): embed = get_embed( 'www.test.com/1234', max_width=400, finder=self.dummy_finder_invalid_width) # Width must be set to None self.assertEqual(embed.width, None)
def embed(url, max_width=None): embed = get_embed(url, max_width=max_width) try: if embed is not None: return mark_safe(embed.html) else: return '' except: return ''
def embed_to_editor_html(url): embed = get_embed(url) if embed is None: return # Render template return render_to_string('wagtailembeds/embed_editor.html', { 'embed': embed, })
def test_no_html(self) : def no_html_finder(url, max_width=None): """ A finder which returns everything but HTML """ embed = self.dummy_finder(url, max_width) embed['html'] = None return embed embed = get_embed('www.test.com/1234', max_width=400, finder=no_html_finder) self.assertEqual(embed.html, '')
def test_no_html(self): def no_html_finder(url, max_width=None): """ A finder which returns everything but HTML """ embed = self.dummy_finder(url, max_width) embed['html'] = None return embed embed = get_embed('www.test.com/1234', max_width=400, finder=no_html_finder) self.assertEqual(embed.html, '')
def embed_to_frontend_html(url): try: embed = get_embed(url) if embed is not None: # Work out ratio if embed.width and embed.height: ratio = str(embed.height / embed.width * 100) + "%" else: ratio = "0" # Build html return '<div style="padding-bottom: %s;" class="responsive-object">%s</div>' % (ratio, embed.html) else: return '' except: return ''
def embed_to_frontend_html(url): try: embed = get_embed(url) if embed is not None: # Work out ratio if embed.width and embed.height: ratio = str(embed.height / embed.width * 100) + "%" else: ratio = "0" # Render template return render_to_string("wagtailembeds/embed_frontend.html", {"embed": embed, "ratio": ratio}) else: return "" except: return ""
def embed_to_frontend_html(url): try: embed = get_embed(url) if embed is not None: # Work out ratio if embed.width and embed.height: ratio = str(embed.height / embed.width * 100) + "%" else: ratio = "0" # Render template render_to_string('wagtailembeds/embed_frontend.html', { 'embed': embed, 'ratio': ratio, }) else: return '' except: return ''
def embed_to_frontend_html(url): try: embed = get_embed(url) if embed is not None: # Work out ratio if embed.width and embed.height: ratio = str(embed.height / embed.width * 100) + "%" else: ratio = "0" # Render template return render_to_string('wagtailembeds/embed_frontend.html', { 'embed': embed, 'ratio': ratio, }) else: return '' except: return ''