-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_main.py
More file actions
107 lines (79 loc) · 2.8 KB
/
test_main.py
File metadata and controls
107 lines (79 loc) · 2.8 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import json
from fastapi.testclient import TestClient
from main import app
client = TestClient(app)
def test_get_entity():
response = client.post(
"/entity_recognition",
headers={"content-type": "application/json"},
json={"sentence": "Bill Gates"},
)
assert response.status_code == 200
assert response.json() == {"output": [{"Text": "Bill Gates", "Start Char": 0, "End Char": 10, "Label": "PERSON"}]}
def test_get_entity_empty():
response = client.post(
"/entity_recognition",
headers={"content-type": "application/json"},
json={"sentence": None},
)
assert response.status_code == 422
def test_get_text_sentiment_neg():
response = client.post(
"/sentiment_analysis",
headers={"content-type": "application/json"},
json={"sentence": "I hate Chilis."},
)
f = open("jsonfiles/sentiment_negative.json", "r")
output = json.loads(f.read())
assert response.status_code == 200
assert response.json() == output
def test_get_text_sentiment_pos():
response = client.post(
"/sentiment_analysis",
headers={"content-type": "application/json"},
json={"sentence": "I love Chilis."},
)
f = open("jsonfiles/sentiment_positive.json", "r")
output = json.loads(f.read())
assert response.status_code == 200
assert response.json() == output
def test_get_text_sentiment_null():
response = client.post(
"/sentiment_analysis",
headers={"content-type": "application/json"},
json={"sentence": None},
)
assert response.status_code == 422
def test_get_text_analysis():
response = client.post(
"/analyze_text",
headers={"content-type": "application/json"},
json={"sentence": "John likes to ride bikes and eating pizza"},
)
f = open("jsonfiles/analyze_response.json", "r")
output = json.loads(f.read())
assert response.status_code == 200
assert response.json() == output
def test_get_text_analysis_failed():
response = client.post(
"/analyze_text",
headers={"content-type": "application/json"},
json={"sentence": None},
)
assert response.status_code == 422
def test_translate_to_french():
response = client.post(
"/translate_french",
headers={"content-type": "application/json"},
json={"sentence": "where is the nearest airport and coffee shop?"},
)
output = "Où sont l'aéroport et le café le plus proche?"
assert response.status_code == 200
assert response.json() == output
def test_generate_text():
response = client.post(
"/generate_text",
headers={"content-type": "application/json"},
json={"sentence": "text is too random, just testing status code"},
)
assert response.status_code == 200