File size: 1,455 Bytes
97391a1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import requests
# 💡 NOTE Run tests with pytest test_integration.py -W ignore::DeprecationWarning
def login(username, password):
"""
Test the login function with valid credentials
"""
url = "http://0.0.0.0:8000/login"
headers = {
"accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
}
data = {
"grant_type": "",
"username": username,
"password": password,
"scope": "",
"client_id": "",
"client_secret": "",
}
response = requests.post(url, headers=headers, data=data)
if response.status_code == 200:
return response.json()["access_token"]
else:
return None
def test_login():
"""
Test the login function with valid credentials
"""
token = login("admin@example.com", "admin")
assert token is not None
def test_predict():
"""
Test the predict function with valid credentials
"""
token = login("admin@example.com", "admin")
files = [("file", ("dog.jpeg", open("dog.jpeg", "rb"), "image/jpeg"))]
headers = {"Authorization": f"Bearer {token}"}
response = requests.post(
"http://localhost:8000/model/predict",
headers=headers,
files=files,
)
assert response.status_code == 200
data = response.json()
assert data["success"] == True
assert data["prediction"] == "Eskimo_dog"
assert data["score"] == 0.9346
|