Repository: wagtail/wagtail
File: wagtail/images/tests/test_models.py (Python)

Code before:

        self.assertIsNone(self.image.focal_point_x)
        self.assertIsNone(self.image.focal_point_y)
        self.assertIsNone(self.image.focal_point_width)
        self.assertIsNone(self.image.focal_point_height)

    def test_is_stored_locally(self):
        self.assertTrue(self.image.is_stored_locally())

    @override_settings(
        DEFAULT_FILE_STORAGE="wagtail.test.dummy_external_storage.DummyExternalStorage"
    )
    def test_is_stored_locally_with_external_storage(self):
        self.assertFalse(self.image.is_stored_locally())

    @override_settings(
        DEFAULT_FILE_STORAGE="wagtail.test.dummy_external_storage.DummyExternalStorage"
    )
    def test_reopen_based_on_storage_that_is_dynamically_set(self):
        self.image.file.close()
        # Simulate the case is witch the storage is set dynamically
        with mock.patch.object(
            self.image.file, "storage", AnotherDummyExternalStorage()
        ):
            with self.image.open_file() as f:
                self.assertIs(f.__class__, AnotherDummyExternalStorageFile)

    def test_get_file_size(self):
        file_size = self.image.get_file_size()
        self.assertIsInstance(file_size, int)
        self.assertGreater(file_size, 0)

    def test_get_file_size_on_missing_file_raises_sourceimageioerror(self):
        self.image.file.delete(save=False)
        with self.assertRaises(SourceImageIOError):
            self.image.get_file_size()

    def test_file_hash(self):
        self.assertEqual(
            self.image.get_file_hash(), "4dd0211870e130b7e1690d2ec53c499a54a48fef"
        )


class TestImageQuerySet(TransactionTestCase):
    fixtures = ["test_empty.json"]

    def test_search_method(self):
        # Create an image for running tests on
        image = Image.objects.create(
            title="Test image",
            file=get_test_image_file(),

Review comment (suggestion):
Nit: Use `assertIsInstance` rather than comparing the class directly
```suggestion
                self.assertIsInstance(f, AnotherDummyExternalStorageFile)
```

Code after:

    def test_set_focal_point(self):
        self.assertIsNone(self.image.focal_point_x)
        self.assertIsNone(self.image.focal_point_y)
        self.assertIsNone(self.image.focal_point_width)
        self.assertIsNone(self.image.focal_point_height)

        self.image.set_focal_point(Rect(100, 150, 200, 350))

        self.assertEqual(self.image.focal_point_x, 150)
        self.assertEqual(self.image.focal_point_y, 250)
        self.assertEqual(self.image.focal_point_width, 100)
        self.assertEqual(self.image.focal_point_height, 200)

        self.image.set_focal_point(None)

        self.assertIsNone(self.image.focal_point_x)
        self.assertIsNone(self.image.focal_point_y)
        self.assertIsNone(self.image.focal_point_width)
        self.assertIsNone(self.image.focal_point_height)

    def test_is_stored_locally(self):
        self.assertTrue(self.image.is_stored_locally())

    @override_settings(
        STORAGES={
            **settings.STORAGES,
            "default": {
                "BACKEND": "wagtail.test.dummy_external_storage.DummyExternalStorage"
            },
        },
    )
    def test_is_stored_locally_with_external_storage(self):
        self.assertFalse(self.image.is_stored_locally())

    @override_settings(
        DEFAULT_FILE_STORAGE="wagtail.test.dummy_external_storage.DummyExternalStorage"
    )
    def test_reopen_based_on_storage_that_is_dynamically_set(self):
        self.image.file.close()
        # Simulate the case is which the storage is set dynamically
        with mock.patch.object(
            self.image.file, "storage", AnotherDummyExternalStorage()
        ):
            with self.image.open_file() as file:
                self.assertIsInstance(file, AnotherDummyExternalStorageFile)

    def test_get_file_size(self):
        file_size = self.image.get_file_size()
        self.assertIsInstance(file_size, int)
        self.assertGreater(file_size, 0)