diff --git a/app/helpers/check_functions.py b/app/helpers/check_functions.py index aeaa77b..14b6553 100644 --- a/app/helpers/check_functions.py +++ b/app/helpers/check_functions.py @@ -3,7 +3,6 @@ from flask import abort -from app.helpers.description import find_descripton_file from app.icon_set import get_icon_set logger = logging.getLogger(__name__) @@ -89,19 +88,3 @@ def get_and_check_icon(icon_set, icon_name): logger.error("The icon doesn't exist: %s", path) abort(404, "Icon not found in icon set") return icon - - -def check_if_descripton_file_exists(icon_set): - """ - Checks that the icon set has a corresponding dictionary containing description for all available - languages. - if not raises a flask error and abort the current request. - - Args: - icon_set: (IconSet) the icon set of which we want to check if it has a description file - """ - # checking that the icon exists in the icon set's folder - path = find_descripton_file(icon_set) - if not os.path.isfile(path): - logger.error("The description dictionary doesn't exist: %s", path) - abort(404, "Description dictionary not found") diff --git a/app/helpers/description.py b/app/helpers/description.py index 21c17ae..a65d75b 100644 --- a/app/helpers/description.py +++ b/app/helpers/description.py @@ -9,21 +9,6 @@ logger = logging.getLogger(__name__) -def get_icon_set_description(icon_set=''): - ''' - Return json containing the description in all available languages for all icons of the - provided icon set - ''' - path = find_descripton_file(icon_set) - if not os.path.isfile(path): - return None - - with open(path, encoding='utf-8') as f: - icon_set_descriptions = json.load(f) - - return [icon_set_descriptions] - - def get_icon_description(icon_name='', icon_set=''): ''' Return json containing the description in all available languages for an icon in the specified diff --git a/app/icon_set.py b/app/icon_set.py index ffe53e9..ca93dd9 100644 --- a/app/icon_set.py +++ b/app/icon_set.py @@ -3,7 +3,6 @@ from flask import url_for from app.helpers.description import find_descripton_file -from app.helpers.description import get_icon_set_description from app.helpers.icons import get_icon_set_template_url from app.helpers.url import get_base_url from app.icon import Icon @@ -81,19 +80,6 @@ def get_icons_url(self): """ return url_for('icons_from_icon_set', icon_set_name=self.name, _external=True) - def get_icon_set_description_url(self): - """ - Generate and return the URL that will list the description in all available lanaguages - of all available icons of this icon set. - - Returns: - the URL to the description in all available languages of all icons in this icon set if - it exists, otherwise return None - """ - if find_descripton_file(self.name): - return url_for('description_from_icon_set', icon_set_name=self.name, _external=True) - return None - def get_icon(self, icon_name): """ Generate and return the URL to access the metadata of one specific icon of this icon set @@ -120,19 +106,6 @@ def get_all_icons(self): icons.append(self.get_icon(name_without_extension)) return icons - def get_description(self): - """ - Generate a dictionary containing the description in all available languages of all icons - belonging to this icon set. - - Returns: - A dictionary of all icon description in all available languages from this icon set it - it exists, otherwise return None - """ - if not self.is_valid(): - return None - return get_icon_set_description(self.name) - def serialize(self): """ As we want to add "icons_url" to the __dict__, we can't really use a json.dumps to generate @@ -148,5 +121,5 @@ def serialize(self): "colorable": self.colorable, "icons_url": self.get_icons_url(), "template_url": get_icon_set_template_url(get_base_url()), - "description_url": self.get_icon_set_description_url() + "has_description": bool(find_descripton_file(self.name)) } diff --git a/app/routes.py b/app/routes.py index 6c316c0..e256480 100644 --- a/app/routes.py +++ b/app/routes.py @@ -9,7 +9,6 @@ from app import app from app.helpers.check_functions import check_color_channels -from app.helpers.check_functions import check_if_descripton_file_exists from app.helpers.check_functions import check_scale from app.helpers.check_functions import get_and_check_icon from app.helpers.check_functions import get_and_check_icon_set @@ -65,13 +64,6 @@ def icons_from_icon_set(icon_set_name): return make_api_compliant_response(icon_set.get_all_icons()) -@app.route('/sets//description', methods=['GET']) -def description_from_icon_set(icon_set_name): - icon_set = get_and_check_icon_set(icon_set_name) - check_if_descripton_file_exists(icon_set_name) - return make_api_compliant_response(icon_set.get_description()) - - @app.route('/sets//icons/', methods=['GET']) def icon_metadata(icon_set_name, icon_name): icon_set = get_and_check_icon_set(icon_set_name) diff --git a/k import url_for b/k import url_for new file mode 100644 index 0000000..3b78e34 --- /dev/null +++ b/k import url_for @@ -0,0 +1,224 @@ +diff --git a/app/helpers/check_functions.py b/app/helpers/check_functions.py +index aeaa77b..14b6553 100644 +--- a/app/helpers/check_functions.py ++++ b/app/helpers/check_functions.py +@@ -3,7 +3,6 @@ import os +  + from flask import abort +  +-from app.helpers.description import find_descripton_file + from app.icon_set import get_icon_set +  + logger = logging.getLogger(__name__) +@@ -89,19 +88,3 @@ def get_and_check_icon(icon_set, icon_name): + logger.error("The icon doesn't exist: %s", path) + abort(404, "Icon not found in icon set") + return icon +- +- +-def check_if_descripton_file_exists(icon_set): +- """ +- Checks that the icon set has a corresponding dictionary containing description for all available +- languages. +- if not raises a flask error and abort the current request. +- +- Args: +- icon_set: (IconSet) the icon set of which we want to check if it has a description file +- """ +- # checking that the icon exists in the icon set's folder +- path = find_descripton_file(icon_set) +- if not os.path.isfile(path): +- logger.error("The description dictionary doesn't exist: %s", path) +- abort(404, "Description dictionary not found") +diff --git a/app/helpers/description.py b/app/helpers/description.py +index 21c17ae..a65d75b 100644 +--- a/app/helpers/description.py ++++ b/app/helpers/description.py +@@ -9,21 +9,6 @@ from app.settings import DESCRIPTION_FOLDER + logger = logging.getLogger(__name__) +  +  +-def get_icon_set_description(icon_set=''): +- ''' +- Return json containing the description in all available languages for all icons of the +- provided icon set +- ''' +- path = find_descripton_file(icon_set) +- if not os.path.isfile(path): +- return None +- +- with open(path, encoding='utf-8') as f: +- icon_set_descriptions = json.load(f) +- +- return [icon_set_descriptions] +- +- + def get_icon_description(icon_name='', icon_set=''): + ''' + Return json containing the description in all available languages for an icon in the specified +diff --git a/app/icon_set.py b/app/icon_set.py +index ffe53e9..ca93dd9 100644 +--- a/app/icon_set.py ++++ b/app/icon_set.py +@@ -3,7 +3,6 @@ import os + from flask import url_for +  + from app.helpers.description import find_descripton_file +-from app.helpers.description import get_icon_set_description + from app.helpers.icons import get_icon_set_template_url + from app.helpers.url import get_base_url + from app.icon import Icon +@@ -81,19 +80,6 @@ class IconSet: + """ + return url_for('icons_from_icon_set', icon_set_name=self.name, _external=True) +  +- def get_icon_set_description_url(self): +- """ +- Generate and return the URL that will list the description in all available lanaguages +- of all available icons of this icon set. +- +- Returns: +- the URL to the description in all available languages of all icons in this icon set if +- it exists, otherwise return None +- """ +- if find_descripton_file(self.name): +- return url_for('description_from_icon_set', icon_set_name=self.name, _external=True) +- return None +- + def get_icon(self, icon_name): + """ + Generate and return the URL to access the metadata of one specific icon of this icon set +@@ -120,19 +106,6 @@ class IconSet: + icons.append(self.get_icon(name_without_extension)) + return icons +  +- def get_description(self): +- """ +- Generate a dictionary containing the description in all available languages of all icons +- belonging to this icon set. +- +- Returns: +- A dictionary of all icon description in all available languages from this icon set it +- it exists, otherwise return None +- """ +- if not self.is_valid(): +- return None +- return get_icon_set_description(self.name) +- + def serialize(self): + """ + As we want to add "icons_url" to the __dict__, we can't really use a json.dumps to generate +@@ -148,5 +121,5 @@ class IconSet: + "colorable": self.colorable, + "icons_url": self.get_icons_url(), + "template_url": get_icon_set_template_url(get_base_url()), +- "description_url": self.get_icon_set_description_url() ++ "has_description": bool(find_descripton_file(self.name)) + } +diff --git a/app/routes.py b/app/routes.py +index 6c316c0..e256480 100644 +--- a/app/routes.py ++++ b/app/routes.py +@@ -9,7 +9,6 @@ from flask import make_response +  + from app import app + from app.helpers.check_functions import check_color_channels +-from app.helpers.check_functions import check_if_descripton_file_exists + from app.helpers.check_functions import check_scale + from app.helpers.check_functions import get_and_check_icon + from app.helpers.check_functions import get_and_check_icon_set +@@ -65,13 +64,6 @@ def icons_from_icon_set(icon_set_name): + return make_api_compliant_response(icon_set.get_all_icons()) +  +  +-@app.route('/sets//description', methods=['GET']) +-def description_from_icon_set(icon_set_name): +- icon_set = get_and_check_icon_set(icon_set_name) +- check_if_descripton_file_exists(icon_set_name) +- return make_api_compliant_response(icon_set.get_description()) +- +- + @app.route('/sets//icons/', methods=['GET']) + def icon_metadata(icon_set_name, icon_name): + icon_set = get_and_check_icon_set(icon_set_name) +diff --git a/tests/unit_tests/test_all_icons.py b/tests/unit_tests/test_all_icons.py +index 0ca3846..b0f03f8 100644 +--- a/tests/unit_tests/test_all_icons.py ++++ b/tests/unit_tests/test_all_icons.py +@@ -191,12 +191,7 @@ class AllIconsTest(ServiceIconsUnitTests): + self.assertIn('name', icon_set_metadata) + self.assertEqual(icon_set_name, icon_set_metadata['name']) + self.assertIn('colorable', icon_set_metadata) +- self.assertIn('description_url', icon_set_metadata) +- if icon_set_metadata['description_url']: +- r = self.app.get( +- icon_set_metadata['description_url'], headers=self.default_header +- ) +- self.assertEqual(r.status_code, 200) ++ self.assertIn('has_description', icon_set_metadata) + self.assertIn('icons_url', icon_set_metadata) + self.assertIsNotNone(icon_set_metadata['icons_url']) + self.assertEqual( +diff --git a/tests/unit_tests/test_description.py b/tests/unit_tests/test_description.py +index 54751ef..859478c 100644 +--- a/tests/unit_tests/test_description.py ++++ b/tests/unit_tests/test_description.py +@@ -1,8 +1,6 @@ + import json + import os +  +-from flask import url_for +- + from app.settings import DESCRIPTION_FOLDER + from tests.unit_tests.base_test import ServiceIconsUnitTests +  +@@ -28,30 +26,3 @@ class IconsTests(ServiceIconsUnitTests): + self.assertTrue( + validate_json(json_file), "validation failed of json file: " + file + ) +- +- def test_get_icon_set_description_valid(self): +- response = self.app.get( +- url_for( +- 'description_from_icon_set', +- icon_set_name='babs-I', +- ), +- headers={"Origin": 'www.example.com'} +- ) +- self.assertEqual(response.status_code, 200) +- +- def test_get_icon_set_description_invalid(self): +- response = self.app.get( +- url_for( +- 'description_from_icon_set', +- icon_set_name='default', +- ), +- headers={"Origin": 'www.example.com'} +- ) +- self.assertEqual( +- response.json, { +- "error": { +- "code": 404, "message": "Description dictionary not found" +- }, +- "success": False +- } +- ) +diff --git a/tests/unit_tests/test_endpoints_compliance.py b/tests/unit_tests/test_endpoints_compliance.py +index ac54da3..0f7e97c 100644 +--- a/tests/unit_tests/test_endpoints_compliance.py ++++ b/tests/unit_tests/test_endpoints_compliance.py +@@ -37,14 +37,6 @@ class CheckerTests(ServiceIconsUnitTests): + ) + ) +  +- def test_icon_set_description(self): +- self.check_response_compliance( +- self.app.get( +- url_for('description_from_icon_set', icon_set_name='babs-I'), +- headers=self.default_header +- ) +- ) +- + def test_icons_list(self): + self.check_response_compliance( + self.app.get( diff --git a/tests/unit_tests/test_all_icons.py b/tests/unit_tests/test_all_icons.py index 0ca3846..b0f03f8 100644 --- a/tests/unit_tests/test_all_icons.py +++ b/tests/unit_tests/test_all_icons.py @@ -191,12 +191,7 @@ def test_all_icon_sets_metadata_endpoint(self): self.assertIn('name', icon_set_metadata) self.assertEqual(icon_set_name, icon_set_metadata['name']) self.assertIn('colorable', icon_set_metadata) - self.assertIn('description_url', icon_set_metadata) - if icon_set_metadata['description_url']: - r = self.app.get( - icon_set_metadata['description_url'], headers=self.default_header - ) - self.assertEqual(r.status_code, 200) + self.assertIn('has_description', icon_set_metadata) self.assertIn('icons_url', icon_set_metadata) self.assertIsNotNone(icon_set_metadata['icons_url']) self.assertEqual( diff --git a/tests/unit_tests/test_description.py b/tests/unit_tests/test_description.py index 54751ef..859478c 100644 --- a/tests/unit_tests/test_description.py +++ b/tests/unit_tests/test_description.py @@ -1,8 +1,6 @@ import json import os -from flask import url_for - from app.settings import DESCRIPTION_FOLDER from tests.unit_tests.base_test import ServiceIconsUnitTests @@ -28,30 +26,3 @@ def test_validate_json_description_files(self): self.assertTrue( validate_json(json_file), "validation failed of json file: " + file ) - - def test_get_icon_set_description_valid(self): - response = self.app.get( - url_for( - 'description_from_icon_set', - icon_set_name='babs-I', - ), - headers={"Origin": 'www.example.com'} - ) - self.assertEqual(response.status_code, 200) - - def test_get_icon_set_description_invalid(self): - response = self.app.get( - url_for( - 'description_from_icon_set', - icon_set_name='default', - ), - headers={"Origin": 'www.example.com'} - ) - self.assertEqual( - response.json, { - "error": { - "code": 404, "message": "Description dictionary not found" - }, - "success": False - } - ) diff --git a/tests/unit_tests/test_endpoints_compliance.py b/tests/unit_tests/test_endpoints_compliance.py index ac54da3..0f7e97c 100644 --- a/tests/unit_tests/test_endpoints_compliance.py +++ b/tests/unit_tests/test_endpoints_compliance.py @@ -37,14 +37,6 @@ def test_icon_set_metadata(self): ) ) - def test_icon_set_description(self): - self.check_response_compliance( - self.app.get( - url_for('description_from_icon_set', icon_set_name='babs-I'), - headers=self.default_header - ) - ) - def test_icons_list(self): self.check_response_compliance( self.app.get(