Skip to content

Commit

Permalink
Add tests to cover focal point change detection
Browse files Browse the repository at this point in the history
  • Loading branch information
ababic committed Apr 24, 2024
1 parent 540a8e1 commit f29855d
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def test_update_from_asset_data(self):
self.obj.is_archived = None
self.obj.is_limited_use = None
self.obj.is_public = None
self.assertIsNone(self.obj.get_focal_point())

with (
mock.patch(
Expand All @@ -217,7 +218,53 @@ def test_update_from_asset_data(self):
self.assertEqual(self.obj.focal_point_y, 13)
self.assertEqual(self.obj.focal_point_height, 26)
self.assertEqual(self.obj.focal_point_width, 26)
self.assertTrue(self.obj._focal_point_changed)

def test_update_from_asset_data_with_focal_point_change(self):
# First, let's set the focal point values to something semi-realistic
self.obj.focal_point_x = 20
self.obj.focal_point_y = 20
self.obj.focal_point_height = 20
self.obj.focal_point_width = 20

current_focal_point = self.obj.get_focal_point()

# Calling update_from_asset_data() should result in a change to these values
with (
mock.patch(
"wagtail_bynder.models.utils.get_default_collection", return_value=None
),
mock.patch.object(self.obj, "update_file"),
):
self.obj.update_from_asset_data(self.asset_data)


new_focal_point = self.obj.get_focal_point()
self.assertNotEqual(new_focal_point, current_focal_point)
self.assertTrue(self.obj._focal_point_changed)

def test_update_from_asset_data_without_focal_point_change(self):
# Set the focal point values to reflect the typical test outcome
self.obj.focal_point_x = 13
self.obj.focal_point_y = 13
self.obj.focal_point_height = 26
self.obj.focal_point_width = 26

current_focal_point = self.obj.get_focal_point()

# Calling update_from_asset_data() should result in no change to these values
with (
mock.patch(
"wagtail_bynder.models.utils.get_default_collection", return_value=None
),
mock.patch.object(self.obj, "update_file"),
):
self.obj.update_from_asset_data(self.asset_data)


new_focal_point = self.obj.get_focal_point()
self.assertEqual(new_focal_point, current_focal_point)
self.assertFalse(self.obj._focal_point_changed)

class BynderSyncedVideoTests(SimpleTestCase):
def setUp(self):
Expand Down

0 comments on commit f29855d

Please sign in to comment.