示例#1
0
 def test_opengraph_ignored_if_not_enough_attributes(self, og):
     og.return_value = {}
     result = fetch_og_preview(self.content, self.urls)
     self.assertFalse(result)
     og.return_value = {"foo": "bar"}
     result = fetch_og_preview(self.content, self.urls)
     self.assertFalse(result)
示例#2
0
 def test_opengraph_ignored_if_not_enough_attributes(self, og):
     og.return_value = {}
     result = fetch_og_preview(self.content, self.urls)
     self.assertFalse(result)
     og.return_value = {"foo": "bar"}
     result = fetch_og_preview(self.content, self.urls)
     self.assertFalse(result)
示例#3
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)
示例#4
0
 def test_opengraph_cache_created_without_image_for_nsfw_content(self, og):
     og.return_value = MockOpenGraph({"title": "foo", "image": "https://domain.tld/pic.png"})
     opengraph = fetch_og_preview(self.nsfw_content, self.urls)
     self.assertEqual(opengraph.title, "foo")
     self.assertEqual(opengraph.description, "")
     self.assertEqual(opengraph.image, "")
     self.assertEqual(opengraph.url, self.urls[0])
示例#5
0
 def test_opengraph_cache_created_without_image_for_nsfw_content(self, og):
     og.return_value = MockOpenGraph({"title": "foo", "image": "https://domain.tld/pic.png"})
     opengraph = fetch_og_preview(self.nsfw_content, self.urls)
     self.assertEqual(opengraph.title, "foo")
     self.assertEqual(opengraph.description, "")
     self.assertEqual(opengraph.image, "")
     self.assertEqual(opengraph.url, self.urls[0])
示例#6
0
 def test_opengraph_cache_created(self, og):
     og.return_value = MockOpenGraph({"title": "foo"})
     opengraph = fetch_og_preview(self.content, self.urls)
     self.assertEqual(opengraph.title, "foo")
     self.assertEqual(opengraph.description, "")
     self.assertEqual(opengraph.image, "")
     self.assertEqual(opengraph.url, self.urls[0])
示例#7
0
 def test_opengraph_cache_created(self, og):
     og.return_value = MockOpenGraph({"title": "foo"})
     opengraph = fetch_og_preview(self.content, self.urls)
     self.assertEqual(opengraph.title, "foo")
     self.assertEqual(opengraph.description, "")
     self.assertEqual(opengraph.image, "")
     self.assertEqual(opengraph.url, self.urls[0])
示例#8
0
 def test_opengraph_fetch_called(self, og):
     fetch_og_preview(self.content, self.urls)
     og.assert_called_once_with(url=self.urls[0], parser="lxml")
示例#9
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")
示例#10
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)
示例#11
0
 def test_opengraph_connection_error_is_passed(self, og):
     result = fetch_og_preview(self.content, self.urls)
     self.assertFalse(result)
示例#12
0
 def test_opengraph_data_error_is_passed(self, og, create):
     og.return_value = MockOpenGraph({"title": "foo"})
     result = fetch_og_preview(self.content, self.urls)
     self.assertFalse(result)
示例#13
0
 def test_opengraph_fetch_called(self, og):
     fetch_og_preview(self.content, self.urls)
     og.assert_called_once_with(url=self.urls[0], parser="lxml")
示例#14
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")
示例#15
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)
示例#16
0
 def test_opengraph_data_error_is_passed(self, og, create):
     og.return_value = MockOpenGraph({"title": "foo"})
     result = fetch_og_preview(self.content, self.urls)
     self.assertFalse(result)
示例#17
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)
示例#18
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)
示例#19
0
 def test_opengraph_data_cleared_before_fetching(self, og_parse):
     OpenGraph.__data__ = {"foo": "bar"}
     fetch_og_preview(self.content, self.urls)
     self.assertEqual(OpenGraph.__data__, {})