示例#1
0
 def test_renders_with_opengraphcache(self):
     content = Content.objects.create(
         text="foobar", guid="barfoo", author=ProfileFactory(),
         opengraph=OpenGraphCacheFactory()
     )
     rendered_og = render_to_string("content/_og_preview.html", {"opengraph": content.opengraph})
     self.assertEqual(content.rendered, "<p>foobar</p>%s" % rendered_og)
示例#2
0
 def test_if_cached_already_dont_fetch(self):
     with freeze_time(datetime.date.today() - datetime.timedelta(days=3)):
         opengraph = OpenGraphCacheFactory(url=self.urls[0])
     result = fetch_og_preview(self.content, self.urls)
     self.assertTrue(result)
     self.content.refresh_from_db()
     self.assertEqual(self.content.opengraph, opengraph)
示例#3
0
 def test_renders_without_previews_with_show_preview_false(self):
     content = Content.objects.create(
         text="foobar", guid="barfoo", author=ProfileFactory(),
         oembed=OEmbedCacheFactory(), opengraph=OpenGraphCacheFactory(),
         show_preview=False,
     )
     self.assertEqual(content.rendered, "<p>foobar</p>")
示例#4
0
 def test_renders_without_previews_with_show_preview_false(self):
     content = ContentFactory(
         text="foobar",
         oembed=OEmbedCacheFactory(),
         opengraph=OpenGraphCacheFactory(),
         show_preview=False,
     )
     self.assertEqual(content.rendered, "<p>foobar</p>")
示例#5
0
 def test_renders_with_opengraphcache(self):
     content = ContentFactory(text="foobar",
                              opengraph=OpenGraphCacheFactory())
     rendered_og = render_to_string("content/_og_preview.html",
                                    {"opengraph": content.opengraph})
     self.assertEqual(content.rendered, "<p>foobar</p>%s" % rendered_og)
示例#6
0
 def test_opengraph_integrity_error_updates_with_existing_object(
         self, og, filter):
     opengraph = OpenGraphCacheFactory(url=self.urls[0])
     og.return_value = MockOpenGraph({"title": "foo"})
     result = fetch_og_preview(self.content, self.urls)
     self.assertEqual(opengraph, result)
示例#7
0
 def test_if_cached_already_but_older_than_7_days_then_fetch(self, og):
     with freeze_time(datetime.date.today() - datetime.timedelta(days=8)):
         OpenGraphCacheFactory(url=self.urls[0])
     fetch_og_preview(self.content, self.urls)
     og.assert_called_once_with(url=self.urls[0], parser="lxml")
示例#8
0
 def test_if_cached_already_dont_fetch(self):
     opengraph = OpenGraphCacheFactory(url=self.urls[0])
     result = fetch_og_preview(self.content, self.urls)
     self.assertTrue(result)
     self.content.refresh_from_db()
     self.assertEqual(self.content.opengraph, opengraph)