Skip to content

Instantly share code, notes, and snippets.

@cosmic-cortex
Created January 27, 2020 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cosmic-cortex/8d63d7ceb65a3f919fb65eab46ac790d to your computer and use it in GitHub Desktop.
Save cosmic-cortex/8d63d7ceb65a3f919fb65eab46ac790d to your computer and use it in GitHub Desktop.
Testing the API endpoint
import pytest
import random
from starlette.testclient import TestClient
from starlette.status import HTTP_200_OK
from api.ml.model import n_features
@pytest.mark.parametrize("n_instances", range(1, 10))
def test_predict(n_instances: int, test_client: TestClient):
fake_data = [[random.random() for _ in range(n_features)] for _ in range(n_instances)]
response = test_client.post("/predict", json={"data": fake_data})
assert response.status_code == HTTP_200_OK
assert len(response.json()["data"]) == n_instances
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment