ki-backend/ki/test/test_skills_endpoint.py

53 lines
2.1 KiB
Python
Raw Permalink Normal View History

2021-07-05 19:37:05 +02:00
# SPDX-FileCopyrightText: WTF Kooperative eG <https://wtf-eg.de/>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
2021-06-13 21:41:01 +02:00
import unittest
2021-06-27 14:25:44 +02:00
from ki.test.ApiTest import ApiTest
2021-06-13 21:41:01 +02:00
2021-06-27 14:25:44 +02:00
class TestSkillsEndpoint(ApiTest):
2021-06-21 22:21:25 +02:00
def test_skills_options(self):
response = self.client.options("/skills")
self.assertEqual(response.status_code, 200)
self.assertIn("Access-Control-Allow-Origin", response.headers)
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
2021-07-26 19:56:36 +02:00
def test_find_skills_php(self):
token = self.login("peter", "geheim")["token"]
response = self.client.get("/skills?search=php", headers={"Authorization": "Bearer " + token})
self.assertEqual(response.status_code, 200)
self.assertGreaterEqual(len(response.json['skills']), 1)
self.assertIn({"id": 1, "name": "PHP", "icon_url": "/skills/1/icon"}, response.json['skills'])
self.assertIn("Access-Control-Allow-Origin", response.headers)
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
def test_find_skills_p(self):
2021-06-27 14:25:44 +02:00
token = self.login("peter", "geheim")["token"]
response = self.client.get("/skills?search=p", headers={"Authorization": "Bearer " + token})
2021-06-13 21:41:01 +02:00
self.assertEqual(response.status_code, 200)
2021-07-26 19:56:36 +02:00
self.assertGreaterEqual(len(response.json['skills']), 3)
2021-06-21 22:21:25 +02:00
self.assertIn("Access-Control-Allow-Origin", response.headers)
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
2021-06-13 21:41:01 +02:00
2021-07-12 20:18:45 +02:00
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")
2021-06-13 21:41:01 +02:00
if __name__ == "main":
unittest.main()