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)
|
2021-07-12 21:13:12 +02:00
|
|
|
self.assertEqual(response.json, {"total": 0, "profiles": []})
|
|
|
|
|
|
|
|
def test_find_all(self):
|
|
|
|
token = self.login("peter", "geheim")["token"]
|
|
|
|
|
|
|
|
response = self.client.get("/users/profiles", 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()
|