From bed3aff059b6de6ff8c6181d61928d1051368cf6 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Thu, 12 Oct 2023 16:16:51 -0700 Subject: [PATCH] Update tests to test multi-part/form method of pushing files to index Instead of using the previous method to push data as json payload of POST request pass it as files to upload via the multi-part/form to the batch indexer API endpoint --- tests/test_client.py | 50 +++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index 40a032f7..831668f7 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -62,11 +62,11 @@ def test_regenerate_with_invalid_content_type(client): # ---------------------------------------------------------------------------------------------------- def test_index_batch(client): # Arrange - request_body = get_sample_files_data() + files = get_sample_files_data() headers = {"x-api-key": "secret"} # Act - response = client.post("/api/v1/indexer/batch", json=request_body, headers=headers) + response = client.post("/api/v1/indexer/batch", files=files, headers=headers) # Assert assert response.status_code == 200 @@ -76,12 +76,11 @@ def test_index_batch(client): def test_regenerate_with_valid_content_type(client): for content_type in ["all", "org", "markdown", "image", "pdf", "notion", "plugin1"]: # Arrange - request_body = get_sample_files_data() - + files = get_sample_files_data() headers = {"x-api-key": "secret"} # Act - response = client.post(f"/api/v1/indexer/batch?search_type={content_type}", json=request_body, headers=headers) + response = client.post(f"/api/v1/indexer/batch?search_type={content_type}", files=files, headers=headers) # Assert assert response.status_code == 200, f"Returned status: {response.status_code} for content type: {content_type}" @@ -92,12 +91,11 @@ def test_regenerate_with_github_fails_without_pat(client): response = client.get(f"/api/update?force=true&t=github") # Arrange - request_body = get_sample_files_data() - + files = get_sample_files_data() headers = {"x-api-key": "secret"} # Act - response = client.post(f"/api/v1/indexer/batch?search_type=github", json=request_body, headers=headers) + response = client.post(f"/api/v1/indexer/batch?search_type=github", files=files, headers=headers) # Assert assert response.status_code == 200, f"Returned status: {response.status_code} for content type: github" @@ -288,24 +286,20 @@ def test_notes_search_with_exclude_filter( def get_sample_files_data(): return { - "org": { - "path/to/filename.org": "* practicing piano", - "path/to/filename1.org": "** top 3 reasons why I moved to SF", - "path/to/filename2.org": "* how to build a search engine", - }, - "pdf": { - "path/to/filename.pdf": "Moore's law does not apply to consumer hardware", - "path/to/filename1.pdf": "The sun is a ball of helium", - "path/to/filename2.pdf": "Effect of sunshine on baseline human happiness", - }, - "plaintext": { - "path/to/filename.txt": "data,column,value", - "path/to/filename1.txt": "my first web page", - "path/to/filename2.txt": "2021-02-02 Journal Entry", - }, - "markdown": { - "path/to/filename.md": "# Notes from client call", - "path/to/filename1.md": "## Studying anthropological records from the Fatimid caliphate", - "path/to/filename2.md": "**Understanding science through the lens of art**", - }, + "files": ("path/to/filename.org", "* practicing piano", "text/org"), + "files": ("path/to/filename1.org", "** top 3 reasons why I moved to SF", "text/org"), + "files": ("path/to/filename2.org", "* how to build a search engine", "text/org"), + "files": ("path/to/filename.pdf", "Moore's law does not apply to consumer hardware", "application/pdf"), + "files": ("path/to/filename1.pdf", "The sun is a ball of helium", "application/pdf"), + "files": ("path/to/filename2.pdf", "Effect of sunshine on baseline human happiness", "application/pdf"), + "files": ("path/to/filename.txt", "data,column,value", "text/plain"), + "files": ("path/to/filename1.txt", "my first web page", "text/plain"), + "files": ("path/to/filename2.txt", "2021-02-02 Journal Entry", "text/plain"), + "files": ("path/to/filename.md", "# Notes from client call", "text/markdown"), + "files": ( + "path/to/filename1.md", + "## Studying anthropological records from the Fatimid caliphate", + "text/markdown", + ), + "files": ("path/to/filename2.md", "**Understanding science through the lens of art**", "text/markdown"), }