ki-backend/ki/test/test_login_endpoint.py

32 lines
1.0 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-22 17:35:27 +02:00
import json
2021-06-27 14:25:44 +02:00
import unittest
2021-06-22 17:35:27 +02:00
2021-06-27 14:25:44 +02:00
from ki.test.ApiTest import ApiTest
2021-06-26 10:51:39 +02:00
2021-06-22 17:35:27 +02:00
2021-06-27 14:25:44 +02:00
class TestLoginEndpoint(ApiTest):
2024-08-28 13:43:33 +02:00
2021-06-22 17:35:27 +02:00
def test_login(self):
2021-06-27 14:25:44 +02:00
response1_data = self.login("peter", "geheim")
response2_data = self.login("peter", "geheim")
2021-06-22 17:35:27 +02:00
self.assertNotEqual(response1_data["token"], response2_data["token"])
2021-06-27 14:25:44 +02:00
def test_login_wrong_credentails(self):
login_data = {"username": "peter", "password": "123456"}
login_response = self.client.post("/users/login", data=json.dumps(login_data), content_type="application/json")
self.assertEqual(login_response.status_code, 403)
def test_login_unknown_user(self):
login_data = {"username": "karl", "password": "123456"}
login_response = self.client.post("/users/login", data=json.dumps(login_data), content_type="application/json")
self.assertEqual(login_response.status_code, 403)
2021-06-22 17:35:27 +02:00
if __name__ == "main":
unittest.main()