Skip to content

Instantly share code, notes, and snippets.

@cosmic-cortex
Created January 27, 2020 18:02
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/c0036b6baf2a25263d58ef9fa2434aa0 to your computer and use it in GitHub Desktop.
Save cosmic-cortex/c0036b6baf2a25263d58ef9fa2434aa0 to your computer and use it in GitHub Desktop.
Testing the API endpoint with invalid user data
from itertools import product
from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY
@pytest.mark.parametrize(
"n_instances, test_data_n_features",
product(range(1, 10), [n for n in range(1, 20) if n != n_features]),
)
def test_predict_with_wrong_input(
n_instances: int, test_data_n_features: int, test_client: TestClient
):
fake_data = [[random.random() for _ in range(test_data_n_features)] for _ in range(n_instances)]
response = test_client.post("/predict", json={"data": fake_data})
assert response.status_code == HTTP_422_UNPROCESSABLE_ENTITY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment