mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
Fix tests to handle updated response types by API
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# Standard Modules
|
||||
from pathlib import Path
|
||||
from io import BytesIO
|
||||
from PIL import Image
|
||||
|
||||
# External Packages
|
||||
from fastapi.testclient import TestClient
|
||||
@@ -94,18 +95,18 @@ def test_image_search(content_config: ContentConfig, search_config: SearchConfig
|
||||
config.content_type = content_config
|
||||
config.search_type = search_config
|
||||
model.image_search = image_search.setup(content_config.image, search_config.image, regenerate=False)
|
||||
query_expected_image_pairs = [("brown kitten next to fallen plant", "/static/0.jpg"), # kitten_park.jpg
|
||||
("a horse and dog on a leash", "static/1.jpg"), # horse_dog.jpg
|
||||
("A guinea pig eating grass", "static/2.jpg")] # guineapig_grass.jpg
|
||||
query_expected_image_pairs = [("kitten", "kitten_park.jpg"),
|
||||
("a horse and dog on a leash", "horse_dog.jpg"),
|
||||
("A guinea pig eating grass", "guineapig_grass.jpg")]
|
||||
|
||||
# Act
|
||||
for query, expected_image_name in query_expected_image_pairs:
|
||||
# Act
|
||||
response = client.get(f"/search?q={query}&n=1&t=image")
|
||||
|
||||
# Assert
|
||||
assert response.status_code == 200
|
||||
actual_image = Path(response.json()[0]["entry"])
|
||||
expected_image = Path(expected_image_name)
|
||||
actual_image = Image.open(BytesIO(client.get(response.json()[0]["entry"]).content))
|
||||
expected_image = Image.open(content_config.image.input_directories[0].joinpath(expected_image_name))
|
||||
|
||||
# Assert
|
||||
assert expected_image == actual_image
|
||||
@@ -123,7 +124,7 @@ def test_notes_search(content_config: ContentConfig, search_config: SearchConfig
|
||||
# Assert
|
||||
assert response.status_code == 200
|
||||
# assert actual_data contains "Khoj via Emacs" entry
|
||||
search_result = response.json()[0]["entry"]
|
||||
search_result = response.json()[0]["Entry"]
|
||||
assert "git clone" in search_result
|
||||
|
||||
|
||||
@@ -139,7 +140,7 @@ def test_notes_search_with_include_filter(content_config: ContentConfig, search_
|
||||
# Assert
|
||||
assert response.status_code == 200
|
||||
# assert actual_data contains explicitly included word "Emacs"
|
||||
search_result = response.json()[0]["entry"]
|
||||
search_result = response.json()[0]["Entry"]
|
||||
assert "Emacs" in search_result
|
||||
|
||||
|
||||
@@ -155,5 +156,5 @@ def test_notes_search_with_exclude_filter(content_config: ContentConfig, search_
|
||||
# Assert
|
||||
assert response.status_code == 200
|
||||
# assert actual_data does not contains explicitly excluded word "Emacs"
|
||||
search_result = response.json()[0]["entry"]
|
||||
search_result = response.json()[0]["Entry"]
|
||||
assert "clone" not in search_result
|
||||
|
||||
Reference in New Issue
Block a user