This commit is contained in:
parent
b0652add43
commit
8478e8d76e
@ -88,71 +88,73 @@ def seed_user(auth_id,
|
|||||||
|
|
||||||
|
|
||||||
def seed(dev: bool):
|
def seed(dev: bool):
|
||||||
seed_contacttypes()
|
with app.app_context():
|
||||||
|
seed_contacttypes()
|
||||||
|
|
||||||
skill_seed_file_path = app.config["KI_DATA_DIR"] + "/seed_data/skills.csv"
|
skill_seed_file_path = app.config["KI_DATA_DIR"] + "/seed_data/skills.csv"
|
||||||
|
|
||||||
app.logger.info("importing skills")
|
app.logger.info("importing skills")
|
||||||
|
|
||||||
with open(skill_seed_file_path) as skills_file:
|
with open(skill_seed_file_path) as skills_file:
|
||||||
skills_csv_reader = csv.DictReader(skills_file)
|
skills_csv_reader = csv.DictReader(skills_file)
|
||||||
|
|
||||||
for skill in skills_csv_reader:
|
for skill in skills_csv_reader:
|
||||||
id = int(skill["id"])
|
id = int(skill["id"])
|
||||||
db_skill = db.session.get(Skill, id)
|
db_skill = db.session.get(Skill, id)
|
||||||
|
|
||||||
if db_skill is None:
|
if db_skill is None:
|
||||||
db.session.add(Skill(id=int(skill["id"]), name=skill["name"]))
|
db.session.add(Skill(id=int(skill["id"]), name=skill["name"]))
|
||||||
|
|
||||||
app.logger.info("importing languages")
|
app.logger.info("importing languages")
|
||||||
|
|
||||||
iso_seed_file_path = app.config["KI_DATA_DIR"] + "/seed_data/iso_639_1.csv"
|
iso_seed_file_path = app.config["KI_DATA_DIR"] + "/seed_data/iso_639_1.csv"
|
||||||
|
|
||||||
with open(iso_seed_file_path) as iso_file:
|
with open(iso_seed_file_path) as iso_file:
|
||||||
iso_csv_reader = csv.DictReader(iso_file)
|
iso_csv_reader = csv.DictReader(iso_file)
|
||||||
|
|
||||||
for iso in iso_csv_reader:
|
for iso in iso_csv_reader:
|
||||||
id = iso["639-1"]
|
id = iso["639-1"]
|
||||||
db_language = db.session.get(Language, id)
|
db_language = db.session.get(Language, id)
|
||||||
|
|
||||||
if db_language is None:
|
if db_language is None:
|
||||||
db.session.add(Language(id=iso["639-1"], name=iso["Sprache"]))
|
db.session.add(Language(id=iso["639-1"], name=iso["Sprache"]))
|
||||||
|
|
||||||
if dev:
|
if dev:
|
||||||
seed_user("klaus", visible=False)
|
seed_user("klaus", visible=False)
|
||||||
|
|
||||||
for i in range(1, 20):
|
for i in range(1, 20):
|
||||||
seed_user(f"babsi{i}")
|
seed_user(f"babsi{i}")
|
||||||
|
|
||||||
seed_user("peter",
|
seed_user("peter",
|
||||||
nickname="peternichtlustig",
|
nickname="peternichtlustig",
|
||||||
visible=False,
|
visible=False,
|
||||||
pronouns="Herr Dr. Dr.",
|
pronouns="Herr Dr. Dr.",
|
||||||
volunteerwork="Gartenverein",
|
volunteerwork="Gartenverein",
|
||||||
availability_status=True,
|
availability_status=True,
|
||||||
availability_hours_per_week=42,
|
availability_hours_per_week=42,
|
||||||
availability_text="Immer",
|
availability_text="Immer",
|
||||||
freetext="Ich mag Kaffee",
|
freetext="Ich mag Kaffee",
|
||||||
skills=[(3, 3), (1, 5)],
|
skills=[(3, 3), (1, 5)],
|
||||||
searchtopics=[3, 1],
|
searchtopics=[3, 1],
|
||||||
languages=[("de", 5), ("fr", 3)],
|
languages=[("de", 5), ("fr", 3)],
|
||||||
address=("Peter Nichtlustig", "Waldweg", "23i", "Hinterhaus", "13337", "Bielefeld", "Deutschland"),
|
address=("Peter Nichtlustig", "Waldweg", "23i", "Hinterhaus", "13337", "Bielefeld",
|
||||||
contacts=[(4, "@peter:wtf-eg.de"), (1, "peter@wtf-eg.de")])
|
"Deutschland"),
|
||||||
|
contacts=[(4, "@peter:wtf-eg.de"), (1, "peter@wtf-eg.de")])
|
||||||
|
|
||||||
seed_user("dirtydieter",
|
seed_user("dirtydieter",
|
||||||
volunteerwork="Müll sammeln",
|
volunteerwork="Müll sammeln",
|
||||||
availability_status=True,
|
availability_status=True,
|
||||||
availability_hours_per_week=24,
|
availability_hours_per_week=24,
|
||||||
availability_text="Nur Nachts!",
|
availability_text="Nur Nachts!",
|
||||||
freetext="1001010010111!!!",
|
freetext="1001010010111!!!",
|
||||||
skills=[(1, 5)],
|
skills=[(1, 5)],
|
||||||
address=("Friedrich Witzig", "", "", "", "", "", ""))
|
address=("Friedrich Witzig", "", "", "", "", "", ""))
|
||||||
|
|
||||||
all_skills = [(skill.id, 3) for skill in Skill.query.all()]
|
all_skills = [(skill.id, 3) for skill in Skill.query.all()]
|
||||||
seed_user("jutta", languages=[("fr", 5)], skills=all_skills)
|
seed_user("jutta", languages=[("fr", 5)], skills=all_skills)
|
||||||
|
|
||||||
seed_user("giesela", skills=[(9, 3), (10, 5)])
|
seed_user("giesela", skills=[(9, 3), (10, 5)])
|
||||||
seed_user("bertha", visible=False, skills=[(11, 3), (10, 5)])
|
seed_user("bertha", visible=False, skills=[(11, 3), (10, 5)])
|
||||||
seed_user("monique", languages=[("fr", 4)])
|
seed_user("monique", languages=[("fr", 4)])
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
@ -26,13 +26,14 @@ class ApiTest(unittest.TestCase):
|
|||||||
config = migrate.get_config()
|
config = migrate.get_config()
|
||||||
command.upgrade(config, "head")
|
command.upgrade(config, "head")
|
||||||
|
|
||||||
seed(True)
|
seed(True)
|
||||||
max_skill = Skill.query.order_by(Skill.id.desc()).first()
|
max_skill = Skill.query.order_by(Skill.id.desc()).first()
|
||||||
self.max_skill_id = max_skill.id
|
self.max_skill_id = max_skill.id
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
db.drop_all()
|
with app.app_context():
|
||||||
db.engine.dispose()
|
db.drop_all()
|
||||||
|
db.engine.dispose()
|
||||||
|
|
||||||
def login(self, username, password):
|
def login(self, username, password):
|
||||||
login_data = {"username": username, "password": password}
|
login_data = {"username": username, "password": password}
|
||||||
|
@ -20,11 +20,12 @@ class TestProfileEndpoint(ApiTest):
|
|||||||
self.assertEqual(login_response.status_code, 200)
|
self.assertEqual(login_response.status_code, 200)
|
||||||
self.assertIn("token", login_response.json)
|
self.assertIn("token", login_response.json)
|
||||||
|
|
||||||
babsi = User.query.filter(User.auth_id == "babsi1").first()
|
with app.app_context():
|
||||||
response = self.client.post(f"/users/{babsi.id}/profile",
|
babsi = User.query.filter(User.auth_id == "babsi1").first()
|
||||||
data=json.dumps({}),
|
response = self.client.post(f"/users/{babsi.id}/profile",
|
||||||
content_type="application/json",
|
data=json.dumps({}),
|
||||||
headers={"Authorization": "Bearer " + login_response.json["token"]})
|
content_type="application/json",
|
||||||
|
headers={"Authorization": "Bearer " + login_response.json["token"]})
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
@ -103,11 +104,12 @@ class TestProfileEndpoint(ApiTest):
|
|||||||
"level": 2
|
"level": 2
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
peter = User.query.filter(User.auth_id == "peter").first()
|
with app.app_context():
|
||||||
response = self.client.post(f"/users/{peter.id}/profile",
|
peter = User.query.filter(User.auth_id == "peter").first()
|
||||||
data=json.dumps(data),
|
response = self.client.post(f"/users/{peter.id}/profile",
|
||||||
content_type="application/json",
|
data=json.dumps(data),
|
||||||
headers={"Authorization": "Bearer " + token})
|
content_type="application/json",
|
||||||
|
headers={"Authorization": "Bearer " + token})
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
@ -185,8 +187,9 @@ class TestProfileEndpoint(ApiTest):
|
|||||||
def test_get_visible_proifle(self):
|
def test_get_visible_proifle(self):
|
||||||
token = self.login("peter", "geheim")["token"]
|
token = self.login("peter", "geheim")["token"]
|
||||||
|
|
||||||
babsi = User.query.filter(User.auth_id == "babsi1").first()
|
with app.app_context():
|
||||||
response = self.client.get(f"/users/{babsi.id}/profile", headers={"Authorization": f"Bearer {token}"})
|
babsi = User.query.filter(User.auth_id == "babsi1").first()
|
||||||
|
response = self.client.get(f"/users/{babsi.id}/profile", headers={"Authorization": f"Bearer {token}"})
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
@ -197,10 +200,11 @@ class TestProfileEndpoint(ApiTest):
|
|||||||
self.assertEqual(login_response.status_code, 200)
|
self.assertEqual(login_response.status_code, 200)
|
||||||
self.assertIn("token", login_response.json)
|
self.assertIn("token", login_response.json)
|
||||||
|
|
||||||
peter = User.query.filter(User.auth_id == "peter").first()
|
with app.app_context():
|
||||||
response = self.client.get(f"/users/{peter.id}/profile",
|
peter = User.query.filter(User.auth_id == "peter").first()
|
||||||
headers={"Authorization": "Bearer " + login_response.json["token"]})
|
response = self.client.get(f"/users/{peter.id}/profile",
|
||||||
profile_id = peter.profile.id
|
headers={"Authorization": "Bearer " + login_response.json["token"]})
|
||||||
|
profile_id = peter.profile.id
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertDictEqual(
|
self.assertDictEqual(
|
||||||
response.json, {
|
response.json, {
|
||||||
|
Loading…
Reference in New Issue
Block a user