From 178381b00c3a749c40a2dd49ca4a0c4d6cb2669b Mon Sep 17 00:00:00 2001 From: gulliver Date: Mon, 26 Jul 2021 19:56:36 +0200 Subject: [PATCH] extend seed skills --- data/seed_data/skills.csv | 5 +++++ ki/test/ApiTest.py | 3 +++ ki/test/test_profile_endpoint.py | 4 ++-- ki/test/test_skills_endpoint.py | 31 ++++++++++++++----------------- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/data/seed_data/skills.csv b/data/seed_data/skills.csv index a88f648..360cf1c 100644 --- a/data/seed_data/skills.csv +++ b/data/seed_data/skills.csv @@ -11,3 +11,8 @@ id,name 10,PostgreSQL 11,SQLite 12,Node.js +13,C++ +14,C +15,VHDL +16,go +17, Perl \ No newline at end of file diff --git a/ki/test/ApiTest.py b/ki/test/ApiTest.py index 493f837..72e9873 100644 --- a/ki/test/ApiTest.py +++ b/ki/test/ApiTest.py @@ -8,6 +8,7 @@ import unittest from app import app, db, migrate from ki.actions import seed +from ki.models import Skill class ApiTest(unittest.TestCase): @@ -26,6 +27,8 @@ class ApiTest(unittest.TestCase): command.upgrade(config, "head") seed(True) + max_skill = Skill.query.order_by(Skill.id.desc()).first() + self.max_skill_id = max_skill.id def tearDown(self): db.drop_all() diff --git a/ki/test/test_profile_endpoint.py b/ki/test/test_profile_endpoint.py index bbbcc67..febc6a0 100644 --- a/ki/test/test_profile_endpoint.py +++ b/ki/test/test_profile_endpoint.py @@ -143,7 +143,7 @@ class TestProfileEndpoint(ApiTest): self.assertEqual(first_skill.level, 4) second_skill = skills[1] - self.assertEqual(second_skill.skill.id, 13) + self.assertEqual(second_skill.skill.id, self.max_skill_id + 1) self.assertEqual(second_skill.skill.name, "Tschunkproduktion") self.assertEqual(second_skill.level, 5) @@ -155,7 +155,7 @@ class TestProfileEndpoint(ApiTest): self.assertEqual(first_searchtopic.skill.name, "Python") second_searchtopic = searchtopics[1] - self.assertEqual(second_searchtopic.skill.id, 14) + self.assertEqual(second_searchtopic.skill.id, self.max_skill_id + 2) self.assertEqual(second_searchtopic.skill.name, "Assembler") languages = profile.languages diff --git a/ki/test/test_skills_endpoint.py b/ki/test/test_skills_endpoint.py index 5526111..1e40ae6 100644 --- a/ki/test/test_skills_endpoint.py +++ b/ki/test/test_skills_endpoint.py @@ -14,27 +14,24 @@ class TestSkillsEndpoint(ApiTest): self.assertIn("Access-Control-Allow-Origin", response.headers) self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*") - def test_get_skills1(self): + 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): token = self.login("peter", "geheim")["token"] response = self.client.get("/skills?search=p", headers={"Authorization": "Bearer " + token}) self.assertEqual(response.status_code, 200) - self.assertEqual( - { - "skills": [{ - "id": 1, - "name": "PHP", - "icon_url": "/skills/1/icon" - }, { - "id": 10, - "name": "PostgreSQL", - "icon_url": "/skills/10/icon" - }, { - "id": 3, - "name": "Python", - "icon_url": "/skills/3/icon" - }] - }, response.json) + self.assertGreaterEqual(len(response.json['skills']), 3) + self.assertIn("Access-Control-Allow-Origin", response.headers) self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")