mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 08:04:21 +00:00
Use client pytest fixture to test API with plugin type configured
This commit is contained in:
parent
ab501a56c9
commit
88a9eadfba
1 changed files with 15 additions and 36 deletions
|
@ -10,7 +10,7 @@ from fastapi.testclient import TestClient
|
||||||
# Internal Packages
|
# Internal Packages
|
||||||
from khoj.main import app
|
from khoj.main import app
|
||||||
from khoj.configure import configure_routes
|
from khoj.configure import configure_routes
|
||||||
from khoj.utils.state import model, config
|
from khoj.utils.state import model
|
||||||
from khoj.search_type import text_search, image_search
|
from khoj.search_type import text_search, image_search
|
||||||
from khoj.utils.rawconfig import ContentConfig, SearchConfig
|
from khoj.utils.rawconfig import ContentConfig, SearchConfig
|
||||||
from khoj.processor.org_mode.org_to_jsonl import OrgToJsonl
|
from khoj.processor.org_mode.org_to_jsonl import OrgToJsonl
|
||||||
|
@ -18,15 +18,9 @@ from khoj.search_filter.word_filter import WordFilter
|
||||||
from khoj.search_filter.file_filter import FileFilter
|
from khoj.search_filter.file_filter import FileFilter
|
||||||
|
|
||||||
|
|
||||||
# Arrange
|
|
||||||
# ----------------------------------------------------------------------------------------------------
|
|
||||||
configure_routes(app)
|
|
||||||
client = TestClient(app)
|
|
||||||
|
|
||||||
|
|
||||||
# Test
|
# Test
|
||||||
# ----------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------
|
||||||
def test_search_with_invalid_content_type():
|
def test_search_with_invalid_content_type(client):
|
||||||
# Arrange
|
# Arrange
|
||||||
user_query = quote("How to call Khoj from Emacs?")
|
user_query = quote("How to call Khoj from Emacs?")
|
||||||
|
|
||||||
|
@ -38,13 +32,8 @@ def test_search_with_invalid_content_type():
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------
|
||||||
def test_search_with_valid_content_type(content_config: ContentConfig, search_config: SearchConfig):
|
def test_search_with_valid_content_type(client):
|
||||||
# Arrange
|
for content_type in ["org", "markdown", "ledger", "music", "plugin1"]:
|
||||||
config.content_type = content_config
|
|
||||||
config.search_type = search_config
|
|
||||||
|
|
||||||
# config.content_type.image = search_config.image
|
|
||||||
for content_type in ["org", "markdown", "ledger", "music"]:
|
|
||||||
# Act
|
# Act
|
||||||
response = client.get(f"/api/search?q=random&t={content_type}")
|
response = client.get(f"/api/search?q=random&t={content_type}")
|
||||||
# Assert
|
# Assert
|
||||||
|
@ -52,7 +41,7 @@ def test_search_with_valid_content_type(content_config: ContentConfig, search_co
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------
|
||||||
def test_update_with_invalid_content_type():
|
def test_update_with_invalid_content_type(client):
|
||||||
# Act
|
# Act
|
||||||
response = client.get(f"/api/update?t=invalid_content_type")
|
response = client.get(f"/api/update?t=invalid_content_type")
|
||||||
|
|
||||||
|
@ -61,12 +50,8 @@ def test_update_with_invalid_content_type():
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------
|
||||||
def test_update_with_valid_content_type(content_config: ContentConfig, search_config: SearchConfig):
|
def test_update_with_valid_content_type(client):
|
||||||
# Arrange
|
for content_type in ["org", "markdown", "ledger", "music", "plugin1"]:
|
||||||
config.content_type = content_config
|
|
||||||
config.search_type = search_config
|
|
||||||
|
|
||||||
for content_type in ["org", "markdown", "ledger", "music"]:
|
|
||||||
# Act
|
# Act
|
||||||
response = client.get(f"/api/update?t={content_type}")
|
response = client.get(f"/api/update?t={content_type}")
|
||||||
# Assert
|
# Assert
|
||||||
|
@ -74,7 +59,7 @@ def test_update_with_valid_content_type(content_config: ContentConfig, search_co
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------
|
||||||
def test_regenerate_with_invalid_content_type():
|
def test_regenerate_with_invalid_content_type(client):
|
||||||
# Act
|
# Act
|
||||||
response = client.get(f"/api/update?force=true&t=invalid_content_type")
|
response = client.get(f"/api/update?force=true&t=invalid_content_type")
|
||||||
|
|
||||||
|
@ -83,12 +68,8 @@ def test_regenerate_with_invalid_content_type():
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------
|
||||||
def test_regenerate_with_valid_content_type(content_config: ContentConfig, search_config: SearchConfig):
|
def test_regenerate_with_valid_content_type(client):
|
||||||
# Arrange
|
for content_type in ["org", "markdown", "ledger", "music", "image", "plugin1"]:
|
||||||
config.content_type = content_config
|
|
||||||
config.search_type = search_config
|
|
||||||
|
|
||||||
for content_type in ["org", "markdown", "ledger", "music", "image"]:
|
|
||||||
# Act
|
# Act
|
||||||
response = client.get(f"/api/update?force=true&t={content_type}")
|
response = client.get(f"/api/update?force=true&t={content_type}")
|
||||||
# Assert
|
# Assert
|
||||||
|
@ -96,10 +77,8 @@ def test_regenerate_with_valid_content_type(content_config: ContentConfig, searc
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------
|
||||||
def test_image_search(content_config: ContentConfig, search_config: SearchConfig):
|
def test_image_search(client, content_config: ContentConfig, search_config: SearchConfig):
|
||||||
# Arrange
|
# Arrange
|
||||||
config.content_type = content_config
|
|
||||||
config.search_type = search_config
|
|
||||||
model.image_search = image_search.setup(content_config.image, search_config.image, regenerate=False)
|
model.image_search = image_search.setup(content_config.image, search_config.image, regenerate=False)
|
||||||
query_expected_image_pairs = [
|
query_expected_image_pairs = [
|
||||||
("kitten", "kitten_park.jpg"),
|
("kitten", "kitten_park.jpg"),
|
||||||
|
@ -121,7 +100,7 @@ def test_image_search(content_config: ContentConfig, search_config: SearchConfig
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------
|
||||||
def test_notes_search(content_config: ContentConfig, search_config: SearchConfig):
|
def test_notes_search(client, content_config: ContentConfig, search_config: SearchConfig):
|
||||||
# Arrange
|
# Arrange
|
||||||
model.orgmode_search = text_search.setup(OrgToJsonl, content_config.org, search_config.asymmetric, regenerate=False)
|
model.orgmode_search = text_search.setup(OrgToJsonl, content_config.org, search_config.asymmetric, regenerate=False)
|
||||||
user_query = quote("How to git install application?")
|
user_query = quote("How to git install application?")
|
||||||
|
@ -137,7 +116,7 @@ def test_notes_search(content_config: ContentConfig, search_config: SearchConfig
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------
|
||||||
def test_notes_search_with_only_filters(content_config: ContentConfig, search_config: SearchConfig):
|
def test_notes_search_with_only_filters(client, content_config: ContentConfig, search_config: SearchConfig):
|
||||||
# Arrange
|
# Arrange
|
||||||
filters = [WordFilter(), FileFilter()]
|
filters = [WordFilter(), FileFilter()]
|
||||||
model.orgmode_search = text_search.setup(
|
model.orgmode_search = text_search.setup(
|
||||||
|
@ -156,7 +135,7 @@ def test_notes_search_with_only_filters(content_config: ContentConfig, search_co
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------
|
||||||
def test_notes_search_with_include_filter(content_config: ContentConfig, search_config: SearchConfig):
|
def test_notes_search_with_include_filter(client, content_config: ContentConfig, search_config: SearchConfig):
|
||||||
# Arrange
|
# Arrange
|
||||||
filters = [WordFilter()]
|
filters = [WordFilter()]
|
||||||
model.orgmode_search = text_search.setup(
|
model.orgmode_search = text_search.setup(
|
||||||
|
@ -175,7 +154,7 @@ def test_notes_search_with_include_filter(content_config: ContentConfig, search_
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------
|
||||||
def test_notes_search_with_exclude_filter(content_config: ContentConfig, search_config: SearchConfig):
|
def test_notes_search_with_exclude_filter(client, content_config: ContentConfig, search_config: SearchConfig):
|
||||||
# Arrange
|
# Arrange
|
||||||
filters = [WordFilter()]
|
filters = [WordFilter()]
|
||||||
model.orgmode_search = text_search.setup(
|
model.orgmode_search = text_search.setup(
|
||||||
|
|
Loading…
Add table
Reference in a new issue