

chore: update model(s) route tests
@b472650aaa680158116793ced64227dfc2bd1c50
--- tests/api_model_test.py
+++ tests/api_model_test.py
... | ... | @@ -1,21 +1,10 @@ |
1 |
-from fastapi.testclient import TestClient |
|
1 |
+import openai |
|
2 | 2 |
from openai import OpenAI |
3 |
- |
|
4 |
-from faster_whisper_server.server_models import ModelObject |
|
3 |
+import pytest |
|
5 | 4 |
|
6 | 5 |
MODEL_THAT_EXISTS = "Systran/faster-whisper-tiny.en" |
7 | 6 |
MODEL_THAT_DOES_NOT_EXIST = "i-do-not-exist" |
8 | 7 |
MIN_EXPECTED_NUMBER_OF_MODELS = 70 # At the time of the test creation there are 89 models |
9 |
- |
|
10 |
- |
|
11 |
-# HACK: because ModelObject(**data) doesn't work |
|
12 |
-def model_dict_to_object(model_dict: dict) -> ModelObject: |
|
13 |
- return ModelObject( |
|
14 |
- id=model_dict["id"], |
|
15 |
- created=model_dict["created"], |
|
16 |
- object_=model_dict["object"], |
|
17 |
- owned_by=model_dict["owned_by"], |
|
18 |
- ) |
|
19 | 8 |
|
20 | 9 |
|
21 | 10 |
def test_list_models(openai_client: OpenAI) -> None: |
... | ... | @@ -23,13 +12,11 @@ |
23 | 12 |
assert len(models) > MIN_EXPECTED_NUMBER_OF_MODELS |
24 | 13 |
|
25 | 14 |
|
26 |
-def test_model_exists(client: TestClient) -> None: |
|
27 |
- response = client.get(f"/v1/models/{MODEL_THAT_EXISTS}") |
|
28 |
- data = response.json() |
|
29 |
- model = model_dict_to_object(data) |
|
15 |
+def test_model_exists(openai_client: OpenAI) -> None: |
|
16 |
+ model = openai_client.models.retrieve(MODEL_THAT_EXISTS) |
|
30 | 17 |
assert model.id == MODEL_THAT_EXISTS |
31 | 18 |
|
32 | 19 |
|
33 |
-def test_model_does_not_exist(client: TestClient) -> None: |
|
34 |
- response = client.get(f"/v1/models/{MODEL_THAT_DOES_NOT_EXIST}") |
|
35 |
- assert response.status_code == 404 |
|
20 |
+def test_model_does_not_exist(openai_client: OpenAI) -> None: |
|
21 |
+ with pytest.raises(openai.NotFoundError): |
|
22 |
+ openai_client.models.retrieve(MODEL_THAT_DOES_NOT_EXIST) |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?