forked from kompetenzinventar/ki-backend
implement auth
This commit is contained in:
35
ki/test/ApiTest.py
Normal file
35
ki/test/ApiTest.py
Normal file
@ -0,0 +1,35 @@
|
||||
from alembic import command
|
||||
import json
|
||||
import unittest
|
||||
|
||||
from app import app, db, migrate
|
||||
from ki.actions import seed
|
||||
|
||||
|
||||
class ApiTest(unittest.TestCase):
|
||||
maxDiff = None
|
||||
|
||||
def setUp(self):
|
||||
app.debug = True
|
||||
app.config["TESTING"] = 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")
|
||||
|
||||
seed(True)
|
||||
|
||||
def tearDown(self):
|
||||
db.drop_all()
|
||||
db.engine.dispose()
|
||||
|
||||
def login(self, username, password):
|
||||
login_data = {"username": username, "password": password}
|
||||
login_response = self.client.post("/users/login", data=json.dumps(login_data), content_type="application/json")
|
||||
|
||||
self.assertEqual(login_response.status_code, 200)
|
||||
self.assertIn("token", login_response.json)
|
||||
|
||||
return login_response.json
|
Reference in New Issue
Block a user