10
10
def test_thread_first_sender (app : APIFlask ):
11
11
"""Test fetching the first thread."""
12
12
with app .app_context ():
13
- thread = (
14
- db .session .execute (
15
- select (Thread )
16
- )
17
- .scalar_one ()
18
- )
13
+ thread = db .session .execute (select (Thread )).scalar_one ()
19
14
earliest_email = min (thread .emails , key = lambda x : x .date )
20
15
assert earliest_email .sender == thread .first_sender
21
16
@@ -32,7 +27,7 @@ def test_get_threads(app: APIFlask, client: FlaskClient):
32
27
thread = threads [0 ]
33
28
thread_id = thread ["id" ]
34
29
assert thread_id == 1
35
- assert not thread ["resolved" ] # resolved is false
30
+ assert not thread ["resolved" ]
36
31
assert len (thread ["emailList" ]) == 5
37
32
38
33
for email in thread ["emailList" ]:
@@ -44,3 +39,29 @@ def test_get_threads(app: APIFlask, client: FlaskClient):
44
39
assert email ["message_id" ] is not None
45
40
assert email ["is_reply" ] is not None
46
41
assert email ["thread_id" ] == thread_id
42
+
43
+
44
+ def test_get_response (app : APIFlask , client : FlaskClient ):
45
+ """Test fetching a response."""
46
+ last_email_id = 5
47
+ response = client .post (
48
+ "/api/emails/get_response" , data = {"id" : last_email_id }
49
+ )
50
+ assert_status (response , 200 )
51
+
52
+ response = response .json
53
+ assert response is not None
54
+
55
+ # check that .map() is intact
56
+ assert response ["confidence" ] is not None
57
+ assert response ["content" ] is not None
58
+ assert response ["questions" ] is not None
59
+ assert response ["documents" ] is not None
60
+ assert response ["id" ] is not None
61
+ assert response ["emailId" ] is not None
62
+
63
+ for doc_list in response ["documents" ]:
64
+ for doc in doc_list :
65
+ assert doc ["confidence" ] is not None
66
+ assert doc ["content" ] is not None
67
+ assert doc ["source" ] is not None
0 commit comments