mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
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
This commit is contained in:
parent
fc99431754
commit
bed3aff059
1 changed files with 22 additions and 28 deletions
|
@ -62,11 +62,11 @@ def test_regenerate_with_invalid_content_type(client):
|
||||||
# ----------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------
|
||||||
def test_index_batch(client):
|
def test_index_batch(client):
|
||||||
# Arrange
|
# Arrange
|
||||||
request_body = get_sample_files_data()
|
files = get_sample_files_data()
|
||||||
headers = {"x-api-key": "secret"}
|
headers = {"x-api-key": "secret"}
|
||||||
|
|
||||||
# Act
|
# 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
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
@ -76,12 +76,11 @@ def test_index_batch(client):
|
||||||
def test_regenerate_with_valid_content_type(client):
|
def test_regenerate_with_valid_content_type(client):
|
||||||
for content_type in ["all", "org", "markdown", "image", "pdf", "notion", "plugin1"]:
|
for content_type in ["all", "org", "markdown", "image", "pdf", "notion", "plugin1"]:
|
||||||
# Arrange
|
# Arrange
|
||||||
request_body = get_sample_files_data()
|
files = get_sample_files_data()
|
||||||
|
|
||||||
headers = {"x-api-key": "secret"}
|
headers = {"x-api-key": "secret"}
|
||||||
|
|
||||||
# Act
|
# 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
|
||||||
assert response.status_code == 200, f"Returned status: {response.status_code} for content type: {content_type}"
|
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")
|
response = client.get(f"/api/update?force=true&t=github")
|
||||||
|
|
||||||
# Arrange
|
# Arrange
|
||||||
request_body = get_sample_files_data()
|
files = get_sample_files_data()
|
||||||
|
|
||||||
headers = {"x-api-key": "secret"}
|
headers = {"x-api-key": "secret"}
|
||||||
|
|
||||||
# Act
|
# 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
|
||||||
assert response.status_code == 200, f"Returned status: {response.status_code} for content type: github"
|
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():
|
def get_sample_files_data():
|
||||||
return {
|
return {
|
||||||
"org": {
|
"files": ("path/to/filename.org", "* practicing piano", "text/org"),
|
||||||
"path/to/filename.org": "* practicing piano",
|
"files": ("path/to/filename1.org", "** top 3 reasons why I moved to SF", "text/org"),
|
||||||
"path/to/filename1.org": "** top 3 reasons why I moved to SF",
|
"files": ("path/to/filename2.org", "* how to build a search engine", "text/org"),
|
||||||
"path/to/filename2.org": "* how to build a search engine",
|
"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"),
|
||||||
"pdf": {
|
"files": ("path/to/filename2.pdf", "Effect of sunshine on baseline human happiness", "application/pdf"),
|
||||||
"path/to/filename.pdf": "Moore's law does not apply to consumer hardware",
|
"files": ("path/to/filename.txt", "data,column,value", "text/plain"),
|
||||||
"path/to/filename1.pdf": "The sun is a ball of helium",
|
"files": ("path/to/filename1.txt", "<html>my first web page</html>", "text/plain"),
|
||||||
"path/to/filename2.pdf": "Effect of sunshine on baseline human happiness",
|
"files": ("path/to/filename2.txt", "2021-02-02 Journal Entry", "text/plain"),
|
||||||
},
|
"files": ("path/to/filename.md", "# Notes from client call", "text/markdown"),
|
||||||
"plaintext": {
|
"files": (
|
||||||
"path/to/filename.txt": "data,column,value",
|
"path/to/filename1.md",
|
||||||
"path/to/filename1.txt": "<html>my first web page</html>",
|
"## Studying anthropological records from the Fatimid caliphate",
|
||||||
"path/to/filename2.txt": "2021-02-02 Journal Entry",
|
"text/markdown",
|
||||||
},
|
),
|
||||||
"markdown": {
|
"files": ("path/to/filename2.md", "**Understanding science through the lens of art**", "text/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**",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue