-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from pydantic import BaseModel | ||
|
||
class Review(BaseModel): | ||
msg : str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,62 @@ | ||
from fastapi.testclient import TestClient | ||
import os | ||
import sys | ||
|
||
# Get the parent directory | ||
parent_dir = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
# Add the parent directory to sys.path | ||
sys.path.append(parent_dir) | ||
|
||
from src.app.api import app | ||
from http import HTTPStatus | ||
|
||
client = TestClient(app) | ||
|
||
def test_read_main(): | ||
response = client.get("/") | ||
assert response.status_code == 200 | ||
response_body = response.json() | ||
assert response_body["message"] == HTTPStatus.OK.phrase | ||
assert response_body["data"]["message"] == "Welcome to SentiBites! Please, read the `/docs`!" | ||
with TestClient(app) as client: | ||
response = client.get("/") | ||
assert response.status_code == 200 | ||
response_body = response.json() | ||
assert response_body["message"] == HTTPStatus.OK.phrase | ||
assert response_body["data"]["message"] == "Welcome to SentiBites! Please, read the `/docs`!" | ||
|
||
def test_read_prediction(): | ||
response = client.post("/models/", params={"payload": "This is a test."}) | ||
assert response.status_code == 200 | ||
response_body = response.json() | ||
assert response_body["message"] == HTTPStatus.OK.phrase | ||
assert response_body["status-code"] == HTTPStatus.OK | ||
assert response_body["data"]["model-type"] == "RoBERTaSB" | ||
assert response_body["data"]["payload"] == "This is a test." | ||
with TestClient(app) as client: | ||
response = client.post("/models", json = {'msg':"This is a test."}) | ||
assert response.status_code == 200 | ||
response_body = response.json() | ||
assert response_body["message"] == HTTPStatus.OK.phrase | ||
assert response_body["status-code"] == HTTPStatus.OK | ||
assert response_body["data"]["model-type"] == "RoBERTaSB" | ||
assert response_body["data"]["payload"] == "This is a test." | ||
|
||
def test_positive_prediction(): | ||
response = client.post("/models/", params={"payload": "This food is really good."}) | ||
assert response.status_code == 200 | ||
response_body = response.json() | ||
assert response_body["message"] == HTTPStatus.OK.phrase | ||
assert response_body["status-code"] == HTTPStatus.OK | ||
assert response_body["data"]["model-type"] == "RoBERTaSB" | ||
assert response_body["data"]["payload"] == "This food is really good." | ||
assert response_body["data"]["prediction"] == "positive" | ||
with TestClient(app) as client: | ||
response = client.post("/models/", json={"msg": "This food is really good."}) | ||
assert response.status_code == 200 | ||
response_body = response.json() | ||
assert response_body["message"] == HTTPStatus.OK.phrase | ||
assert response_body["status-code"] == HTTPStatus.OK | ||
assert response_body["data"]["model-type"] == "RoBERTaSB" | ||
assert response_body["data"]["payload"] == "This food is really good." | ||
assert response_body["data"]["prediction"] == "positive" | ||
|
||
def test_negative_prediction(): | ||
response = client.post("/models/", params={"payload": "Never buying this again."}) | ||
assert response.status_code == 200 | ||
response_body = response.json() | ||
assert response_body["message"] == HTTPStatus.OK.phrase | ||
assert response_body["status-code"] == HTTPStatus.OK | ||
assert response_body["data"]["model-type"] == "RoBERTaSB" | ||
assert response_body["data"]["payload"] == "Never buying this again." | ||
assert response_body["data"]["prediction"] == "negative" | ||
with TestClient(app) as client: | ||
response = client.post("/models/", json={"msg": "Never buying this again."}) | ||
assert response.status_code == 200 | ||
response_body = response.json() | ||
assert response_body["message"] == HTTPStatus.OK.phrase | ||
assert response_body["status-code"] == HTTPStatus.OK | ||
assert response_body["data"]["model-type"] == "RoBERTaSB" | ||
assert response_body["data"]["payload"] == "Never buying this again." | ||
assert response_body["data"]["prediction"] == "negative" | ||
|
||
def test_bad_url(): | ||
with TestClient(app) as client: | ||
response = client.post("/mode", json={"msg": "Never buying this again."}) | ||
assert response.status_code == 404 | ||
|
||
def test_bad_request(): | ||
with TestClient(app) as client: | ||
response = client.post("/models/", json={"false": "Never buying this again."}) | ||
assert response.status_code == 422 |