forked from kompetenzinventar/ki-backend
fix svg icon header
This commit is contained in:
parent
cd2a7853dd
commit
c37824785d
11
ki/routes.py
11
ki/routes.py
@ -12,6 +12,9 @@ from ki.handlers import update_profile as update_profile_handler
|
|||||||
from ki.models import ContactType, Language, Skill, Token, User
|
from ki.models import ContactType, Language, Skill, Token, User
|
||||||
from app import app
|
from app import app
|
||||||
|
|
||||||
|
content_type_svg = "image/svg+xml"
|
||||||
|
content_type_png = "image/png"
|
||||||
|
|
||||||
|
|
||||||
def token_auth(func):
|
def token_auth(func):
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
@ -71,22 +74,22 @@ def handle_icon_request(model, id, path):
|
|||||||
icon_svg_path = icon_base_path + ".svg"
|
icon_svg_path = icon_base_path + ".svg"
|
||||||
|
|
||||||
if os.path.exists(icon_svg_path):
|
if os.path.exists(icon_svg_path):
|
||||||
return send_file(icon_svg_path, mimetype="image/svg")
|
return send_file(icon_svg_path, mimetype=content_type_svg)
|
||||||
|
|
||||||
icon_png_path = icon_base_path + ".png"
|
icon_png_path = icon_base_path + ".png"
|
||||||
|
|
||||||
if os.path.exists(icon_png_path):
|
if os.path.exists(icon_png_path):
|
||||||
return send_file(icon_png_path, mimetype="image/png")
|
return send_file(icon_png_path, mimetype=content_type_png)
|
||||||
|
|
||||||
unknown_svg_path = path + "unknown.svg"
|
unknown_svg_path = path + "unknown.svg"
|
||||||
|
|
||||||
if os.path.exists(unknown_svg_path):
|
if os.path.exists(unknown_svg_path):
|
||||||
return send_file(unknown_svg_path, mimetype="image/svg")
|
return send_file(unknown_svg_path, mimetype=content_type_svg)
|
||||||
|
|
||||||
unknown_png_path = path + "unknown.png"
|
unknown_png_path = path + "unknown.png"
|
||||||
|
|
||||||
if os.path.exists(unknown_png_path):
|
if os.path.exists(unknown_png_path):
|
||||||
return send_file(unknown_png_path, mimetype="image/png")
|
return send_file(unknown_png_path, mimetype=content_type_png)
|
||||||
|
|
||||||
return make_response({"error": "icon not found"}, 404)
|
return make_response({"error": "icon not found"}, 404)
|
||||||
|
|
||||||
|
38
ki/test/test_languages_endpoint.py
Normal file
38
ki/test/test_languages_endpoint.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# SPDX-FileCopyrightText: WTF Kooperative eG <https://wtf-eg.de/>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from ki.test.ApiTest import ApiTest
|
||||||
|
|
||||||
|
|
||||||
|
class TestLanguagesEndpoint(ApiTest):
|
||||||
|
def test_skills_options(self):
|
||||||
|
response = self.client.options("/languages")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertIn("Access-Control-Allow-Origin", response.headers)
|
||||||
|
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
|
||||||
|
|
||||||
|
def test_search_languages_fr(self):
|
||||||
|
token = self.login("peter", "geheim")["token"]
|
||||||
|
|
||||||
|
response = self.client.get("/languages?search=fr", headers={"Authorization": "Bearer " + token})
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertEqual({"languages": [{
|
||||||
|
"id": "fr",
|
||||||
|
"name": "Französisch",
|
||||||
|
"icon_url": "/languages/fr/icon"
|
||||||
|
}]}, response.json)
|
||||||
|
self.assertIn("Access-Control-Allow-Origin", response.headers)
|
||||||
|
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
|
||||||
|
|
||||||
|
def test_get_fr_icon(self):
|
||||||
|
response = self.client.get("/languages/fr/icon")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertIn("Content-Type", response.headers)
|
||||||
|
self.assertEqual(response.headers["Content-Type"], "image/png")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "main":
|
||||||
|
unittest.main()
|
@ -38,6 +38,18 @@ class TestSkillsEndpoint(ApiTest):
|
|||||||
self.assertIn("Access-Control-Allow-Origin", response.headers)
|
self.assertIn("Access-Control-Allow-Origin", response.headers)
|
||||||
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
|
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
|
||||||
|
|
||||||
|
def test_get_php_skill_icon(self):
|
||||||
|
response = self.client.get("/skills/1/icon")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertIn("Content-Type", response.headers)
|
||||||
|
self.assertEqual(response.headers["Content-Type"], "image/svg+xml; charset=utf-8")
|
||||||
|
|
||||||
|
def test_get_fallback_skill_icon(self):
|
||||||
|
response = self.client.get("/skills/2/icon")
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertIn("Content-Type", response.headers)
|
||||||
|
self.assertEqual(response.headers["Content-Type"], "image/svg+xml; charset=utf-8")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "main":
|
if __name__ == "main":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user