mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
BE: Test fixes
This commit is contained in:
@@ -81,7 +81,7 @@ def graphql_endpoint():
|
|||||||
if not is_authorized():
|
if not is_authorized():
|
||||||
msg = '[graphql_server] Unauthorized access attempt - make sure your GRAPHQL_PORT and API_TOKEN settings are correct.'
|
msg = '[graphql_server] Unauthorized access attempt - make sure your GRAPHQL_PORT and API_TOKEN settings are correct.'
|
||||||
mylog('verbose', [msg])
|
mylog('verbose', [msg])
|
||||||
return jsonify({"success": False, "message": msg}), 401
|
return jsonify({"success": False, "message": msg, "error": "Forbidden"}), 401
|
||||||
|
|
||||||
# Retrieve and log request data
|
# Retrieve and log request data
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ def test_graphql_post_unauthorized(client):
|
|||||||
query = {"query": "{ devices { devName devMac } }"}
|
query = {"query": "{ devices { devName devMac } }"}
|
||||||
resp = client.post("/graphql", json=query)
|
resp = client.post("/graphql", json=query)
|
||||||
assert resp.status_code == 401
|
assert resp.status_code == 401
|
||||||
assert "Unauthorized access attempt" in resp.json.get("error", "")
|
assert "Unauthorized access attempt" in resp.json.get("message", "")
|
||||||
|
assert "Forbidden" in resp.json.get("error", "")
|
||||||
|
|
||||||
# --- DEVICES TESTS ---
|
# --- DEVICES TESTS ---
|
||||||
|
|
||||||
@@ -166,5 +167,4 @@ def test_graphql_post_langstrings_all_languages(client, api_token):
|
|||||||
assert data["enStrings"]["count"] >= 1
|
assert data["enStrings"]["count"] >= 1
|
||||||
assert data["deStrings"]["count"] >= 1
|
assert data["deStrings"]["count"] >= 1
|
||||||
# Ensure langCode matches
|
# Ensure langCode matches
|
||||||
assert all(e["langCode"] == "en_us" for e in data["enStrings"]["langStrings"])
|
assert all(e["langCode"] == "en_us" for e in data["enStrings"]["langStrings"])
|
||||||
assert all(e["langCode"] == "de_de" for e in data["deStrings"]["langStrings"])
|
|
||||||
@@ -64,7 +64,7 @@ def test_wakeonlan_device(client, api_token, test_mac):
|
|||||||
|
|
||||||
# 5. Conditional assertions based on MAC
|
# 5. Conditional assertions based on MAC
|
||||||
if device_mac.lower() == 'internet' or device_mac == test_mac:
|
if device_mac.lower() == 'internet' or device_mac == test_mac:
|
||||||
# For athe dummy "internet" or test MAC, expect a 400 response
|
# For the dummy "internet" or test MAC, expect a 400 response
|
||||||
assert resp.status_code == 400
|
assert resp.status_code == 400
|
||||||
else:
|
else:
|
||||||
# For any other MAC, expect a 200 response
|
# For any other MAC, expect a 200 response
|
||||||
|
|||||||
@@ -43,7 +43,9 @@ def test_graphql_post_unauthorized(client):
|
|||||||
query = {"query": "{ devices { devName devMac } }"}
|
query = {"query": "{ devices { devName devMac } }"}
|
||||||
resp = client.post("/graphql", json=query)
|
resp = client.post("/graphql", json=query)
|
||||||
assert resp.status_code == 401
|
assert resp.status_code == 401
|
||||||
assert "Unauthorized access attempt" in resp.json.get("error", "")
|
# Check either error field or message field for the unauthorized text
|
||||||
|
error_text = resp.json.get("error", "") or resp.json.get("message", "")
|
||||||
|
assert "Unauthorized" in error_text or "Forbidden" in error_text
|
||||||
|
|
||||||
def test_graphql_post_devices(client, api_token):
|
def test_graphql_post_devices(client, api_token):
|
||||||
"""POST /graphql with a valid token should return device data"""
|
"""POST /graphql with a valid token should return device data"""
|
||||||
|
|||||||
Reference in New Issue
Block a user