Compare commits
No commits in common. "ea57f326b73c4f747a7678614ddf90d798ba2215" and "cd3f0f173b3b3b7b5a1cb30d45db243ad4cf38f9" have entirely different histories.
ea57f326b7
...
cd3f0f173b
@ -113,15 +113,6 @@ curl -s \
|
|||||||
http://localhost:5000/users/1/profile
|
http://localhost:5000/users/1/profile
|
||||||
```
|
```
|
||||||
|
|
||||||
Profilsuche nach Nickname:
|
|
||||||
|
|
||||||
```
|
|
||||||
curl -s \
|
|
||||||
-D "/dev/stderr" \
|
|
||||||
-H "Authorization: Bearer 22e6c5fc-8a5a-440e-b1f4-018deb9fd24e" \
|
|
||||||
http://localhost:5000/users/profiles
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Docker
|
## Docker
|
||||||
|
|
||||||
|
@ -7,5 +7,3 @@ peter:
|
|||||||
password: geheim
|
password: geheim
|
||||||
klaus:
|
klaus:
|
||||||
password: jutta
|
password: jutta
|
||||||
dieter:
|
|
||||||
password: hunger
|
|
||||||
|
@ -31,7 +31,7 @@ def seed(dev: bool):
|
|||||||
|
|
||||||
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")
|
logging.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)
|
||||||
@ -43,7 +43,7 @@ def seed(dev: bool):
|
|||||||
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")
|
logging.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"
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ def seed(dev: bool):
|
|||||||
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:
|
||||||
app.logger.info("seeding peter :)")
|
logging.info("seeding peter :)")
|
||||||
|
|
||||||
peter = User(auth_id="peter")
|
peter = User(auth_id="peter")
|
||||||
db.session.add(peter)
|
db.session.add(peter)
|
||||||
@ -105,23 +105,9 @@ def seed(dev: bool):
|
|||||||
peter_fr = ProfileLanguage(profile=peters_profile, language_id="fr", level=3)
|
peter_fr = ProfileLanguage(profile=peters_profile, language_id="fr", level=3)
|
||||||
db.session.add(peter_fr)
|
db.session.add(peter_fr)
|
||||||
|
|
||||||
app.logger.info("seeding klaus :D")
|
logging.info("seeding klaus :D")
|
||||||
|
|
||||||
klaus = User(auth_id="klaus")
|
klaus = User(auth_id="klaus")
|
||||||
db.session.add(klaus)
|
db.session.add(klaus)
|
||||||
|
|
||||||
app.logger.info("seeding dieter \\o/")
|
|
||||||
|
|
||||||
dieter = User(auth_id="dieter")
|
|
||||||
db.session.add(dieter)
|
|
||||||
|
|
||||||
dieters_profile = Profile(nickname="dirtydieter",
|
|
||||||
pronouns="",
|
|
||||||
volunteerwork="Müll sammeln",
|
|
||||||
availability="Nur nachts",
|
|
||||||
freetext="1001010010111!!!",
|
|
||||||
visible=True,
|
|
||||||
user=dieter)
|
|
||||||
db.session.add(dieters_profile)
|
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
@ -18,15 +18,11 @@ def find_profiles():
|
|||||||
if page_size > 100:
|
if page_size > 100:
|
||||||
return make_response({"messages": {"page_size": "Die maximale Anzahl Einträge pro Seite beträgt 100"}}, 400)
|
return make_response({"messages": {"page_size": "Die maximale Anzahl Einträge pro Seite beträgt 100"}}, 400)
|
||||||
|
|
||||||
query = Profile.query.filter(Profile.visible.is_(True))
|
offset = (page - 1) * page_size
|
||||||
|
|
||||||
if "nickname" in request.args:
|
|
||||||
nickname = request.args.get("nickname")
|
|
||||||
query = query.filter(Profile.nickname.like(f"%{nickname}%"))
|
|
||||||
|
|
||||||
|
query = Profile.query.filter(Profile.visible is True)
|
||||||
count = query.count()
|
count = query.count()
|
||||||
|
|
||||||
offset = (page - 1) * page_size
|
|
||||||
db_profiles = query.limit(page_size).offset(offset).all()
|
db_profiles = query.limit(page_size).offset(offset).all()
|
||||||
api_profiles = []
|
api_profiles = []
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class Profile(db.Model):
|
|||||||
"availability": self.availability,
|
"availability": self.availability,
|
||||||
"freetext": self.freetext,
|
"freetext": self.freetext,
|
||||||
"visible": self.visible,
|
"visible": self.visible,
|
||||||
"address": self.address.to_dict() if self.address else None,
|
"address": self.address.to_dict(),
|
||||||
"contacts": list(map(lambda contact: contact.to_dict(), self.contacts)),
|
"contacts": list(map(lambda contact: contact.to_dict(), self.contacts)),
|
||||||
"skills": list(map(lambda skill: skill.to_dict(), self.skills)),
|
"skills": list(map(lambda skill: skill.to_dict(), self.skills)),
|
||||||
"searchtopics": list(map(lambda searchtopic: searchtopic.to_dict(), self.searchtopics)),
|
"searchtopics": list(map(lambda searchtopic: searchtopic.to_dict(), self.searchtopics)),
|
||||||
|
@ -7,35 +7,36 @@ import unittest
|
|||||||
from ki.test.ApiTest import ApiTest
|
from ki.test.ApiTest import ApiTest
|
||||||
|
|
||||||
|
|
||||||
class TestFindProfilesEndpoint(ApiTest):
|
class TestSkillsEndpoint(ApiTest):
|
||||||
def test_find_profiles_options(self):
|
def test_skills_options(self):
|
||||||
response = self.client.options("/users/profiles")
|
response = self.client.options("/skills")
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertIn("Access-Control-Allow-Origin", response.headers)
|
self.assertIn("Access-Control-Allow-Origin", response.headers)
|
||||||
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
|
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
|
||||||
|
|
||||||
def test_find_nobody(self):
|
def test_get_skills1(self):
|
||||||
token = self.login("peter", "geheim")["token"]
|
token = self.login("peter", "geheim")["token"]
|
||||||
|
|
||||||
response = self.client.get("/users/profiles?nickname=horsthorsthorst",
|
response = self.client.get("/skills?search=p", headers={"Authorization": "Bearer " + token})
|
||||||
headers={"Authorization": "Bearer " + token})
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.json, {"total": 0, "profiles": []})
|
self.assertEqual(
|
||||||
|
{
|
||||||
def test_find_sql_specialchars(self):
|
"skills": [{
|
||||||
token = self.login("peter", "geheim")["token"]
|
"id": 1,
|
||||||
|
"name": "PHP",
|
||||||
response = self.client.get("/users/profiles?nickname=%22%27%25", headers={"Authorization": "Bearer " + token})
|
"icon_url": "/skills/1/icon"
|
||||||
self.assertEqual(response.status_code, 200)
|
}, {
|
||||||
self.assertEqual(response.json, {"total": 0, "profiles": []})
|
"id": 10,
|
||||||
|
"name": "PostgreSQL",
|
||||||
def test_find_all(self):
|
"icon_url": "/skills/10/icon"
|
||||||
token = self.login("peter", "geheim")["token"]
|
}, {
|
||||||
|
"id": 3,
|
||||||
response = self.client.get("/users/profiles", headers={"Authorization": "Bearer " + token})
|
"name": "Python",
|
||||||
self.assertEqual(response.status_code, 200)
|
"icon_url": "/skills/3/icon"
|
||||||
self.assertDictContainsSubset({"total": 1}, response.json)
|
}]
|
||||||
self.assertDictContainsSubset({"nickname": "dirtydieter"}, response.json["profiles"][0])
|
}, response.json)
|
||||||
|
self.assertIn("Access-Control-Allow-Origin", response.headers)
|
||||||
|
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "main":
|
if __name__ == "main":
|
||||||
|
@ -174,14 +174,7 @@ class TestProfileEndpoint(ApiTest):
|
|||||||
response = self.client.get("/users/1/profile")
|
response = self.client.get("/users/1/profile")
|
||||||
self.assertEqual(response.status_code, 401)
|
self.assertEqual(response.status_code, 401)
|
||||||
|
|
||||||
def test_get_visible_proifle(self):
|
def test_get_profile(self):
|
||||||
token = self.login("peter", "geheim")["token"]
|
|
||||||
|
|
||||||
response = self.client.get("/users/3/profile", headers={"Authorization": f"Bearer {token}"})
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
def test_get_own_profile(self):
|
|
||||||
login_data = {"username": "peter", "password": "geheim"}
|
login_data = {"username": "peter", "password": "geheim"}
|
||||||
login_response = self.client.post("/users/login", data=json.dumps(login_data), content_type="application/json")
|
login_response = self.client.post("/users/login", data=json.dumps(login_data), content_type="application/json")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user