Commit
·
97391a1
1
Parent(s):
4af5fb3
chore: Add integration tests files
Browse files- .dockerignore +1 -0
- .gitattributes +1 -0
- compose.yml +78 -0
- tests/__init__.py +0 -0
- tests/dog.jpeg +3 -0
- tests/pytest.ini +3 -0
- tests/requirements.txt +2 -0
- tests/test_integration.py +54 -0
.dockerignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
uploads
|
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
compose.yml
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: "3.2"
|
| 2 |
+
services:
|
| 3 |
+
api:
|
| 4 |
+
image: flask_api
|
| 5 |
+
container_name: ml_api
|
| 6 |
+
build:
|
| 7 |
+
context: ./api
|
| 8 |
+
target: build
|
| 9 |
+
ports:
|
| 10 |
+
- "8000:5000"
|
| 11 |
+
depends_on:
|
| 12 |
+
- redis
|
| 13 |
+
- model
|
| 14 |
+
volumes:
|
| 15 |
+
- ./uploads:/src/uploads
|
| 16 |
+
environment:
|
| 17 |
+
POSTGRES_DB: $POSTGRES_DB
|
| 18 |
+
POSTGRES_USER: $POSTGRES_USER
|
| 19 |
+
POSTGRES_PASSWORD: $POSTGRES_PASSWORD
|
| 20 |
+
DATABASE_HOST: $DATABASE_HOST
|
| 21 |
+
SECRET_KEY: $SECRET_KEY
|
| 22 |
+
networks:
|
| 23 |
+
- shared_network
|
| 24 |
+
|
| 25 |
+
redis:
|
| 26 |
+
image: redis:6.2.6
|
| 27 |
+
networks:
|
| 28 |
+
- shared_network
|
| 29 |
+
|
| 30 |
+
db:
|
| 31 |
+
image: postgres:latest
|
| 32 |
+
container_name: postgres_db
|
| 33 |
+
environment:
|
| 34 |
+
POSTGRES_DB: $POSTGRES_DB
|
| 35 |
+
POSTGRES_USER: $POSTGRES_USER
|
| 36 |
+
POSTGRES_PASSWORD: $POSTGRES_PASSWORD
|
| 37 |
+
volumes:
|
| 38 |
+
- postgres_data:/var/lib/postgresql/data
|
| 39 |
+
ports:
|
| 40 |
+
- "5432:5432"
|
| 41 |
+
networks:
|
| 42 |
+
- shared_network
|
| 43 |
+
|
| 44 |
+
model:
|
| 45 |
+
image: ml_service
|
| 46 |
+
container_name: ml_service
|
| 47 |
+
build:
|
| 48 |
+
context: ./model
|
| 49 |
+
dockerfile: ./Dockerfile
|
| 50 |
+
depends_on:
|
| 51 |
+
- redis
|
| 52 |
+
volumes:
|
| 53 |
+
- ./uploads:/src/uploads
|
| 54 |
+
networks:
|
| 55 |
+
- shared_network
|
| 56 |
+
|
| 57 |
+
ui:
|
| 58 |
+
image: ml_ui
|
| 59 |
+
container_name: ml_ui
|
| 60 |
+
build:
|
| 61 |
+
context: ./ui
|
| 62 |
+
target: build
|
| 63 |
+
ports:
|
| 64 |
+
- "9090:9090"
|
| 65 |
+
depends_on:
|
| 66 |
+
- api
|
| 67 |
+
environment:
|
| 68 |
+
- API_HOST=api
|
| 69 |
+
- API_PORT=5000
|
| 70 |
+
networks:
|
| 71 |
+
- shared_network
|
| 72 |
+
|
| 73 |
+
networks:
|
| 74 |
+
shared_network:
|
| 75 |
+
external: true
|
| 76 |
+
|
| 77 |
+
volumes:
|
| 78 |
+
postgres_data:
|
tests/__init__.py
ADDED
|
File without changes
|
tests/dog.jpeg
ADDED
|
Git LFS Details
|
tests/pytest.ini
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[pytest]
|
| 2 |
+
filterwarnings =
|
| 3 |
+
ignore::DeprecationWarning
|
tests/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pytest==7.1.2
|
| 2 |
+
requests==2.28.1
|
tests/test_integration.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
|
| 3 |
+
# 💡 NOTE Run tests with pytest test_integration.py -W ignore::DeprecationWarning
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def login(username, password):
|
| 7 |
+
"""
|
| 8 |
+
Test the login function with valid credentials
|
| 9 |
+
"""
|
| 10 |
+
url = "http://0.0.0.0:8000/login"
|
| 11 |
+
headers = {
|
| 12 |
+
"accept": "application/json",
|
| 13 |
+
"Content-Type": "application/x-www-form-urlencoded",
|
| 14 |
+
}
|
| 15 |
+
data = {
|
| 16 |
+
"grant_type": "",
|
| 17 |
+
"username": username,
|
| 18 |
+
"password": password,
|
| 19 |
+
"scope": "",
|
| 20 |
+
"client_id": "",
|
| 21 |
+
"client_secret": "",
|
| 22 |
+
}
|
| 23 |
+
response = requests.post(url, headers=headers, data=data)
|
| 24 |
+
if response.status_code == 200:
|
| 25 |
+
return response.json()["access_token"]
|
| 26 |
+
else:
|
| 27 |
+
return None
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def test_login():
|
| 31 |
+
"""
|
| 32 |
+
Test the login function with valid credentials
|
| 33 |
+
"""
|
| 34 |
+
token = login("admin@example.com", "admin")
|
| 35 |
+
assert token is not None
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def test_predict():
|
| 39 |
+
"""
|
| 40 |
+
Test the predict function with valid credentials
|
| 41 |
+
"""
|
| 42 |
+
token = login("admin@example.com", "admin")
|
| 43 |
+
files = [("file", ("dog.jpeg", open("dog.jpeg", "rb"), "image/jpeg"))]
|
| 44 |
+
headers = {"Authorization": f"Bearer {token}"}
|
| 45 |
+
response = requests.post(
|
| 46 |
+
"http://localhost:8000/model/predict",
|
| 47 |
+
headers=headers,
|
| 48 |
+
files=files,
|
| 49 |
+
)
|
| 50 |
+
assert response.status_code == 200
|
| 51 |
+
data = response.json()
|
| 52 |
+
assert data["success"] == True
|
| 53 |
+
assert data["prediction"] == "Eskimo_dog"
|
| 54 |
+
assert data["score"] == 0.9346
|