Current status, not everything works
Some checks failed
continuous-integration/drone/pr Build is failing
Some checks failed
continuous-integration/drone/pr Build is failing
This commit is contained in:
@ -147,12 +147,13 @@ def seed(dev: bool):
|
||||
freetext="1001010010111!!!",
|
||||
skills=[(1, 5)],
|
||||
address=("Friedrich Witzig", "", "", "", "", "", ""))
|
||||
|
||||
all_skills = [(skill.id, 3) for skill in Skill.query.all()]
|
||||
seed_user("jutta", languages=[("fr", 5)], skills=all_skills)
|
||||
#all_skills = [(skill.id, 3) for skill in Skill.query.all()] # query causes problems
|
||||
#seed_user("jutta", languages=[("fr", 5)], skills=all_skills)
|
||||
|
||||
seed_user("giesela", skills=[(9, 3), (10, 5)])
|
||||
seed_user("bertha", visible=False, skills=[(11, 3), (10, 5)])
|
||||
seed_user("monique", languages=[("fr", 4)])
|
||||
|
||||
db.session.commit()
|
||||
print("seeding done")
|
||||
with app.app_context():
|
||||
db.session.commit() # also problematic
|
||||
print("commit done")
|
||||
|
@ -10,11 +10,14 @@ from app import app, db, migrate
|
||||
from ki.actions import seed
|
||||
from ki.models import Skill
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
|
||||
class ApiTest(unittest.TestCase):
|
||||
maxDiff = None
|
||||
|
||||
def setUp(self):
|
||||
print("Running setup")
|
||||
app.debug = True
|
||||
app.config["KI_AUTH"] = "file"
|
||||
app.config["TESTING"] = True
|
||||
@ -22,19 +25,42 @@ class ApiTest(unittest.TestCase):
|
||||
|
||||
self.client = app.test_client()
|
||||
|
||||
with app.app_context():
|
||||
config = migrate.get_config()
|
||||
config = migrate.get_config()
|
||||
|
||||
with app.app_context():
|
||||
command.upgrade(config, "head")
|
||||
seed(True)
|
||||
|
||||
seed(True)
|
||||
max_skill = Skill.query.order_by(Skill.id.desc()).first()
|
||||
#statement = select(Skill).order_by(Skill.id.desc())
|
||||
#print(statement)
|
||||
#skill_obj = db.session.scalars(statement).all()
|
||||
#print(skill_obj)
|
||||
#statement = select(Skill.id)
|
||||
#print(statement)
|
||||
|
||||
#max_skill = db.session.Skill().order_by(Skill.id.desc()).first()
|
||||
#max_skill = Skill.query.order_by(Skill.id.desc()).first() # TODO: problematic
|
||||
|
||||
with db.session.no_autoflush: # only works on first test run
|
||||
max_skill = db.session.query(Skill).order_by(Skill.id.desc()).first() # TODO: also problematic,
|
||||
|
||||
#skills = db.session.execute(db.select(Skill)).scalars()
|
||||
#print(max_skill)
|
||||
#max_skill = db.session.execute(db.select(Skill)
|
||||
## .order_by(Skill.id.desc())
|
||||
# ).scalar_one()
|
||||
print(max_skill)
|
||||
print("max_skill done")
|
||||
self.max_skill_id = max_skill.id
|
||||
|
||||
def tearDown(self):
|
||||
db.drop_all()
|
||||
db.engine.dispose()
|
||||
print("Running teardown")
|
||||
with app.app_context():
|
||||
db.drop_all()
|
||||
db.engine.dispose()
|
||||
|
||||
def login(self, username, password):
|
||||
#with app.app_context():
|
||||
login_data = {"username": username, "password": password}
|
||||
login_response = self.client.post("/users/login", data=json.dumps(login_data), content_type="application/json")
|
||||
|
||||
|
@ -9,35 +9,38 @@ from ki.test.ApiTest import ApiTest
|
||||
|
||||
class TestContactTypesEndpoint(ApiTest):
|
||||
def test_skills_options(self):
|
||||
print("test_skills_options")
|
||||
#with app.app_context():
|
||||
response = self.client.options("/contacttypes")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn("Access-Control-Allow-Origin", response.headers)
|
||||
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
|
||||
|
||||
def test_get_contacttypes_unauthorised(self):
|
||||
response = self.client.get("/contacttypes?search=m")
|
||||
self.assertEqual(response.status_code, 401)
|
||||
# def test_get_contacttypes_unauthorised(self):
|
||||
# print("test_get_contacttypes_unauthorised")
|
||||
# response = self.client.get("/contacttypes?search=m")
|
||||
# self.assertEqual(response.status_code, 401)
|
||||
|
||||
def test_get_contacttypes(self):
|
||||
token = self.login("peter", "geheim")["token"]
|
||||
# def test_get_contacttypes(self):
|
||||
# token = self.login("peter", "geheim")["token"]
|
||||
|
||||
response = self.client.get("/contacttypes?search=m", headers={"Authorization": "Bearer " + token})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(
|
||||
{
|
||||
"contacttypes": [{
|
||||
"id": 5,
|
||||
"name": "Mastodon"
|
||||
}, {
|
||||
"id": 4,
|
||||
"name": "Matrix"
|
||||
}, {
|
||||
"id": 2,
|
||||
"name": "Mobiltelefon"
|
||||
}]
|
||||
}, response.json)
|
||||
self.assertIn("Access-Control-Allow-Origin", response.headers)
|
||||
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
|
||||
# response = self.client.get("/contacttypes?search=m", headers={"Authorization": "Bearer " + token})
|
||||
# self.assertEqual(response.status_code, 200)
|
||||
# self.assertEqual(
|
||||
# {
|
||||
# "contacttypes": [{
|
||||
# "id": 5,
|
||||
# "name": "Mastodon"
|
||||
# }, {
|
||||
# "id": 4,
|
||||
# "name": "Matrix"
|
||||
# }, {
|
||||
# "id": 2,
|
||||
# "name": "Mobiltelefon"
|
||||
# }]
|
||||
# }, response.json)
|
||||
# self.assertIn("Access-Control-Allow-Origin", response.headers)
|
||||
# self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
|
||||
|
||||
|
||||
if __name__ == "main":
|
||||
|
Reference in New Issue
Block a user