2021-07-06 21:14:41 +02:00
|
|
|
# SPDX-FileCopyrightText: WTF Kooperative eG <https://wtf-eg.de/>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2021-07-05 18:54:25 +02:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from ki.test.ApiTest import ApiTest
|
|
|
|
|
|
|
|
|
2021-07-12 21:13:12 +02:00
|
|
|
class TestFindProfilesEndpoint(ApiTest):
|
|
|
|
def test_find_profiles_options(self):
|
|
|
|
response = self.client.options("/users/profiles")
|
2021-07-05 18:54:25 +02:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertIn("Access-Control-Allow-Origin", response.headers)
|
|
|
|
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
|
|
|
|
|
2021-07-12 21:13:12 +02:00
|
|
|
def test_find_nobody(self):
|
2021-07-05 18:54:25 +02:00
|
|
|
token = self.login("peter", "geheim")["token"]
|
|
|
|
|
2021-07-12 21:13:12 +02:00
|
|
|
response = self.client.get("/users/profiles?nickname=horsthorsthorst",
|
|
|
|
headers={"Authorization": "Bearer " + token})
|
2021-07-05 18:54:25 +02:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2022-01-16 16:35:23 +01:00
|
|
|
self.assertEqual(response.json, {"total": 0, "page": 1, "pages": 0, "profiles": []})
|
2021-07-12 21:13:12 +02:00
|
|
|
|
|
|
|
def test_find_sql_specialchars(self):
|
|
|
|
token = self.login("peter", "geheim")["token"]
|
|
|
|
|
|
|
|
response = self.client.get("/users/profiles?nickname=%22%27%25", headers={"Authorization": "Bearer " + token})
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2022-01-16 16:35:23 +01:00
|
|
|
self.assertEqual(response.json, {"total": 0, "page": 1, "pages": 0, "profiles": []})
|
2021-07-12 21:13:12 +02:00
|
|
|
|
2022-01-16 16:35:23 +01:00
|
|
|
def test_find_all_page1(self):
|
2021-07-12 21:13:12 +02:00
|
|
|
token = self.login("peter", "geheim")["token"]
|
|
|
|
|
|
|
|
response = self.client.get("/users/profiles", headers={"Authorization": "Bearer " + token})
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2022-01-16 16:35:23 +01:00
|
|
|
self.assertDictContainsSubset({"total": 23, "page": 1, "pages": 2}, response.json)
|
|
|
|
self.assertDictContainsSubset({"nickname": "babsi1"}, response.json["profiles"][0])
|
|
|
|
self.assertDictContainsSubset({"nickname": "dirtydieter"}, response.json["profiles"][19])
|
|
|
|
|
|
|
|
def test_find_all_page2(self):
|
|
|
|
token = self.login("peter", "geheim")["token"]
|
|
|
|
|
|
|
|
response = self.client.get("/users/profiles?page=2", headers={"Authorization": "Bearer " + token})
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertDictContainsSubset({"total": 23, "page": 2, "pages": 2}, response.json)
|
|
|
|
self.assertDictContainsSubset({"nickname": "giesela"}, response.json["profiles"][0])
|
2021-09-20 21:07:48 +02:00
|
|
|
self.assertDictContainsSubset({"nickname": "jutta"}, response.json["profiles"][1])
|
2022-01-16 16:35:23 +01:00
|
|
|
self.assertDictContainsSubset({"nickname": "monique"}, response.json["profiles"][2])
|
2021-08-16 22:41:03 +02:00
|
|
|
|
|
|
|
def test_find_dieter(self):
|
|
|
|
token = self.login("peter", "geheim")["token"]
|
|
|
|
|
|
|
|
response = self.client.get("/users/profiles?search=dieter%20php", headers={"Authorization": "Bearer " + token})
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2021-07-12 21:13:12 +02:00
|
|
|
self.assertDictContainsSubset({"total": 1}, response.json)
|
|
|
|
self.assertDictContainsSubset({"nickname": "dirtydieter"}, response.json["profiles"][0])
|
2021-07-05 18:54:25 +02:00
|
|
|
|
2021-08-16 22:41:03 +02:00
|
|
|
def test_not_find_dieter(self):
|
|
|
|
token = self.login("peter", "geheim")["token"]
|
|
|
|
|
|
|
|
response = self.client.get("/users/profiles?search=dieter%20sqlite",
|
|
|
|
headers={"Authorization": "Bearer " + token})
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertDictContainsSubset({"total": 0}, response.json)
|
|
|
|
|
|
|
|
def test_find_sql(self):
|
|
|
|
token = self.login("peter", "geheim")["token"]
|
|
|
|
|
|
|
|
response = self.client.get("/users/profiles?search=sql", headers={"Authorization": "Bearer " + token})
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertDictContainsSubset({"total": 2}, response.json)
|
2022-01-16 16:35:23 +01:00
|
|
|
self.assertDictContainsSubset({"nickname": "giesela"}, response.json["profiles"][0])
|
|
|
|
self.assertDictContainsSubset({"nickname": "jutta"}, response.json["profiles"][1])
|
2021-08-16 22:41:03 +02:00
|
|
|
|
|
|
|
def test_find_postgres(self):
|
|
|
|
token = self.login("peter", "geheim")["token"]
|
|
|
|
|
|
|
|
response = self.client.get("/users/profiles?search=post", headers={"Authorization": "Bearer " + token})
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2021-09-20 21:07:48 +02:00
|
|
|
self.assertDictContainsSubset({"total": 2}, response.json)
|
2022-01-16 16:35:23 +01:00
|
|
|
self.assertDictContainsSubset({"nickname": "giesela"}, response.json["profiles"][0])
|
|
|
|
self.assertDictContainsSubset({"nickname": "jutta"}, response.json["profiles"][1])
|
2021-08-16 22:41:03 +02:00
|
|
|
|
|
|
|
def test_find_php_franzosen(self):
|
|
|
|
token = self.login("peter", "geheim")["token"]
|
|
|
|
|
|
|
|
response = self.client.get("/users/profiles?search=php%20franz", headers={"Authorization": "Bearer " + token})
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertDictContainsSubset({"total": 1}, response.json)
|
|
|
|
self.assertDictContainsSubset({"nickname": "jutta"}, response.json["profiles"][0])
|
|
|
|
|
|
|
|
def test_find_franzosen(self):
|
|
|
|
token = self.login("peter", "geheim")["token"]
|
|
|
|
|
|
|
|
response = self.client.get("/users/profiles?search=französisch", headers={"Authorization": "Bearer " + token})
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertDictContainsSubset({"total": 2}, response.json)
|
|
|
|
self.assertDictContainsSubset({"nickname": "jutta"}, response.json["profiles"][0])
|
|
|
|
self.assertDictContainsSubset({"nickname": "monique"}, response.json["profiles"][1])
|
|
|
|
|
2023-04-20 18:25:32 +02:00
|
|
|
def test_find_dieter_by_name(self):
|
2023-04-20 18:07:01 +02:00
|
|
|
token = self.login("peter", "geheim")["token"]
|
|
|
|
|
|
|
|
response = self.client.get("/users/profiles?search=friedrich", headers={"Authorization": "Bearer " + token})
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertDictContainsSubset({"total": 1}, response.json)
|
|
|
|
self.assertDictContainsSubset({"nickname": "dirtydieter"}, response.json["profiles"][0])
|
|
|
|
|
2021-07-05 18:54:25 +02:00
|
|
|
|
|
|
|
if __name__ == "main":
|
|
|
|
unittest.main()
|