Пример #1
0
 def test_pyembed_errors_swallowed(self):
     for error in [
             PyEmbedError, PyEmbedDiscoveryError, PyEmbedConsumerError,
             ValueError
     ]:
         with patch("socialhome.content.previews.PyEmbed.embed",
                    side_effect=error):
             result = fetch_oembed_preview(self.content, self.urls)
             self.assertFalse(result)
Пример #2
0
 def test_skips_twitter_profile_stream_oembeds(self, embed):
     fetch_oembed_preview(self.content, ["https://twitter.com/foobar"])
     self.assertFalse(embed.called)
     self.content.refresh_from_db()
     self.assertIsNone(self.content.oembed)
Пример #3
0
 def test_pyembed_called(self, embed):
     fetch_oembed_preview(self.content, self.urls)
     embed.assert_called_once_with(self.urls[0])
Пример #4
0
 def test_cache_not_updated_if_previous_found(self):
     OEmbedCacheFactory(url=self.urls[0])
     result = fetch_oembed_preview(self.content, self.urls)
     self.content.refresh_from_db()
     self.assertEqual(self.content.oembed, result)
Пример #5
0
 def test_cache_updated_if_previous_found_older_than_7_days(self, embed):
     with freeze_time(datetime.date.today() - datetime.timedelta(days=8)):
         OEmbedCacheFactory(url=self.urls[0])
     fetch_oembed_preview(self.content, self.urls)
     embed.assert_called_once_with(self.urls[0])
Пример #6
0
 def test_oembed_cache_created(self, embed):
     result = fetch_oembed_preview(self.content, self.urls)
     self.assertEqual(result.oembed, "foobar")
     self.content.refresh_from_db()
     self.assertEqual(self.content.oembed, result)
Пример #7
0
 def test_adds_dnt_flag_to_twitter_oembed(self, embed):
     fetch_oembed_preview(self.content, ["https://twitter.com/foobar"])
     embed.assert_called_once_with("https://twitter.com/foobar", dnt="true", omit_script="true")
Пример #8
0
 def test_oembed_width_corrected(self, embed):
     result = fetch_oembed_preview(self.content, self.urls)
     self.assertEqual(result.oembed, 'foo width="100%"  bar')
Пример #9
0
 def test_oembed_cache_created(self, embed):
     result = fetch_oembed_preview(self.content, self.urls)
     self.assertEqual(result.oembed, "foobar")
     self.content.refresh_from_db()
     self.assertEqual(self.content.oembed, result)
Пример #10
0
 def test_pyembed_errors_swallowed(self):
     for error in [PyEmbedError, PyEmbedDiscoveryError, PyEmbedConsumerError, ValueError]:
         with patch("socialhome.content.previews.PyEmbed.embed", side_effect=error):
             result = fetch_oembed_preview(self.content, self.urls)
             self.assertFalse(result)
Пример #11
0
 def test_empty_oembed_skipped(self, embed):
     result = fetch_oembed_preview(self.content, self.urls)
     embed.assert_called_once_with(self.urls[0])
     self.assertFalse(result)
Пример #12
0
 def test_pyembed_called(self, embed):
     fetch_oembed_preview(self.content, self.urls)
     embed.assert_called_once_with(self.urls[0])
Пример #13
0
 def test_cache_updated_if_previous_found_older_than_7_days(self, embed):
     with freeze_time(datetime.date.today() - datetime.timedelta(days=8)):
         OEmbedCacheFactory(url=self.urls[0])
     fetch_oembed_preview(self.content, self.urls)
     embed.assert_called_once_with(self.urls[0])
Пример #14
0
 def test_cache_not_updated_if_previous_found(self):
     OEmbedCacheFactory(url=self.urls[0])
     result = fetch_oembed_preview(self.content, self.urls)
     self.content.refresh_from_db()
     self.assertEqual(self.content.oembed, result)
Пример #15
0
 def test_empty_oembed_skipped(self, embed):
     result = fetch_oembed_preview(self.content, self.urls)
     embed.assert_called_once_with(self.urls[0])
     self.assertFalse(result)
Пример #16
0
 def test_integrityerror_updates_with_found_cache(self, embed, filter):
     oembed = OEmbedCacheFactory(url=self.urls[0])
     result = fetch_oembed_preview(self.content, self.urls)
     self.assertEqual(result, oembed)
Пример #17
0
 def test_oembed_width_corrected(self, embed):
     result = fetch_oembed_preview(self.content, self.urls)
     self.assertEqual(result.oembed, 'foo width="100%"  bar')
Пример #18
0
 def test_adds_dnt_flag_to_twitter_oembed(self, embed):
     fetch_oembed_preview(self.content,
                          ["https://twitter.com/foobar/12345"])
     embed.assert_called_once_with("https://twitter.com/foobar/12345",
                                   dnt="true",
                                   omit_script="true")
Пример #19
0
 def test_integrityerror_updates_with_found_cache(self, embed, filter):
     oembed = OEmbedCacheFactory(url=self.urls[0])
     result = fetch_oembed_preview(self.content, self.urls)
     self.assertEqual(result, oembed)
Пример #20
0
 def test_adds_dnt_flag_to_twitter_oembed(self, embed):
     result = fetch_oembed_preview(self.content,
                                   ["https://twitter.com/foobar"])
     embed.assert_called_once_with("https://twitter.com/foobar", dnt="true")