Example #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)
Example #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)
Example #3
0
 def test_pyembed_called(self, embed):
     fetch_oembed_preview(self.content, self.urls)
     embed.assert_called_once_with(self.urls[0])
Example #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)
Example #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])
Example #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)
Example #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")
Example #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')
Example #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)
Example #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)
Example #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)
Example #12
0
 def test_pyembed_called(self, embed):
     fetch_oembed_preview(self.content, self.urls)
     embed.assert_called_once_with(self.urls[0])
Example #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])
Example #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)
Example #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)
Example #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)
Example #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')
Example #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")
Example #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)
Example #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")