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):
|
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()
|