Skip to content

Commit

Permalink
PB-63: Update tests to not fail on non square babs icons
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasJoss committed Aug 23, 2024
1 parent 650a95f commit 59db179
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 17 additions & 12 deletions tests/unit_tests/test_all_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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.
Expand All @@ -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}"
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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):
"""
Expand All @@ -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):
"""
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 59db179

Please sign in to comment.