mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
Setup Search with Search_Config to Fix Tests
- Rename pytest fixture search_config to more appropriate content_config - Create search_config pytest fixture - Use search_config where search being setup, used in tests
This commit is contained in:
@@ -9,7 +9,7 @@ import pytest
|
||||
from src.main import app, model, config
|
||||
from src.search_type import asymmetric, image_search
|
||||
from src.utils.helpers import resolve_absolute_path
|
||||
from src.utils.rawconfig import ContentTypeConfig
|
||||
from src.utils.rawconfig import ContentTypeConfig, SearchTypeConfig
|
||||
|
||||
|
||||
# Arrange
|
||||
@@ -18,55 +18,60 @@ client = TestClient(app)
|
||||
|
||||
# Test
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
def test_search_with_invalid_search_type():
|
||||
def test_search_with_invalid_content_type():
|
||||
# Arrange
|
||||
user_query = "How to call semantic search from Emacs?"
|
||||
|
||||
# Act
|
||||
response = client.get(f"/search?q={user_query}&t=invalid_search_type")
|
||||
response = client.get(f"/search?q={user_query}&t=invalid_content_type")
|
||||
|
||||
# Assert
|
||||
assert response.status_code == 422
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
def test_search_with_valid_search_type(search_config: ContentTypeConfig):
|
||||
def test_search_with_valid_content_type(content_config: ContentTypeConfig, search_config: SearchTypeConfig):
|
||||
# Arrange
|
||||
config.content_type = search_config
|
||||
config.content_type = content_config
|
||||
config.search_type = search_config
|
||||
|
||||
# config.content_type.image = search_config.image
|
||||
for search_type in ["notes", "ledger", "music", "image"]:
|
||||
for content_type in ["notes", "ledger", "music", "image"]:
|
||||
# Act
|
||||
response = client.get(f"/search?q=random&t={search_type}")
|
||||
response = client.get(f"/search?q=random&t={content_type}")
|
||||
# Assert
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
def test_regenerate_with_invalid_search_type():
|
||||
def test_regenerate_with_invalid_content_type():
|
||||
# Act
|
||||
response = client.get(f"/regenerate?t=invalid_search_type")
|
||||
response = client.get(f"/regenerate?t=invalid_content_type")
|
||||
|
||||
# Assert
|
||||
assert response.status_code == 422
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
def test_regenerate_with_valid_search_type(search_config: ContentTypeConfig):
|
||||
def test_regenerate_with_valid_content_type(content_config: ContentTypeConfig, search_config: SearchTypeConfig):
|
||||
# Arrange
|
||||
config.content_type = search_config
|
||||
for search_type in ["notes", "ledger", "music", "image"]:
|
||||
config.content_type = content_config
|
||||
config.search_type = search_config
|
||||
|
||||
for content_type in ["notes", "ledger", "music", "image"]:
|
||||
# Act
|
||||
response = client.get(f"/regenerate?t={search_type}")
|
||||
response = client.get(f"/regenerate?t={content_type}")
|
||||
# Assert
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
@pytest.mark.skip(reason="Flaky test. Search doesn't always return expected image path.")
|
||||
def test_image_search(search_config: ContentTypeConfig):
|
||||
def test_image_search(content_config: ContentTypeConfig, search_config: SearchTypeConfig):
|
||||
# Arrange
|
||||
config.content_type = search_config
|
||||
model.image_search = image_search.setup(search_config.image, regenerate=False)
|
||||
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", "kitten_park.jpg"),
|
||||
("a horse and dog on a leash", "horse_dog.jpg"),
|
||||
("A guinea pig eating grass", "guineapig_grass.jpg")]
|
||||
@@ -78,16 +83,16 @@ def test_image_search(search_config: ContentTypeConfig):
|
||||
# Assert
|
||||
assert response.status_code == 200
|
||||
actual_image = Path(response.json()[0]["Entry"])
|
||||
expected_image = resolve_absolute_path(search_config.image.input_directory.joinpath(expected_image_name))
|
||||
expected_image = resolve_absolute_path(content_config.image.input_directory.joinpath(expected_image_name))
|
||||
|
||||
# Assert
|
||||
assert expected_image == actual_image
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
def test_notes_search(search_config: ContentTypeConfig):
|
||||
def test_notes_search(content_config: ContentTypeConfig, search_config: SearchTypeConfig):
|
||||
# Arrange
|
||||
model.notes_search = asymmetric.setup(search_config.org, regenerate=False)
|
||||
model.notes_search = asymmetric.setup(content_config.org, search_config.asymmetric, regenerate=False)
|
||||
user_query = "How to git install application?"
|
||||
|
||||
# Act
|
||||
@@ -101,9 +106,9 @@ def test_notes_search(search_config: ContentTypeConfig):
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
def test_notes_search_with_include_filter(search_config: ContentTypeConfig):
|
||||
def test_notes_search_with_include_filter(content_config: ContentTypeConfig, search_config: SearchTypeConfig):
|
||||
# Arrange
|
||||
model.notes_search = asymmetric.setup(search_config.org, regenerate=False)
|
||||
model.notes_search = asymmetric.setup(content_config.org, search_config.asymmetric, regenerate=False)
|
||||
user_query = "How to git install application? +Emacs"
|
||||
|
||||
# Act
|
||||
@@ -117,9 +122,9 @@ def test_notes_search_with_include_filter(search_config: ContentTypeConfig):
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
def test_notes_search_with_exclude_filter(search_config: ContentTypeConfig):
|
||||
def test_notes_search_with_exclude_filter(content_config: ContentTypeConfig, search_config: SearchTypeConfig):
|
||||
# Arrange
|
||||
model.notes_search = asymmetric.setup(search_config.org, regenerate=False)
|
||||
model.notes_search = asymmetric.setup(content_config.org, search_config.asymmetric, regenerate=False)
|
||||
user_query = "How to git install application? -clone"
|
||||
|
||||
# Act
|
||||
|
||||
Reference in New Issue
Block a user