generated from geoadmin/template-service-flask
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
226 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
[1mdiff --git a/app/helpers/check_functions.py b/app/helpers/check_functions.py[m | ||
[1mindex aeaa77b..14b6553 100644[m | ||
[1m--- a/app/helpers/check_functions.py[m | ||
[1m+++ b/app/helpers/check_functions.py[m | ||
[36m@@ -3,7 +3,6 @@[m [mimport os[m | ||
[m | ||
from flask import abort[m | ||
[m | ||
[31m-from app.helpers.description import find_descripton_file[m | ||
from app.icon_set import get_icon_set[m | ||
[m | ||
logger = logging.getLogger(__name__)[m | ||
[36m@@ -89,19 +88,3 @@[m [mdef get_and_check_icon(icon_set, icon_name):[m | ||
logger.error("The icon doesn't exist: %s", path)[m | ||
abort(404, "Icon not found in icon set")[m | ||
return icon[m | ||
[31m-[m | ||
[31m-[m | ||
[31m-def check_if_descripton_file_exists(icon_set):[m | ||
[31m- """[m | ||
[31m- Checks that the icon set has a corresponding dictionary containing description for all available[m | ||
[31m- languages.[m | ||
[31m- if not raises a flask error and abort the current request.[m | ||
[31m-[m | ||
[31m- Args:[m | ||
[31m- icon_set: (IconSet) the icon set of which we want to check if it has a description file[m | ||
[31m- """[m | ||
[31m- # checking that the icon exists in the icon set's folder[m | ||
[31m- path = find_descripton_file(icon_set)[m | ||
[31m- if not os.path.isfile(path):[m | ||
[31m- logger.error("The description dictionary doesn't exist: %s", path)[m | ||
[31m- abort(404, "Description dictionary not found")[m | ||
[1mdiff --git a/app/helpers/description.py b/app/helpers/description.py[m | ||
[1mindex 21c17ae..a65d75b 100644[m | ||
[1m--- a/app/helpers/description.py[m | ||
[1m+++ b/app/helpers/description.py[m | ||
[36m@@ -9,21 +9,6 @@[m [mfrom app.settings import DESCRIPTION_FOLDER[m | ||
logger = logging.getLogger(__name__)[m | ||
[m | ||
[m | ||
[31m-def get_icon_set_description(icon_set=''):[m | ||
[31m- '''[m | ||
[31m- Return json containing the description in all available languages for all icons of the[m | ||
[31m- provided icon set[m | ||
[31m- '''[m | ||
[31m- path = find_descripton_file(icon_set)[m | ||
[31m- if not os.path.isfile(path):[m | ||
[31m- return None[m | ||
[31m-[m | ||
[31m- with open(path, encoding='utf-8') as f:[m | ||
[31m- icon_set_descriptions = json.load(f)[m | ||
[31m-[m | ||
[31m- return [icon_set_descriptions][m | ||
[31m-[m | ||
[31m-[m | ||
def get_icon_description(icon_name='', icon_set=''):[m | ||
'''[m | ||
Return json containing the description in all available languages for an icon in the specified[m | ||
[1mdiff --git a/app/icon_set.py b/app/icon_set.py[m | ||
[1mindex ffe53e9..ca93dd9 100644[m | ||
[1m--- a/app/icon_set.py[m | ||
[1m+++ b/app/icon_set.py[m | ||
[36m@@ -3,7 +3,6 @@[m [mimport os[m | ||
from flask import url_for[m | ||
[m | ||
from app.helpers.description import find_descripton_file[m | ||
[31m-from app.helpers.description import get_icon_set_description[m | ||
from app.helpers.icons import get_icon_set_template_url[m | ||
from app.helpers.url import get_base_url[m | ||
from app.icon import Icon[m | ||
[36m@@ -81,19 +80,6 @@[m [mclass IconSet:[m | ||
"""[m | ||
return url_for('icons_from_icon_set', icon_set_name=self.name, _external=True)[m | ||
[m | ||
[31m- def get_icon_set_description_url(self):[m | ||
[31m- """[m | ||
[31m- Generate and return the URL that will list the description in all available lanaguages[m | ||
[31m- of all available icons of this icon set.[m | ||
[31m-[m | ||
[31m- Returns:[m | ||
[31m- the URL to the description in all available languages of all icons in this icon set if[m | ||
[31m- it exists, otherwise return None[m | ||
[31m- """[m | ||
[31m- if find_descripton_file(self.name):[m | ||
[31m- return url_for('description_from_icon_set', icon_set_name=self.name, _external=True)[m | ||
[31m- return None[m | ||
[31m-[m | ||
def get_icon(self, icon_name):[m | ||
"""[m | ||
Generate and return the URL to access the metadata of one specific icon of this icon set[m | ||
[36m@@ -120,19 +106,6 @@[m [mclass IconSet:[m | ||
icons.append(self.get_icon(name_without_extension))[m | ||
return icons[m | ||
[m | ||
[31m- def get_description(self):[m | ||
[31m- """[m | ||
[31m- Generate a dictionary containing the description in all available languages of all icons[m | ||
[31m- belonging to this icon set.[m | ||
[31m-[m | ||
[31m- Returns:[m | ||
[31m- A dictionary of all icon description in all available languages from this icon set it[m | ||
[31m- it exists, otherwise return None[m | ||
[31m- """[m | ||
[31m- if not self.is_valid():[m | ||
[31m- return None[m | ||
[31m- return get_icon_set_description(self.name)[m | ||
[31m-[m | ||
def serialize(self):[m | ||
"""[m | ||
As we want to add "icons_url" to the __dict__, we can't really use a json.dumps to generate[m | ||
[36m@@ -148,5 +121,5 @@[m [mclass IconSet:[m | ||
"colorable": self.colorable,[m | ||
"icons_url": self.get_icons_url(),[m | ||
"template_url": get_icon_set_template_url(get_base_url()),[m | ||
[31m- "description_url": self.get_icon_set_description_url()[m | ||
[32m+[m[32m "has_description": bool(find_descripton_file(self.name))[m | ||
}[m | ||
[1mdiff --git a/app/routes.py b/app/routes.py[m | ||
[1mindex 6c316c0..e256480 100644[m | ||
[1m--- a/app/routes.py[m | ||
[1m+++ b/app/routes.py[m | ||
[36m@@ -9,7 +9,6 @@[m [mfrom flask import make_response[m | ||
[m | ||
from app import app[m | ||
from app.helpers.check_functions import check_color_channels[m | ||
[31m-from app.helpers.check_functions import check_if_descripton_file_exists[m | ||
from app.helpers.check_functions import check_scale[m | ||
from app.helpers.check_functions import get_and_check_icon[m | ||
from app.helpers.check_functions import get_and_check_icon_set[m | ||
[36m@@ -65,13 +64,6 @@[m [mdef icons_from_icon_set(icon_set_name):[m | ||
return make_api_compliant_response(icon_set.get_all_icons())[m | ||
[m | ||
[m | ||
[[email protected]('/sets/<string:icon_set_name>/description', methods=['GET'])[m | ||
[31m-def description_from_icon_set(icon_set_name):[m | ||
[31m- icon_set = get_and_check_icon_set(icon_set_name)[m | ||
[31m- check_if_descripton_file_exists(icon_set_name)[m | ||
[31m- return make_api_compliant_response(icon_set.get_description())[m | ||
[31m-[m | ||
[31m-[m | ||
@app.route('/sets/<string:icon_set_name>/icons/<string:icon_name>', methods=['GET'])[m | ||
def icon_metadata(icon_set_name, icon_name):[m | ||
icon_set = get_and_check_icon_set(icon_set_name)[m | ||
[1mdiff --git a/tests/unit_tests/test_all_icons.py b/tests/unit_tests/test_all_icons.py[m | ||
[1mindex 0ca3846..b0f03f8 100644[m | ||
[1m--- a/tests/unit_tests/test_all_icons.py[m | ||
[1m+++ b/tests/unit_tests/test_all_icons.py[m | ||
[36m@@ -191,12 +191,7 @@[m [mclass AllIconsTest(ServiceIconsUnitTests):[m | ||
self.assertIn('name', icon_set_metadata)[m | ||
self.assertEqual(icon_set_name, icon_set_metadata['name'])[m | ||
self.assertIn('colorable', icon_set_metadata)[m | ||
[31m- self.assertIn('description_url', icon_set_metadata)[m | ||
[31m- if icon_set_metadata['description_url']:[m | ||
[31m- r = self.app.get([m | ||
[31m- icon_set_metadata['description_url'], headers=self.default_header[m | ||
[31m- )[m | ||
[31m- self.assertEqual(r.status_code, 200)[m | ||
[32m+[m[32m self.assertIn('has_description', icon_set_metadata)[m | ||
self.assertIn('icons_url', icon_set_metadata)[m | ||
self.assertIsNotNone(icon_set_metadata['icons_url'])[m | ||
self.assertEqual([m | ||
[1mdiff --git a/tests/unit_tests/test_description.py b/tests/unit_tests/test_description.py[m | ||
[1mindex 54751ef..859478c 100644[m | ||
[1m--- a/tests/unit_tests/test_description.py[m | ||
[1m+++ b/tests/unit_tests/test_description.py[m | ||
[36m@@ -1,8 +1,6 @@[m | ||
import json[m | ||
import os[m | ||
[m | ||
[31m-from flask import url_for[m | ||
[31m-[m | ||
from app.settings import DESCRIPTION_FOLDER[m | ||
from tests.unit_tests.base_test import ServiceIconsUnitTests[m | ||
[m | ||
[36m@@ -28,30 +26,3 @@[m [mclass IconsTests(ServiceIconsUnitTests):[m | ||
self.assertTrue([m | ||
validate_json(json_file), "validation failed of json file: " + file[m | ||
)[m | ||
[31m-[m | ||
[31m- def test_get_icon_set_description_valid(self):[m | ||
[31m- response = self.app.get([m | ||
[31m- url_for([m | ||
[31m- 'description_from_icon_set',[m | ||
[31m- icon_set_name='babs-I',[m | ||
[31m- ),[m | ||
[31m- headers={"Origin": 'www.example.com'}[m | ||
[31m- )[m | ||
[31m- self.assertEqual(response.status_code, 200)[m | ||
[31m-[m | ||
[31m- def test_get_icon_set_description_invalid(self):[m | ||
[31m- response = self.app.get([m | ||
[31m- url_for([m | ||
[31m- 'description_from_icon_set',[m | ||
[31m- icon_set_name='default',[m | ||
[31m- ),[m | ||
[31m- headers={"Origin": 'www.example.com'}[m | ||
[31m- )[m | ||
[31m- self.assertEqual([m | ||
[31m- response.json, {[m | ||
[31m- "error": {[m | ||
[31m- "code": 404, "message": "Description dictionary not found"[m | ||
[31m- },[m | ||
[31m- "success": False[m | ||
[31m- }[m | ||
[31m- )[m | ||
[1mdiff --git a/tests/unit_tests/test_endpoints_compliance.py b/tests/unit_tests/test_endpoints_compliance.py[m | ||
[1mindex ac54da3..0f7e97c 100644[m | ||
[1m--- a/tests/unit_tests/test_endpoints_compliance.py[m | ||
[1m+++ b/tests/unit_tests/test_endpoints_compliance.py[m | ||
[36m@@ -37,14 +37,6 @@[m [mclass CheckerTests(ServiceIconsUnitTests):[m | ||
)[m | ||
)[m | ||
[m | ||
[31m- def test_icon_set_description(self):[m | ||
[31m- self.check_response_compliance([m | ||
[31m- self.app.get([m | ||
[31m- url_for('description_from_icon_set', icon_set_name='babs-I'),[m | ||
[31m- headers=self.default_header[m | ||
[31m- )[m | ||
[31m- )[m | ||
[31m-[m | ||
def test_icons_list(self):[m | ||
self.check_response_compliance([m | ||
self.app.get([m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.