Download tests/test_integration.py from iBrokeTheCode/Image_Classifier_with_CNN: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/spaces/iBrokeTheCode/Image_Classifier_with_CNN/resolve/3ce4bfcd092cc1d5f518baf6ca367ffa336d7d75/tests/test_integration.py
- Command line
-
hf download hf://spaces/iBrokeTheCode/Image_Classifier_with_CNN@3ce4bfcd092cc1d5f518baf6ca367ffa336d7d75/tests/test_integration.py
-
curl -L -o test_integration.py https://huggingface.co/spaces/iBrokeTheCode/Image_Classifier_with_CNN/resolve/3ce4bfcd092cc1d5f518baf6ca367ffa336d7d75/tests/test_integration.py
1.46 kB
| 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 | |