forked from kompetenzinventar/ki-backend
60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
from alembic import command
|
|
import unittest
|
|
import json
|
|
|
|
from app import app, db, migrate
|
|
from ki.commands import seed
|
|
from ki.models import Profile, User
|
|
|
|
|
|
class TestProfileEndpoint(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")
|
|
|
|
seed()
|
|
|
|
def test_get_profile(self):
|
|
user = User(auth_id="peter")
|
|
db.session.add(user)
|
|
|
|
profile = Profile(user=user)
|
|
profile.nickname = "Popeter"
|
|
db.session.add(profile)
|
|
|
|
db.session.commit()
|
|
|
|
login_data = {"username": "peter", "password": "geheim"}
|
|
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)
|
|
|
|
response = self.client.get("/users/1/profile",
|
|
headers={
|
|
"Authorization":
|
|
"Bearer " + login_response.json["token"]
|
|
})
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(
|
|
response.json, {
|
|
"profile": {
|
|
"freetext": "",
|
|
"nickname": "Popeter",
|
|
"pronouns": "",
|
|
"volunteerwork": ""
|
|
}
|
|
})
|
|
|
|
|
|
if __name__ == "main":
|
|
unittest.main()
|