Kotta commited on
Commit
71ddbd0
·
1 Parent(s): 8f051f8

feature(#85): Implement FastApi Unit Test For Api Endpoints

Browse files
Files changed (1) hide show
  1. Brain/tests/functional/test_api.py +211 -0
Brain/tests/functional/test_api.py ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi.testclient import TestClient
2
+ import pytest
3
+
4
+ from app import app
5
+
6
+ client = TestClient(app)
7
+
8
+
9
+ @pytest.mark.parametrize(
10
+ "body",
11
+ [
12
+ (
13
+ {
14
+ "confs": {
15
+ "openai_key": "",
16
+ "pinecone_key": "",
17
+ "pinecone_env": "",
18
+ "firebase_key": "",
19
+ "settings": {"temperature": 0.6},
20
+ "token": "eSyP3i7ITZuq8hWn2qutTl:APA91bH1FtWkaTSJwuX4WKWAl3Q-ZFyrOw4UtMP4IfwuvNrHOThH7EvEGIhtguilLRyQNlLiXatEN0xntHAc8bbKobSGjge3wxIHlspbIWY_855CzONqaVdl3y3zOmgKZNnuhYi4gwbh",
21
+ "uuid": "c40a09075d11940f",
22
+ },
23
+ "message": "Please search an image that shows Brown Teddy Bear",
24
+ }
25
+ )
26
+ ],
27
+ )
28
+ def test_send_notificatoin(body):
29
+ response = client.post("/sendNotification", json=body)
30
+ assert response.status_code == 200
31
+
32
+
33
+ @pytest.mark.parametrize(
34
+ "body",
35
+ [
36
+ (
37
+ {
38
+ "image_name": "0ddffe51-3763-48d9-ab74-2086de529217",
39
+ "confs": {
40
+ "token": "eSyP3i7ITZuq8hWn2qutTl:APA91bH1FtWkaTSJwuX4WKWAl3Q-ZFyrOw4UtMP4IfwuvNrHOThH7EvEGIhtguilLRyQNlLiXatEN0xntHAc8bbKobSGjge3wxIHlspbIWY_855CzONqaVdl3y3zOmgKZNnuhYi4gwbh",
41
+ "uuid": "test-uuid",
42
+ "openai_key": "",
43
+ "pinecone_key": "",
44
+ "pinecone_env": "",
45
+ "firebase_key": "",
46
+ "settings": {"temperature": 0.6},
47
+ },
48
+ "status": "updated",
49
+ }
50
+ )
51
+ ],
52
+ )
53
+ def test_upload_image(body):
54
+ response = client.post("/uploadImage", json=body)
55
+ assert response.status_code == 200
56
+
57
+
58
+ @pytest.mark.parametrize(
59
+ "body",
60
+ [
61
+ (
62
+ {
63
+ "image_name": "0ddffe51-3763-48d9-ab74-2086de529217",
64
+ "message": "This is the text about the image",
65
+ "confs": {
66
+ "token": "eSyP3i7ITZuq8hWn2qutTl:APA91bH1FtWkaTSJwuX4WKWAl3Q-ZFyrOw4UtMP4IfwuvNrHOThH7EvEGIhtguilLRyQNlLiXatEN0xntHAc8bbKobSGjge3wxIHlspbIWY_855CzONqaVdl3y3zOmgKZNnuhYi4gwbh",
67
+ "uuid": "test-uuid",
68
+ "openai_key": "",
69
+ "pinecone_key": "",
70
+ "pinecone_env": "",
71
+ "firebase_key": "",
72
+ "settings": {"temperature": 0.6},
73
+ },
74
+ }
75
+ )
76
+ ],
77
+ )
78
+ def test_image_relatedness(body):
79
+ response = client.post("/image_relatedness", json=body)
80
+ assert response.status_code == 200
81
+
82
+
83
+ @pytest.mark.parametrize(
84
+ "body",
85
+ [
86
+ (
87
+ {
88
+ "prompt": {"image_name": "test_image", "message": "test_message"},
89
+ "completion": {"image_name": "test_image", "message": "test_message"},
90
+ "rating": 1,
91
+ "confs": {
92
+ "token": "eSyP3i7ITZuq8hWn2qutTl:APA91bH1FtWkaTSJwuX4WKWAl3Q-ZFyrOw4UtMP4IfwuvNrHOThH7EvEGIhtguilLRyQNlLiXatEN0xntHAc8bbKobSGjge3wxIHlspbIWY_855CzONqaVdl3y3zOmgKZNnuhYi4gwbh",
93
+ "uuid": "test-uuid",
94
+ "openai_key": "",
95
+ "pinecone_key": "",
96
+ "pinecone_env": "",
97
+ "firebase_key": "",
98
+ "settings": {"temperature": 0.6},
99
+ },
100
+ }
101
+ )
102
+ ],
103
+ )
104
+ def test_feedback(body):
105
+ response = client.post("/feedback", json=body)
106
+ assert response.status_code == 200
107
+
108
+
109
+ @pytest.mark.parametrize(
110
+ "body",
111
+ [
112
+ (
113
+ {
114
+ "confs": {
115
+ "openai_key": "",
116
+ "pinecone_key": "",
117
+ "pinecone_env": "",
118
+ "firebase_key": "",
119
+ "settings": {"temperature": 0.6},
120
+ }
121
+ }
122
+ )
123
+ ],
124
+ )
125
+ def test_feedback(body):
126
+ response = client.post("/feedback/test/1", json=body)
127
+ assert response.status_code == 200
128
+
129
+
130
+ @pytest.mark.parametrize(
131
+ "body",
132
+ [
133
+ (
134
+ {
135
+ "confs": {
136
+ "openai_key": "",
137
+ "pinecone_key": "",
138
+ "pinecone_env": "",
139
+ "firebase_key": "",
140
+ "settings": {"temperature": 0.6},
141
+ }
142
+ }
143
+ )
144
+ ],
145
+ )
146
+ def test_commands(body):
147
+ response = client.post("/commands", json=body)
148
+ assert response.status_code == 200
149
+
150
+
151
+ @pytest.mark.parametrize(
152
+ "body",
153
+ [
154
+ (
155
+ {
156
+ "history": [
157
+ {"role": "system", "content": "You are a helpful assistant."},
158
+ {"role": "user", "content": "Who won the world series in 2020?"},
159
+ {
160
+ "role": "assistant",
161
+ "content": "The Los Angeles Dodgers won the World Series in 2020.",
162
+ },
163
+ ],
164
+ "user_input": "Where was it played?",
165
+ "confs": {
166
+ "token": "test_token",
167
+ "uuid": "test_uuid",
168
+ "openai_key": "",
169
+ "pinecone_key": "",
170
+ "pinecone_env": "",
171
+ "firebase_key": "",
172
+ "settings": {"temperature": 0.6},
173
+ },
174
+ }
175
+ )
176
+ ],
177
+ )
178
+ def test_chat_rising(body):
179
+ response = client.post("/chat_rising", json=body)
180
+ assert response.status_code == 200
181
+
182
+
183
+ @pytest.mark.parametrize(
184
+ "body",
185
+ [
186
+ (
187
+ {
188
+ "contacts": [
189
+ {
190
+ "contactId": "1",
191
+ "displayName": "Thomas",
192
+ "phoneNumbers": ["217 374 8105"],
193
+ "status": "updated",
194
+ }
195
+ ],
196
+ "confs": {
197
+ "token": "test_token",
198
+ "uuid": "test-uuid",
199
+ "openai_key": "",
200
+ "pinecone_key": "",
201
+ "pinecone_env": "",
202
+ "firebase_key": "",
203
+ "settings": {"temperature": 0.6},
204
+ },
205
+ }
206
+ )
207
+ ],
208
+ )
209
+ def test_train_contacts(body):
210
+ response = client.post("/train/contacts", json=body)
211
+ assert response.status_code == 200