better endpoints
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m15s
Run linting on the backend code / Build (pull_request) Successful in 27s
Run testing on the backend code / Build (pull_request) Failing after 48s
Build and release debug APK / Build APK (pull_request) Failing after 4m38s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 25s

This commit is contained in:
Helldragon67 2025-02-17 10:27:02 +01:00
parent fd091a9ccc
commit f258df8e72
4 changed files with 25 additions and 45 deletions

File diff suppressed because one or more lines are too long

View File

@ -270,8 +270,8 @@ def get_toilets(location: tuple[float, float] = Query(...), radius: int = 500) -
raise HTTPException(status_code=404, detail="No toilets found") from exc
@app.post("/user/create")
def register_user(email: str = Body(...), password: str = Body(...)) -> str:
@app.post("/user/create/{email}/{password}")
def register_user(email: str, password: str) -> str:
try:
response = supabase.supabase.auth.admin.create_user({
"email": email,
@ -293,11 +293,11 @@ def register_user(email: str = Body(...), password: str = Body(...)) -> str:
@app.post("/user/delete")
def delete_user(request: UserDeleteRequest):
@app.post("/user/delete/{user_id}")
def delete_user(user_id: str):
try:
response = supabase.supabase.auth.admin.delete_user(request.user_id)
response = supabase.supabase.auth.admin.delete_user(user_id)
logger.debug(response)
except Exception as e:
if e.code == 'user_not_found' :
@ -306,6 +306,6 @@ def delete_user(request: UserDeleteRequest):
logger.error(f"Failed to create user : {str(e.code)}")
raise HTTPException(status_code=500, detail=str(e)) from e
logger.info(f"User with ID {request.user_id} deleted successfully")
logger.info(f"User with ID {user_id} deleted successfully")

View File

@ -19,50 +19,30 @@ def test_user_handling(client) :
Test the creation of a new user.
"""
# Create a new user
response = client.post(
"/user/create",
json={
"email": TEST_EMAIL,
"password": TEST_PW
}
)
response = client.post(f"/user/create/{TEST_EMAIL}/{TEST_PW}")
# Verify user has been created
assert response.status_code == 200
assert response.status_code == 200, "Failed to create dummy user"
user_id = response.json()
# # Create same user again to raise an error
response = client.post(
"/user/create",
json={
"email": TEST_EMAIL,
"password": TEST_PW
}
)
# Create same user again to raise an error
response = client.post(f"/user/create/{TEST_EMAIL}/{TEST_PW}")
# Verify user already exists
assert response.status_code == 422
assert response.status_code == 422, "Failed to simulate dummy user already created."
# Delete the user.
response = client.post(
"/user/delete",
json={
"user_id": user_id
}
)
print(response)
response = client.post(f"/user/delete/{user_id}")
# Verify user has been deleted
assert response.status_code == 200, "Failed to delete dummy user."
# Delete the user again to raise an error
response = client.post(
"/user/delete",
json={
"user_id": user_id
}
)
print(response)
response = client.post(f"/user/delete/{user_id}")
# Verify user has been deleted
assert response.status_code == 404, "Failed to delete dummy user."
assert response.status_code == 404, "Failed to simulate dummy user already deleted."

View File

@ -134,7 +134,7 @@ class ClusterManager:
# Check that there are is least 1 cluster
if len(set(labels)) > 1 :
self.logger.info(f"Found {len(set(labels))} different {cluster_type} clusters.")
self.logger.info(f"Found {len(set(labels))} {cluster_type} clusters.")
# Separate clustered points and noise points
self.cluster_points = self.all_points[labels != -1]
self.cluster_labels = labels[labels != -1]