Skip to content

Commit

Permalink
add API test
Browse files Browse the repository at this point in the history
  • Loading branch information
wwoszczek committed Dec 12, 2023
1 parent dcf3633 commit f3c5bf2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
run: |
pytest tests/test_mlflow.py
pytest tests/test_train_model.py
pytest tests/test_api.py
continue-on-error: false


Expand Down
29 changes: 29 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest
from fastapi.testclient import TestClient
import io
import sys
import os

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from src.app.api import app
from pathlib import Path

ROOT_DIR = Path(Path(__file__).resolve().parent)


def test_make_prediction_endpoint():
with TestClient(app) as client:
# Replace 'path/to/your/image.jpg' with the actual path to your test image
image_path = ROOT_DIR / 'test_image_1.jpg'

# Open the image file in binary mode
with open(image_path, 'rb') as img_file:
# Create a file-like object from the image file
img_file_object = io.BytesIO(img_file.read())

files = {'beans_img': ('test_image_1.jpg', img_file_object, 'image/jpeg')}
response = client.post("/make_prediction", files=files)

assert response.status_code == 200
assert set(response.json().keys()) == {'prediction', 'probs'}
Binary file added tests/test_image_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f3c5bf2

Please sign in to comment.