mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 08:04:21 +00:00
Fix tests to handle updated response types by API
This commit is contained in:
parent
bdc1b9f2bb
commit
c9ff97451b
2 changed files with 22 additions and 15 deletions
|
@ -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
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
# Standard Modules
|
||||
from pathlib import Path
|
||||
from PIL import Image
|
||||
|
||||
# External Packages
|
||||
import pytest
|
||||
|
||||
# Internal Packages
|
||||
from src.main import model
|
||||
from src.main import model, web_directory
|
||||
from src.search_type import image_search
|
||||
from src.utils.helpers import resolve_absolute_path
|
||||
from src.utils.rawconfig import ContentConfig, SearchConfig
|
||||
|
@ -24,8 +28,9 @@ def test_image_search_setup(content_config: ContentConfig, search_config: Search
|
|||
@pytest.mark.skip(reason="results inconsistent currently")
|
||||
def test_image_search(content_config: ContentConfig, search_config: SearchConfig):
|
||||
# Arrange
|
||||
output_directory = resolve_absolute_path(web_directory)
|
||||
model.image_search = image_search.setup(content_config.image, search_config.image, regenerate=False)
|
||||
query_expected_image_pairs = [("brown kitten next to plant", "kitten_park.jpg"),
|
||||
query_expected_image_pairs = [("kitten", "kitten_park.jpg"),
|
||||
("horse and dog in a farm", "horse_dog.jpg"),
|
||||
("A guinea pig eating grass", "guineapig_grass.jpg")]
|
||||
|
||||
|
@ -39,11 +44,12 @@ def test_image_search(content_config: ContentConfig, search_config: SearchConfig
|
|||
results = image_search.collate_results(
|
||||
hits,
|
||||
model.image_search.image_names,
|
||||
content_config.image.input_directory,
|
||||
output_directory=output_directory,
|
||||
static_files_url='/static',
|
||||
count=1)
|
||||
|
||||
actual_image = results[0]["Entry"]
|
||||
expected_image = resolve_absolute_path(content_config.image.input_directory.joinpath(expected_image_name))
|
||||
actual_image = Image.open(output_directory.joinpath(Path(results[0]["entry"]).name))
|
||||
expected_image = Image.open(content_config.image.input_directories[0].joinpath(expected_image_name))
|
||||
|
||||
# Assert
|
||||
assert expected_image == actual_image
|
||||
|
|
Loading…
Add table
Reference in a new issue