Skip to content

Commit

Permalink
Update test_server.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Red_wolf2467 committed Nov 17, 2024
1 parent 3d1eae7 commit b64f102
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from quart import Quart, jsonify, request
from server import (
check_chatfilter,
check_user_db
check_user_db,
save_data,
load_data
)


Expand Down Expand Up @@ -34,6 +36,35 @@ async def check_user():
result = check_user_db(int(user_id), ids_list)
return jsonify(result)

@app.route("/flagg_user", methods=["POST"])
async def add_flagged_user():
data = await request.get_json()
user_id = data["id"]
user_name = data["name"]
reason = data["reason"]

if str(user_id) in ids_list:
return jsonify({"success": False, "message": "User already in Database!"})
else:
ids_list[str(user_id)] = {
"id": int(user_id),
"name": str(user_name),
"reason": str(reason),
"flagged": True
}
return jsonify({"success": True, "message": "User was flagged"})

@app.route("/deflag_user", methods=["POST"])
async def remove_flagged_user():
data = await request.get_json()
user_id = data["id"]

if str(user_id) in ids_list:
del ids_list[str(user_id)]
return jsonify({"success": True, "message": "User was deflagged"})
else:
return jsonify({"success": False, "message": "User not flagged!"})

yield app


Expand Down Expand Up @@ -69,3 +100,36 @@ async def test_check_user(app):
assert data["name"] is None


# Admin Endpoints Tests
@pytest.mark.asyncio
async def test_flag_user(app):
client = app.test_client()

# Benutzer flaggen, der nicht in der Datenbank ist
response = await client.post("/flagg_user", json={"id": 789, "name": "New User", "reason": "test reason"})
data = await response.get_json()
assert data["success"] is True
assert data["message"] == "User was flagged"

# Versuchen, denselben Benutzer erneut zu flaggen
response = await client.post("/flagg_user", json={"id": 789, "name": "New User", "reason": "test reason"})
data = await response.get_json()
assert data["success"] is False
assert data["message"] == "User already in Database!"


@pytest.mark.asyncio
async def test_deflag_user(app):
client = app.test_client()

# Benutzer, der bereits in der Datenbank ist, deflaggen
response = await client.post("/deflag_user", json={"id": 123})
data = await response.get_json()
assert data["success"] is True
assert data["message"] == "User was deflagged"

# Versuchen, einen Benutzer zu deflaggen, der nicht in der Datenbank ist
response = await client.post("/deflag_user", json={"id": 999})
data = await response.get_json()
assert data["success"] is False
assert data["message"] == "User not flagged!"

0 comments on commit b64f102

Please sign in to comment.