File size: 1,922 Bytes
41d63dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from fastapi.testclient import TestClient
from main import app

client = TestClient(app)

def test_positive_sentiment():
    response = client.post("/analyze/", json={"text": "I'm thrilled with the results of this service!"})
    assert response.status_code == 200
    assert response.json() == {"sentiment": "joy"}

def test_negative_sentiment():
    response = client.post("/analyze/", json={"text": "What a disappointment! It didn't meet my expectations at all."})
    assert response.status_code == 200
    assert response.json() == {"sentiment": "anger"}

def test_neutral_sentiment():
    response = client.post("/analyze/", json={"text": "The product does exactly what it promises. Nothing more, nothing less."})
    assert response.status_code == 200
    assert response.json() == {"sentiment": "neutral"}

def test_anger_sentiment():
    response = client.post("/analyze/", json={"text": "This app is frustrating and annoying to use!"})
    assert response.status_code == 200
    assert response.json() == {"sentiment": "anger"}

def test_disgust_sentiment():
    response = client.post("/analyze/", json={"text": "The taste of this food is disgusting!"})
    assert response.status_code == 200
    assert response.json() == {"sentiment": "disgust"}

def test_fear_sentiment():
    response = client.post("/analyze/", json={"text": "I'm worried that this might be unsafe."})
    assert response.status_code == 200
    assert response.json() == {"sentiment": "fear"}

def test_sadness_sentiment():
    response = client.post("/analyze/", json={"text": "It's sad to see it perform so poorly."})
    assert response.status_code == 200
    assert response.json() == {"sentiment": "sadness"}

def test_surprise_sentiment():
    response = client.post("/analyze/", json={"text": "Wow, I didn't expect it to be this good!"})
    assert response.status_code == 200
    assert response.json() == {"sentiment": "surprise"}