ki-backend/ki/test/test_login_endpoint.py

44 lines
1.2 KiB
Python
Raw Normal View History

2021-06-22 17:35:27 +02:00
from alembic import command
import json
import unittest
2021-06-26 10:51:39 +02:00
from app import app, db, migrate
from ki.actions import seed
2021-06-22 17:35:27 +02:00
class TestLoginEndpoint(unittest.TestCase):
def setUp(self):
app.debug = True
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:"
self.client = app.test_client()
with app.app_context():
config = migrate.get_config()
command.upgrade(config, "head")
2021-06-26 10:51:39 +02:00
seed(True)
def tearDown(self):
db.drop_all()
db.engine.dispose()
2021-06-22 17:35:27 +02:00
def test_login(self):
response1_data = self.login()
response2_data = self.login()
self.assertNotEqual(response1_data["token"], response2_data["token"])
def login(self):
response = self.client.post("/users/login",
data=json.dumps({
"username": "peter",
"password": "geheim"
}),
content_type="application/json")
self.assertEqual(response.status_code, 200)
self.assertIn("token", response.json)
return response.json
if __name__ == "main":
unittest.main()