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
|
||||
```
|
||||
|
||||
Profilsuche nach Nickname:
|
||||
|
||||
```
|
||||
curl -s \
|
||||
-D "/dev/stderr" \
|
||||
-H "Authorization: Bearer 22e6c5fc-8a5a-440e-b1f4-018deb9fd24e" \
|
||||
http://localhost:5000/users/profiles
|
||||
```
|
||||
|
||||
|
||||
## Docker
|
||||
|
||||
|
@ -7,5 +7,3 @@ peter:
|
||||
password: geheim
|
||||
klaus:
|
||||
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"
|
||||
|
||||
app.logger.info("importing skills")
|
||||
logging.info("importing skills")
|
||||
|
||||
with open(skill_seed_file_path) as skills_file:
|
||||
skills_csv_reader = csv.DictReader(skills_file)
|
||||
@ -43,7 +43,7 @@ def seed(dev: bool):
|
||||
if db_skill is None:
|
||||
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"
|
||||
|
||||
@ -58,7 +58,7 @@ def seed(dev: bool):
|
||||
db.session.add(Language(id=iso["639-1"], name=iso["Sprache"]))
|
||||
|
||||
if dev:
|
||||
app.logger.info("seeding peter :)")
|
||||
logging.info("seeding peter :)")
|
||||
|
||||
peter = User(auth_id="peter")
|
||||
db.session.add(peter)
|
||||
@ -105,23 +105,9 @@ def seed(dev: bool):
|
||||
peter_fr = ProfileLanguage(profile=peters_profile, language_id="fr", level=3)
|
||||
db.session.add(peter_fr)
|
||||
|
||||
app.logger.info("seeding klaus :D")
|
||||
logging.info("seeding klaus :D")
|
||||
|
||||
klaus = User(auth_id="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()
|
||||
|
@ -18,15 +18,11 @@ def find_profiles():
|
||||
if page_size > 100:
|
||||
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))
|
||||
|
||||
if "nickname" in request.args:
|
||||
nickname = request.args.get("nickname")
|
||||
query = query.filter(Profile.nickname.like(f"%{nickname}%"))
|
||||
offset = (page - 1) * page_size
|
||||
|
||||
query = Profile.query.filter(Profile.visible is True)
|
||||
count = query.count()
|
||||
|
||||
offset = (page - 1) * page_size
|
||||
db_profiles = query.limit(page_size).offset(offset).all()
|
||||
api_profiles = []
|
||||
|
||||
|
@ -53,7 +53,7 @@ class Profile(db.Model):
|
||||
"availability": self.availability,
|
||||
"freetext": self.freetext,
|
||||
"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)),
|
||||
"skills": list(map(lambda skill: skill.to_dict(), self.skills)),
|
||||
"searchtopics": list(map(lambda searchtopic: searchtopic.to_dict(), self.searchtopics)),
|
||||
|
@ -7,35 +7,36 @@ import unittest
|
||||
from ki.test.ApiTest import ApiTest
|
||||
|
||||
|
||||
class TestFindProfilesEndpoint(ApiTest):
|
||||
def test_find_profiles_options(self):
|
||||
response = self.client.options("/users/profiles")
|
||||
class TestSkillsEndpoint(ApiTest):
|
||||
def test_skills_options(self):
|
||||
response = self.client.options("/skills")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn("Access-Control-Allow-Origin", response.headers)
|
||||
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
|
||||
|
||||
def test_find_nobody(self):
|
||||
def test_get_skills1(self):
|
||||
token = self.login("peter", "geheim")["token"]
|
||||
|
||||
response = self.client.get("/users/profiles?nickname=horsthorsthorst",
|
||||
headers={"Authorization": "Bearer " + token})
|
||||
response = self.client.get("/skills?search=p", headers={"Authorization": "Bearer " + token})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json, {"total": 0, "profiles": []})
|
||||
|
||||
def test_find_sql_specialchars(self):
|
||||
token = self.login("peter", "geheim")["token"]
|
||||
|
||||
response = self.client.get("/users/profiles?nickname=%22%27%25", headers={"Authorization": "Bearer " + token})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json, {"total": 0, "profiles": []})
|
||||
|
||||
def test_find_all(self):
|
||||
token = self.login("peter", "geheim")["token"]
|
||||
|
||||
response = self.client.get("/users/profiles", headers={"Authorization": "Bearer " + token})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertDictContainsSubset({"total": 1}, response.json)
|
||||
self.assertDictContainsSubset({"nickname": "dirtydieter"}, response.json["profiles"][0])
|
||||
self.assertEqual(
|
||||
{
|
||||
"skills": [{
|
||||
"id": 1,
|
||||
"name": "PHP",
|
||||
"icon_url": "/skills/1/icon"
|
||||
}, {
|
||||
"id": 10,
|
||||
"name": "PostgreSQL",
|
||||
"icon_url": "/skills/10/icon"
|
||||
}, {
|
||||
"id": 3,
|
||||
"name": "Python",
|
||||
"icon_url": "/skills/3/icon"
|
||||
}]
|
||||
}, response.json)
|
||||
self.assertIn("Access-Control-Allow-Origin", response.headers)
|
||||
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
|
||||
|
||||
|
||||
if __name__ == "main":
|
||||
|
@ -174,14 +174,7 @@ class TestProfileEndpoint(ApiTest):
|
||||
response = self.client.get("/users/1/profile")
|
||||
self.assertEqual(response.status_code, 401)
|
||||
|
||||
def test_get_visible_proifle(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):
|
||||
def test_get_profile(self):
|
||||
login_data = {"username": "peter", "password": "geheim"}
|
||||
login_response = self.client.post("/users/login", data=json.dumps(login_data), content_type="application/json")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user