Repository: wagtail/wagtail
File: wagtail/embeds/tests/test_embeds.py (Python)

Code before:
        self.assertEqual(finders[0].app_id, "1234567890")
        self.assertEqual(finders[0].app_secret, "abcdefghijklmnop")
        # omitscript defaults to False
        self.assertIs(finders[0].omitscript, False)


class TestEmbeds(TestCase):
    def setUp(self):
        self.hit_count = 0

    def dummy_finder(self, url, max_width=None, max_height=None):
        # Up hit count
        self.hit_count += 1

        # Return a pretend record
        return {
            "title": "Test: " + url,
            "type": "video",
            "width": max_width if max_width else 640,
            "height": 480,
            "html": "<p>Blah blah blah</p>",
        }

    @override_settings(WAGTAILEMBEDS_RESPONSIVE_HTML=True)
    def test_get_embed_responsive(self):
        # Instead of patching just get_embed, we need to patch get_finders
        with patch("wagtail.embeds.embeds.get_finders") as get_finders_mock:
            # Configure get_finders to return our dummy finder properly
            dummy_finder = DummyFinder(self.dummy_finder)
            get_finders_mock.return_value = [dummy_finder]

            embed = get_embed("www.test.com/1234", max_width=400)

        # Check that the embed is correct
        self.assertEqual(embed.title, "Test: www.test.com/1234")
        self.assertEqual(embed.type, "video")
        self.assertEqual(embed.width, 400)
        self.assertEqual(embed.thumbnail_url, "")

        # Check ratio calculations
        self.assertEqual(embed.ratio, 480 / 400)
        self.assertEqual(embed.ratio_css, "120.0%")
        self.assertTrue(embed.is_responsive)

        # Check that there has only been one hit to the backend
        self.assertEqual(self.hit_count, 1)

        # Look for the same embed again and check the hit count hasn't increased
        with patch("wagtail.embeds.embeds.get_finders") as get_finders_mock:
            get_finders_mock.return_value = [DummyFinder(self.dummy_finder)]
            get_embed("www.test.com/1234", max_width=400)

Review comment (suggestion):
```suggestion
```

No need to add comments like this, thanks though.

Code after:
        self.assertEqual(finders[0].app_id, "1234567890")
        self.assertEqual(finders[0].app_secret, "abcdefghijklmnop")
        # omitscript defaults to False
        self.assertIs(finders[0].omitscript, False)


class TestEmbeds(TestCase):
    def setUp(self):
        self.hit_count = 0

    def dummy_finder(self, url, max_width=None, max_height=None):
        # Up hit count
        self.hit_count += 1

        # Return a pretend record
        return {
            "title": "Test: " + url,
            "type": "video",
            "width": max_width if max_width else 640,
            "height": 480,
            "html": "<p>Blah blah blah</p>",
        }

    @override_settings(WAGTAILEMBEDS_RESPONSIVE_HTML=True)
    def test_get_embed_responsive(self):
        with patch("wagtail.embeds.embeds.get_finders") as get_finders_mock:
            # Configure get_finders to return our dummy finder properly
            dummy_finder = DummyFinder(self.dummy_finder)
            get_finders_mock.return_value = [dummy_finder]

            embed = get_embed("www.test.com/1234", max_width=400)

        # Check that the embed is correct
        self.assertEqual(embed.title, "Test: www.test.com/1234")
        self.assertEqual(embed.type, "video")
        self.assertEqual(embed.width, 400)
        self.assertEqual(embed.thumbnail_url, "")

        # Check ratio calculations
        self.assertEqual(embed.ratio, 480 / 400)
        self.assertEqual(embed.ratio_css, "120.0%")
        self.assertTrue(embed.is_responsive)

        # Check that there has only been one hit to the backend
        self.assertEqual(self.hit_count, 1)

        # Look for the same embed again and check the hit count hasn't increased
        with patch("wagtail.embeds.embeds.get_finders") as get_finders_mock:
            get_finders_mock.return_value = [DummyFinder(self.dummy_finder)]
            get_embed("www.test.com/1234", max_width=400)
        self.assertEqual(self.hit_count, 1)