From 59db179fa1ec745ff09035fb4186dfe2fe60d364 Mon Sep 17 00:00:00 2001 From: Lukas Joss Date: Fri, 23 Aug 2024 15:01:21 +0200 Subject: [PATCH] PB-63: Update tests to not fail on non square babs icons --- app/settings.py | 1 + tests/unit_tests/test_all_icons.py | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/settings.py b/app/settings.py index 4d90c9d..075040e 100644 --- a/app/settings.py +++ b/app/settings.py @@ -13,6 +13,7 @@ COLORABLE_ICON_SETS = ['default'] DEFAULT_COLOR = {"r": '255', "g": '0', "b": '0'} +NON_SQUARE_ICON_SETS = ['babs-D', 'babs-I', 'babs-F'] TRAP_HTTP_EXCEPTIONS = True LOGS_DIR = os.getenv('LOGS_DIR', str(BASE_DIR / 'logs')) os.environ['LOGS_DIR'] = LOGS_DIR # Set default if not set diff --git a/tests/unit_tests/test_all_icons.py b/tests/unit_tests/test_all_icons.py index 0fd8bdd..f6368fd 100644 --- a/tests/unit_tests/test_all_icons.py +++ b/tests/unit_tests/test_all_icons.py @@ -12,6 +12,7 @@ from app.icon_set import get_icon_set from app.settings import COLORABLE_ICON_SETS from app.settings import IMAGE_FOLDER +from app.settings import NON_SQUARE_ICON_SETS from tests.unit_tests.base_test import ServiceIconsUnitTests @@ -66,7 +67,7 @@ def setUp(self): self.all_icon_sets[icon_set_name].append(icon_name) def check_image( - self, icon_name, image_url, expected_size=48, check_color=False, red=255, green=0, blue=0 + self, icon_name, icon_set_name, image_url, expected_size=48, check_color=False, red=255, green=0, blue=0 ): """ Retrieve an icon from the test instance and check everything related to this icon. @@ -84,14 +85,15 @@ def check_image( self.assertIn('max-age=', response.headers['Cache-Control']) # reading the icon image so that we can check its size in px and average color with Image.open(io.BytesIO(response.data)) as icon: - width, height = icon.size - self.assertEqual( - width, - height, - msg=f"Icons should be squares (wrong size of {width}px/{height}px" - f" for icon : {icon_name})" - ) - self.assertEqual(width, expected_size) + if(icon_set_name not in NON_SQUARE_ICON_SETS): + width, height = icon.size + self.assertEqual( + width, + height, + msg=f"Icons should be squares (wrong size of {width}px/{height}px" + f" for icon : {icon_name})" + ) + self.assertEqual(width, expected_size) if check_color: average_color = get_average_color(icon) error_message = f"Color mismatch for icon {icon_name}" @@ -271,7 +273,7 @@ def test_all_icon_basic_image(self): icon_url = url_for( 'colorized_icon', icon_set_name=icon_set_name, icon_name=icon_name ) - self.check_image(icon_name, icon_url) + self.check_image(icon_name, icon_set_name, icon_url) def test_all_icon_double_size(self): """ @@ -283,7 +285,7 @@ def test_all_icon_double_size(self): double_size_icon_url = url_for( 'colorized_icon', icon_set_name=icon_set_name, icon_name=icon_name, scale=2 ) - self.check_image(icon_name, double_size_icon_url, expected_size=96) + self.check_image(icon_name, icon_set_name, double_size_icon_url, expected_size=96) def test_all_icon_half_size(self): """ @@ -298,7 +300,7 @@ def test_all_icon_half_size(self): icon_name=icon_name, scale='0.5x' ) - self.check_image(icon_name, half_size_icon_url, expected_size=24) + self.check_image(icon_name, icon_set_name, half_size_icon_url, expected_size=24) def test_all_icons_colorized(self): """ @@ -316,6 +318,7 @@ def test_all_icons_colorized(self): colored_url = url_for('colorized_icon', **url_params) self.check_image( icon_name, + icon_set_name, colored_url, check_color=icon_set.colorable, red=0, @@ -341,6 +344,7 @@ def test_all_icons_colorized_and_double_size(self): colored_url = url_for('colorized_icon', **url_params) self.check_image( icon_name, + icon_set_name, colored_url, check_color=icon_set.colorable, expected_size=96, @@ -367,6 +371,7 @@ def test_all_icons_colorized_and_half_size(self): colored_url = url_for('colorized_icon', **url_params) self.check_image( icon_name, + icon_set_name, colored_url, check_color=icon_set.colorable, expected_size=24,