Skip to content

Commit 8c716f4

Browse files
committed
Add test for locale-independent sidebar image ratio formatting
1 parent 66ca5d8 commit 8c716f4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/test_admin.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,22 @@ def test_file_icon_with_size(self):
19351935
self.assertNotIn('sidebar_image_ratio', context.keys())
19361936
self.assertIn('download_url', context.keys())
19371937

1938+
def test_sidebar_image_ratio_format(self):
1939+
"""
1940+
Test that sidebar_image_ratio is formatted as a string with 6 decimal places
1941+
to ensure consistent formatting regardless of locale settings
1942+
"""
1943+
image = Image.objects.create(name='test.jpg')
1944+
image._width = 100
1945+
image._height = 200
1946+
image.save()
1947+
context = {}
1948+
height, width, context = get_aspect_ratio_and_download_url(context=context, detail=True, file=image, height=40, width=40)
1949+
self.assertIsInstance(context['sidebar_image_ratio'], str)
1950+
expected_ratio = '%.6F' % (image.width / 210)
1951+
self.assertEqual(context['sidebar_image_ratio'], expected_ratio)
1952+
self.assertEqual(context['sidebar_image_ratio'], '0.476190')
1953+
19381954

19391955
class AdditionalAdminFormsTests(TestCase):
19401956
def setUp(self):

0 commit comments

Comments
 (0)