2022-06-01 15:37:39 +00:00
|
|
|
"""Test that the root API endpoint is available."""
|
2021-10-07 11:00:03 +00:00
|
|
|
|
|
|
|
import json
|
2022-05-20 15:24:51 +00:00
|
|
|
|
2021-10-07 11:00:03 +00:00
|
|
|
import requests
|
|
|
|
|
|
|
|
# We expect the server to be running on the local host
|
|
|
|
url = "http://localhost:8000/api/"
|
|
|
|
|
|
|
|
print("Testing InvenTree API endpoint")
|
|
|
|
|
|
|
|
response = requests.get(url)
|
|
|
|
|
2022-08-01 04:35:23 +00:00
|
|
|
assert response.status_code == 200
|
2021-10-07 11:00:03 +00:00
|
|
|
|
|
|
|
print("- Response 200 OK")
|
|
|
|
|
|
|
|
data = json.loads(response.text)
|
|
|
|
|
|
|
|
required_keys = [
|
|
|
|
'server',
|
|
|
|
'version',
|
|
|
|
'apiVersion',
|
|
|
|
'worker_running',
|
|
|
|
]
|
|
|
|
|
|
|
|
for key in required_keys:
|
2022-08-01 04:35:23 +00:00
|
|
|
assert key in data
|
2021-10-07 11:00:03 +00:00
|
|
|
print(f"- Found key '{key}'")
|
|
|
|
|
|
|
|
# Check that the worker is running
|
2022-08-01 04:35:23 +00:00
|
|
|
assert data['worker_running']
|
2021-10-07 11:00:03 +00:00
|
|
|
|
|
|
|
print("- Background worker is operational")
|
|
|
|
|
|
|
|
print("API Endpoint Tests Passed OK")
|