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
|
import requests
from flask.testing import FlaskClient
def test_chat_rag(logged_in: FlaskClient, mocker, clean_mongo):
result = requests.Response()
result.status_code = 200
result.json = lambda: {"choices": [{"message": {"role": "assistant", "content": "This is a test response."}}]} # type: ignore
mocker.patch("sec_certs_page.chat.views.chat_rag", return_value=result)
resp = logged_in.post(
"/chat/rag/",
json={
"query": [{"role": "user", "content": "What is this a certificate of?"}],
"about": "entry",
"collection": "cc",
"hashid": "3d1b01ce576f605d",
},
)
assert resp.status_code == 200
assert resp.json["status"] == "ok"
assert "This is a test response." in resp.json["response"]
def test_chat_full(logged_in: FlaskClient, mocker, clean_mongo):
result = requests.Response()
result.status_code = 200
result.json = lambda: {"choices": [{"message": {"role": "assistant", "content": "This is a test response."}}]} # type: ignore
mocker.patch("sec_certs_page.chat.views.chat_full", return_value=result)
resp = logged_in.post(
"/chat/full/",
json={
"query": [{"role": "user", "content": "What is this a certificate of?"}],
"context": "both",
"collection": "cc",
"hashid": "3d1b01ce576f605d",
},
)
assert resp.status_code == 200
assert resp.json["status"] == "ok"
assert "This is a test response." in resp.json["response"]
def test_chat_limit(logged_in: FlaskClient, mocker, clean_mongo):
result = requests.Response()
result.status_code = 200
result.json = lambda: {"choices": [{"message": {"role": "assistant", "content": "This is a test response."}}]} # type: ignore
mocker.patch("sec_certs_page.chat.views.chat_full", return_value=result)
for i in range(100):
resp = logged_in.post(
"/chat/full/",
json={
"query": [{"role": "user", "content": "What is this a certificate of?"}],
"context": "both",
"collection": "cc",
"hashid": "3d1b01ce576f605d",
},
)
assert resp.status_code == 200
resp = logged_in.post(
"/chat/full/",
json={
"query": [{"role": "user", "content": "What is this a certificate of?"}],
"context": "both",
"collection": "cc",
"hashid": "3d1b01ce576f605d",
},
)
assert resp.status_code == 429
assert resp.json["status"] == "error"
assert "You have reached the request limit of 100 requests" in resp.json["message"]
|