Files
integration-test/run_test.py
T
2025-07-29 17:01:32 -05:00

49 lines
1.5 KiB
Python

import os
import pytest
import requests
def test_health_endpoint():
"""
Test the health endpoint to ensure it returns the expected response.
Makes an HTTP GET request to the health endpoint and validates:
- The request is successful (status code 200)
- The response is valid JSON
- The response contains results.message == "ok"
"""
urls = {
"testing": "https://api.cleverbrag.epsilon.cleverthis.com",
"staging": "https://api.cleverbrag.delta.cleverthis.com",
"production": "https://api.cleverbrag.cleverthis.com",
}
url = urls[os.getenv("TARGET_ENVIRONMENT")]
# Make the HTTP request
response = requests.get(url)
# Assert the request was successful
assert (
response.status_code == 200
), f"Expected status code 200, got {response.status_code}"
# Parse the JSON response
json_response = response.json()
# Validate the response structure and content
assert "results" in json_response, "Response should contain 'results' key"
assert (
"message" in json_response["results"]
), "Response results should contain 'message' key"
assert (
json_response["results"]["message"] == "ok"
), f"Expected message 'ok', got '{json_response['results']['message']}'"
if __name__ == "__main__":
print(f"Running pytest in {TARGET_ENVIRONMENT}")
# Allow running the test directly with python run_test.py
test_health_endpoint()
print("Health endpoint test passed!")