Skip to content

Commit

Permalink
PB-227: Added tests for babs2 helptext
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasJoss committed Jan 22, 2024
1 parent cb5eae1 commit 8fc110f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
6 changes: 3 additions & 3 deletions app/helpers/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
def get_icon_set_translation(icon_set=''):
path = os.path.abspath(os.path.join(JSON_FOLDER, icon_set + '_dictionary.json'))
if(not(os.path.isfile(path))):
return "false"
else: return "true"
return False
else: return True

def get_icon_translation(icon_name='', icon_set=''):
path = os.path.abspath(os.path.join(JSON_FOLDER, icon_set + '_dictionary.json'))
if(not(os.path.isfile(path))):
return "false"
return False

with open(path) as f:
df = json.load(f)
Expand Down
18 changes: 0 additions & 18 deletions tests/unit_tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,6 @@ def request_colorized_icon(
headers={"Origin": origin}
)

def request_titled_icon(
self,
icon_name="001-D-Beschaedigung",
scale='1x',
icon_category="babs2",
# see .env.test
origin=ORIGIN_FOR_TESTING
):
return self.app.get(
url_for(
'icon_metadata',
icon_set_name=icon_category,
icon_name=icon_name,
scale=scale
),
headers=self.default_header
)

def check_response_not_allowed(self, response, msg, is_checker=False):
self.assertEqual(response.status_code, 403, msg=msg)
if not is_checker:
Expand Down
5 changes: 5 additions & 0 deletions tests/unit_tests/test_all_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ def test_all_icon_metadata_endpoint(self):
json_response = response.json
self.assertIn('icon_set', json_response)
self.assertEqual(icon_set_name, json_response['icon_set'])
self.assertIn('title', json_response)
if(json_response['title']):
self.assertIn('de', json_response['title'])
self.assertIn('fr', json_response['title'])
self.assertIn('it', json_response['title'])
self.assertIn('name', json_response)
self.assertEqual(icon_name, json_response['name'])
self.assertIn('template_url', json_response)
Expand Down
27 changes: 27 additions & 0 deletions tests/unit_tests/test_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import json
import os

from tests.unit_tests.base_test import ServiceIconsUnitTests

from app.settings import JSON_FOLDER

def validateJSON(jsonData):
try:
json.loads(jsonData)
except ValueError as err:
return False
return True

class IconsTests(ServiceIconsUnitTests):

def test_json(self):
path = os.path.abspath(os.path.join(JSON_FOLDER, 'babs2_dictionary.json'))
self.assertTrue(os.path.exists(path),"babs2 json file doesn't exist")

for root, dirs, files in os.walk(os.path.join(JSON_FOLDER)):
for name in files:
p = os.path.join(root, name)
with open(p) as f:
json_file = f.read()
self.assertTrue(validateJSON(json_file),"json file validation failed")

0 comments on commit 8fc110f

Please sign in to comment.