Skip to content

Commit f9a04ff

Browse files
committed
test(backend): added csv and pdf upload
1 parent 488e033 commit f9a04ff

File tree

7 files changed

+135
-5
lines changed

7 files changed

+135
-5
lines changed

backend/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
app = FastAPI()
3131

3232
add_cors_middleware(app)
33-
max_brain_size = os.getenv("MAX_BRAIN_SIZE")
33+
max_brain_size = os.getenv("MAX_BRAIN_SIZE", 52428800)
3434
max_brain_size_with_own_key = os.getenv("MAX_BRAIN_SIZE_WITH_KEY", 209715200)
3535

3636

backend/models/brains.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Brain(BaseModel):
1818
model: Optional[str] = "gpt-3.5-turbo-0613"
1919
temperature: Optional[float] = 0.0
2020
max_tokens: Optional[int] = 256
21-
max_brain_size: Optional[int] = int(os.getenv("MAX_BRAIN_SIZE", 0))
21+
max_brain_size: Optional[int] = int(os.getenv("MAX_BRAIN_SIZE",52428800))
2222
files: List[Any] = []
2323

2424
class Config:

backend/routes/user_routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async def get_user_endpoint(
3232
information about the user's API usage.
3333
"""
3434

35-
max_brain_size = int(os.getenv("MAX_BRAIN_SIZE", 0))
35+
max_brain_size = int(os.getenv("MAX_BRAIN_SIZE", 52428800))
3636
if request.headers.get("Openai-Api-Key"):
3737
max_brain_size = MAX_BRAIN_SIZE_WITH_OWN_KEY
3838

backend/test_file/test.csv

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
StanGirard/quivr,Sat May 13 2023 02:20:09 GMT+0200 (heure d’été d’Europe centrale),0
2+
StanGirard/quivr,Tue May 16 2023 18:03:49 GMT+0200 (heure d’été d’Europe centrale),660
3+
StanGirard/quivr,Thu May 18 2023 03:04:23 GMT+0200 (heure d’été d’Europe centrale),1380
4+
StanGirard/quivr,Thu May 18 2023 23:04:11 GMT+0200 (heure d’été d’Europe centrale),2070
5+
StanGirard/quivr,Sat May 20 2023 04:44:40 GMT+0200 (heure d’été d’Europe centrale),2790
6+
StanGirard/quivr,Sun May 21 2023 03:19:46 GMT+0200 (heure d’été d’Europe centrale),3510
7+
StanGirard/quivr,Mon May 22 2023 08:03:18 GMT+0200 (heure d’été d’Europe centrale),4230
8+
StanGirard/quivr,Tue May 23 2023 16:57:58 GMT+0200 (heure d’été d’Europe centrale),4950
9+
StanGirard/quivr,Sat May 27 2023 02:18:31 GMT+0200 (heure d’été d’Europe centrale),5640
10+
StanGirard/quivr,Thu Jun 01 2023 18:45:27 GMT+0200 (heure d’été d’Europe centrale),6360
11+
StanGirard/quivr,Thu Jun 08 2023 16:33:57 GMT+0200 (heure d’été d’Europe centrale),7080
12+
StanGirard/quivr,Mon Jun 19 2023 12:58:34 GMT+0200 (heure d’été d’Europe centrale),7800
13+
StanGirard/quivr,Tue Jun 27 2023 14:45:52 GMT+0200 (heure d’été d’Europe centrale),8520
14+
StanGirard/quivr,Fri Jun 30 2023 11:43:51 GMT+0200 (heure d’été d’Europe centrale),9210
15+
StanGirard/quivr,Fri Jul 07 2023 23:08:23 GMT+0200 (heure d’été d’Europe centrale),9930
16+
StanGirard/quivr,Mon Jul 10 2023 08:13:07 GMT+0200 (heure d’été d’Europe centrale),10650
17+
StanGirard/quivr,Wed Jul 12 2023 09:40:29 GMT+0200 (heure d’été d’Europe centrale),13837

backend/test_file/test.pdf

10.4 KB
Binary file not shown.
File renamed without changes.

backend/test_main.py

Lines changed: 115 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def test_upload_and_delete_file():
314314
default_brain_id = brain_response.json()["brain_id"]
315315

316316
# File to upload
317-
file_path = "test.txt"
317+
file_path = "test_file/test.txt"
318318
file_name = "test.txt" # Assuming the name of the file on the server is the same as the local file name
319319

320320
# Set enable_summarization flag
@@ -359,7 +359,7 @@ def test_upload_explore_and_delete_file():
359359
default_brain_id = brain_response.json()["brain_id"]
360360

361361
# File to upload
362-
file_path = "test.txt"
362+
file_path = "test_file/test.txt"
363363
file_name = "test.txt" # Assuming the name of the file on the server is the same as the local file name
364364

365365
# Set enable_summarization flag
@@ -404,6 +404,119 @@ def test_upload_explore_and_delete_file():
404404
assert "message" in delete_response_data
405405

406406

407+
def test_upload_explore_and_delete_file_pdf():
408+
# Retrieve the default brain
409+
brain_response = client.get(
410+
"/brains/default", headers={"Authorization": "Bearer " + API_KEY}
411+
)
412+
assert brain_response.status_code == 200
413+
default_brain_id = brain_response.json()["brain_id"]
414+
415+
# File to upload
416+
file_path = "test_file/test.pdf"
417+
file_name = "test.pdf" # Assuming the name of the file on the server is the same as the local file name
418+
419+
# Set enable_summarization flag
420+
enable_summarization = False
421+
422+
# Upload the file
423+
with open(file_path, "rb") as file:
424+
upload_response = client.post(
425+
f"/upload?brain_id={default_brain_id}&enable_summarization={enable_summarization}",
426+
headers={"Authorization": "Bearer " + API_KEY},
427+
files={"uploadFile": file},
428+
)
429+
430+
# Assert that the upload response status code is 200 (HTTP OK)
431+
assert upload_response.status_code == 200
432+
# assert it starts with File uploaded successfully:
433+
assert upload_response.json()["message"].startswith("File uploaded successfully:")
434+
# show message if it fails
435+
if not upload_response.json()["message"].startswith("File uploaded successfully:"):
436+
print(upload_response.json()["message"])
437+
438+
# Optionally, you can assert on specific fields in the upload response data
439+
upload_response_data = upload_response.json()
440+
assert "message" in upload_response_data
441+
442+
# Explore (Download) the file
443+
explore_response = client.get(
444+
f"/explore/{file_name}",
445+
headers={"Authorization": "Bearer " + API_KEY},
446+
)
447+
448+
# Assert that the explore response status code is 200 (HTTP OK)
449+
assert explore_response.status_code == 200
450+
451+
# Delete the file
452+
delete_response = client.delete(
453+
f"/explore/{file_name}",
454+
headers={"Authorization": "Bearer " + API_KEY},
455+
params={"brain_id": default_brain_id},
456+
)
457+
458+
# Assert that the delete response status code is 200 (HTTP OK)
459+
assert delete_response.status_code == 200
460+
461+
# Optionally, you can assert on specific fields in the delete response data
462+
delete_response_data = delete_response.json()
463+
assert "message" in delete_response_data
464+
465+
466+
def test_upload_explore_and_delete_file_csv():
467+
# Retrieve the default brain
468+
brain_response = client.get(
469+
"/brains/default", headers={"Authorization": "Bearer " + API_KEY}
470+
)
471+
assert brain_response.status_code == 200
472+
default_brain_id = brain_response.json()["brain_id"]
473+
474+
# File to upload
475+
file_path = "test_file/test.csv"
476+
file_name = "test.csv" # Assuming the name of the file on the server is the same as the local file name
477+
478+
# Set enable_summarization flag
479+
enable_summarization = False
480+
481+
# Upload the file
482+
with open(file_path, "rb") as file:
483+
upload_response = client.post(
484+
f"/upload?brain_id={default_brain_id}&enable_summarization={enable_summarization}",
485+
headers={"Authorization": "Bearer " + API_KEY},
486+
files={"uploadFile": file},
487+
)
488+
489+
# Assert that the upload response status code is 200 (HTTP OK)
490+
assert upload_response.status_code == 200
491+
492+
# Optionally, you can assert on specific fields in the upload response data
493+
upload_response_data = upload_response.json()
494+
assert "message" in upload_response_data
495+
496+
# Explore (Download) the file
497+
explore_response = client.get(
498+
f"/explore/{file_name}",
499+
headers={"Authorization": "Bearer " + API_KEY},
500+
)
501+
502+
# Assert that the explore response status code is 200 (HTTP OK)
503+
assert explore_response.status_code == 200
504+
505+
# Delete the file
506+
delete_response = client.delete(
507+
f"/explore/{file_name}",
508+
headers={"Authorization": "Bearer " + API_KEY},
509+
params={"brain_id": default_brain_id},
510+
)
511+
512+
# Assert that the delete response status code is 200 (HTTP OK)
513+
assert delete_response.status_code == 200
514+
515+
# Optionally, you can assert on specific fields in the delete response data
516+
delete_response_data = delete_response.json()
517+
assert "message" in delete_response_data
518+
519+
407520
def test_get_user_info():
408521
# Send a request to get user information
409522
response = client.get("/user", headers={"Authorization": "Bearer " + API_KEY})

0 commit comments

Comments
 (0)