mirror of
https://github.com/StanGirard/quivr.git
synced 2024-11-23 12:26:03 +03:00
test(all): added (#1624)
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
This commit is contained in:
parent
8ed0adf7b2
commit
5a3f284785
@ -34,4 +34,4 @@ async def process_file(
|
||||
brain_id, doc_with_metadata.to_json(), user_openai_api_key, file.file_sha1
|
||||
)
|
||||
|
||||
return
|
||||
return "Hello World!"
|
||||
|
@ -38,4 +38,5 @@ botocore==1.31.46
|
||||
celery[sqs]
|
||||
python-dotenv
|
||||
pytest-mock
|
||||
pytest-celery
|
||||
|
||||
|
@ -214,3 +214,63 @@ def test_set_as_default_brain_endpoint(client, api_key):
|
||||
default_brain = get_user_default_brain(user_id)
|
||||
assert default_brain is not None
|
||||
assert str(default_brain.brain_id) == str(brain_id)
|
||||
|
||||
|
||||
def create_public_brain_retrieve_and_then_delete(client, api_key):
|
||||
# Generate a random name for the brain
|
||||
random_brain_name = "".join(
|
||||
random.choices(string.ascii_letters + string.digits, k=10)
|
||||
)
|
||||
|
||||
# Set up the request payload
|
||||
payload = {
|
||||
"name": random_brain_name,
|
||||
"status": "public",
|
||||
"model": "gpt-3.5-turbo",
|
||||
"temperature": 0,
|
||||
"max_tokens": 256,
|
||||
"brain_type": "doc",
|
||||
}
|
||||
|
||||
# Making a POST request to the /brains/ endpoint
|
||||
response = client.post(
|
||||
"/brains/",
|
||||
json=payload,
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
)
|
||||
|
||||
# Assert that the response status code is 200 (HTTP OK)
|
||||
assert response.status_code == 200
|
||||
|
||||
# Optionally, assert on specific fields in the response
|
||||
response_data = response.json()
|
||||
# e.g., assert that the response contains a 'brain_id' field
|
||||
assert "id" in response_data
|
||||
assert "name" in response_data
|
||||
|
||||
# Optionally, assert that the returned 'name' matches the one sent in the request
|
||||
assert response_data["name"] == payload["name"]
|
||||
|
||||
# Now, retrieve all brains for the current user
|
||||
response = client.get(
|
||||
"/brains/public",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
)
|
||||
|
||||
# Assert that the response status code is 200 (HTTP OK)
|
||||
assert response.status_code == 200
|
||||
assert len(response.json()["brains"]) > 0
|
||||
|
||||
# Check brain is in public list
|
||||
brain_id = response_data["id"]
|
||||
public_brains = response.json()["brains"]
|
||||
assert brain_id in [brain["id"] for brain in public_brains]
|
||||
|
||||
# Delete the brain
|
||||
response = client.delete(
|
||||
f"/brains/{brain_id}/subscription",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
)
|
||||
|
||||
# Assert that the DELETE response status code is 200 (HTTP OK)
|
||||
assert response.status_code == 200
|
||||
|
@ -114,3 +114,19 @@ def test_create_chat_and_talk_with_no_brain(client, api_key):
|
||||
"/chat/" + chat_id, headers={"Authorization": "Bearer " + api_key}
|
||||
)
|
||||
assert delete_response.status_code == 200
|
||||
|
||||
|
||||
# Test delete all chats for a user
|
||||
def test_delete_all_chats(client, api_key):
|
||||
chats = client.get("/chat", headers={"Authorization": "Bearer " + api_key})
|
||||
assert chats.status_code == 200
|
||||
chats_data = chats.json()
|
||||
for chat in chats_data["chats"]:
|
||||
# e.g., assert that each chat object contains 'chat_id' and 'chat_name'
|
||||
assert "chat_id" in chat
|
||||
assert "chat_name" in chat
|
||||
chat_id = chat["chat_id"]
|
||||
delete_response = client.delete(
|
||||
"/chat/" + chat_id, headers={"Authorization": "Bearer " + api_key}
|
||||
)
|
||||
assert delete_response.status_code == 200
|
||||
|
13
backend/tests/test_notification.py
Normal file
13
backend/tests/test_notification.py
Normal file
@ -0,0 +1,13 @@
|
||||
def test_get_notifications(client, api_key):
|
||||
# Send a request to get notifications
|
||||
response = client.get(
|
||||
"/notifications/ab780686-bcf3-46cb-9068-d724628caccd",
|
||||
headers={"Authorization": "Bearer " + api_key},
|
||||
)
|
||||
|
||||
# Assert that the response status code is 200 (HTTP OK)
|
||||
assert response.status_code == 200
|
||||
|
||||
# Assert that the response contains the expected fields
|
||||
notifications = response.json()
|
||||
assert notifications == []
|
@ -16,3 +16,20 @@ def test_get_user_info(client, api_key):
|
||||
assert "models" in user_info
|
||||
assert "requests_stats" in user_info
|
||||
assert "id" in user_info
|
||||
|
||||
|
||||
def test_get_user_identity(client, api_key):
|
||||
# Send a request to get user identity
|
||||
response = client.get(
|
||||
"/user/identity", headers={"Authorization": "Bearer " + api_key}
|
||||
)
|
||||
|
||||
# Assert that the response status code is 200 (HTTP OK)
|
||||
assert response.status_code == 200
|
||||
|
||||
# Assert that the response contains the expected fields
|
||||
user_identity = response.json()
|
||||
print(user_identity)
|
||||
assert "id" in user_identity
|
||||
assert "email" in user_identity
|
||||
assert "openai_api_key" in user_identity
|
||||
|
Loading…
Reference in New Issue
Block a user