Skip to content

Commit bbe8baa

Browse files
committed
test response map
1 parent c0c0cd8 commit bbe8baa

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

server_tests/test_cli.py

+5
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ def test_seed_email(runner):
1010
result: Result = runner.invoke(args=["seed", "email"])
1111
print(result.stdout)
1212
assert result.exit_code == 0
13+
14+
def test_seed_thread(runner):
15+
result: Result = runner.invoke(args=["seed", "thread"])
16+
print(result.stdout)
17+
assert result.exit_code == 0

server_tests/test_email.py

+28-7
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@
1010
def test_thread_first_sender(app: APIFlask):
1111
"""Test fetching the first thread."""
1212
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()
1914
earliest_email = min(thread.emails, key=lambda x: x.date)
2015
assert earliest_email.sender == thread.first_sender
2116

@@ -32,7 +27,7 @@ def test_get_threads(app: APIFlask, client: FlaskClient):
3227
thread = threads[0]
3328
thread_id = thread["id"]
3429
assert thread_id == 1
35-
assert not thread["resolved"] # resolved is false
30+
assert not thread["resolved"]
3631
assert len(thread["emailList"]) == 5
3732

3833
for email in thread["emailList"]:
@@ -44,3 +39,29 @@ def test_get_threads(app: APIFlask, client: FlaskClient):
4439
assert email["message_id"] is not None
4540
assert email["is_reply"] is not None
4641
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

Comments
 (0)