Spaces:
Runtime error
Runtime error
Delete test_main.py
Browse files- test_main.py +0 -70
test_main.py
DELETED
@@ -1,70 +0,0 @@
|
|
1 |
-
from fastapi.testclient import TestClient
|
2 |
-
from main import app
|
3 |
-
from main import TextInput
|
4 |
-
from fastapi.encoders import jsonable_encoder
|
5 |
-
|
6 |
-
client = TestClient(app)
|
7 |
-
|
8 |
-
# Test the welcome endpoint
|
9 |
-
def test_welcome():
|
10 |
-
# Test the welcome endpoint
|
11 |
-
response = client.get("/")
|
12 |
-
assert response.status_code == 200
|
13 |
-
assert response.json() == "Welcome to our Text Classification API"
|
14 |
-
|
15 |
-
# Test the sentiment analysis endpoint for positive sentiment
|
16 |
-
def test_positive_sentiment():
|
17 |
-
with client:
|
18 |
-
# Define the request payload
|
19 |
-
# Initialize payload as a TextInput object
|
20 |
-
payload = TextInput(text="I love this product! It's amazing!")
|
21 |
-
|
22 |
-
# Convert TextInput object to JSON-serializable dictionary
|
23 |
-
payload_dict = jsonable_encoder(payload)
|
24 |
-
|
25 |
-
# Send a POST request to the sentiment analysis endpoint
|
26 |
-
response = client.post("/analyze/{text}", json=payload_dict)
|
27 |
-
|
28 |
-
# Assert that the response status code is 200 OK
|
29 |
-
assert response.status_code == 200
|
30 |
-
|
31 |
-
# Assert that the sentiment returned is positive
|
32 |
-
assert response.json()[0]['label'] == "positive"
|
33 |
-
|
34 |
-
# Test the sentiment analysis endpoint for negative sentiment
|
35 |
-
def test_negative_sentiment():
|
36 |
-
with client:
|
37 |
-
# Define the request payload
|
38 |
-
# Initialize payload as a TextInput object
|
39 |
-
payload = TextInput(text="I'm really disappointed with this service. It's terrible.")
|
40 |
-
|
41 |
-
# Convert TextInput object to JSON-serializable dictionary
|
42 |
-
payload_dict = jsonable_encoder(payload)
|
43 |
-
|
44 |
-
# Send a POST request to the sentiment analysis endpoint
|
45 |
-
response = client.post("/analyze/{text}", json=payload_dict)
|
46 |
-
|
47 |
-
# Assert that the response status code is 200 OK
|
48 |
-
assert response.status_code == 200
|
49 |
-
|
50 |
-
# Assert that the sentiment returned is positive
|
51 |
-
assert response.json()[0]['label'] == "negative"
|
52 |
-
|
53 |
-
# Test the sentiment analysis endpoint for neutral sentiment
|
54 |
-
def test_neutral_sentiment():
|
55 |
-
with client:
|
56 |
-
# Define the request payload
|
57 |
-
# Initialize payload as a TextInput object
|
58 |
-
payload = TextInput(text="This is a neutral statement.")
|
59 |
-
|
60 |
-
# Convert TextInput object to JSON-serializable dictionary
|
61 |
-
payload_dict = jsonable_encoder(payload)
|
62 |
-
|
63 |
-
# Send a POST request to the sentiment analysis endpoint
|
64 |
-
response = client.post("/analyze/{text}", json=payload_dict)
|
65 |
-
|
66 |
-
# Assert that the response status code is 200 OK
|
67 |
-
assert response.status_code == 200
|
68 |
-
|
69 |
-
# Assert that the sentiment returned is positive
|
70 |
-
assert response.json()[0]['label'] == "neutral"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|