Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Soumaya-JE authored Oct 3, 2024
1 parent 1b9b597 commit d0a291e
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/testing/test_endpoint_monitoring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pytest
import requests


# Sample credentials for users
VALID_CREDENTIALS_USER1 = ("user1", "datascientest")
VALID_CREDENTIALS_ADMIN = ("admin", "adminsecret")
INVALID_CREDENTIALS = ("user1", "wrongpassword")


# Défine API GATEWAY URL
API_GATEWAY_MONITOR = "http://localhost:8000/monitor"


# Test the /monitor endpoint with admin credentials
def test_monitor_endpoint_as_admin():
response = requests.get(
url=API_GATEWAY_MONITOR,
auth=VALID_CREDENTIALS_ADMIN
)

assert response.status_code == 200
response_json = response.json()
assert 'accuracy' in response_json
accuracy = response_json['accuracy'][0]
assert accuracy > 0.6
assert 'data_drift' in response_json
assert 'model_drift' in response_json



# Test the /monitor endpoint without admin credentials
def test_monitor_endpoint_as_user():
response = requests.get(
url=API_GATEWAY_MONITOR,
auth=VALID_CREDENTIALS_USER1
)

assert response.status_code == 403



0 comments on commit d0a291e

Please sign in to comment.