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)
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)
def test_pyembed_called(self, embed): fetch_oembed_preview(self.content, self.urls) embed.assert_called_once_with(self.urls[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)
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])
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)
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")
def test_oembed_width_corrected(self, embed): result = fetch_oembed_preview(self.content, self.urls) self.assertEqual(result.oembed, 'foo width="100%" bar')
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)
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)
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)
def test_pyembed_called(self, embed): fetch_oembed_preview(self.content, self.urls) embed.assert_called_once_with(self.urls[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])
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)
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)
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)
def test_oembed_width_corrected(self, embed): result = fetch_oembed_preview(self.content, self.urls) self.assertEqual(result.oembed, 'foo width="100%" bar')
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")
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)
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")