@@ -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+
407520def 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