Version Khoj API, Update frontends, tests and docs to reflect it

- Split router.py into v1.0, beta and frontend (no-prefix) api modules
  under new router package. Version tag in main.py via prefix
- Update frontends to use the versioned api endpoints
- Update tests to work with versioned api endpoints
- Update docs to mentioned, reference only versioned api endpoints
This commit is contained in:
Debanjum Singh Solanky
2022-09-14 21:22:20 +03:00
parent ee65a4f2c7
commit e42a38e825
11 changed files with 154 additions and 124 deletions

View File

@@ -28,7 +28,7 @@ def test_search_with_invalid_content_type():
user_query = quote("How to call Khoj from Emacs?")
# Act
response = client.get(f"/search?q={user_query}&t=invalid_content_type")
response = client.get(f"/api/v1.0/search?q={user_query}&t=invalid_content_type")
# Assert
assert response.status_code == 422
@@ -43,29 +43,29 @@ def test_search_with_valid_content_type(content_config: ContentConfig, search_co
# config.content_type.image = search_config.image
for content_type in ["org", "markdown", "ledger", "music"]:
# Act
response = client.get(f"/search?q=random&t={content_type}")
response = client.get(f"/api/v1.0/search?q=random&t={content_type}")
# Assert
assert response.status_code == 200
# ----------------------------------------------------------------------------------------------------
def test_reload_with_invalid_content_type():
def test_update_with_invalid_content_type():
# Act
response = client.get(f"/reload?t=invalid_content_type")
response = client.get(f"/api/v1.0/update?t=invalid_content_type")
# Assert
assert response.status_code == 422
# ----------------------------------------------------------------------------------------------------
def test_reload_with_valid_content_type(content_config: ContentConfig, search_config: SearchConfig):
def test_update_with_valid_content_type(content_config: ContentConfig, search_config: SearchConfig):
# Arrange
config.content_type = content_config
config.search_type = search_config
for content_type in ["org", "markdown", "ledger", "music"]:
# Act
response = client.get(f"/reload?t={content_type}")
response = client.get(f"/api/v1.0/update?t={content_type}")
# Assert
assert response.status_code == 200
@@ -73,7 +73,7 @@ def test_reload_with_valid_content_type(content_config: ContentConfig, search_co
# ----------------------------------------------------------------------------------------------------
def test_regenerate_with_invalid_content_type():
# Act
response = client.get(f"/regenerate?t=invalid_content_type")
response = client.get(f"/api/v1.0/update?force=true&t=invalid_content_type")
# Assert
assert response.status_code == 422
@@ -87,7 +87,7 @@ def test_regenerate_with_valid_content_type(content_config: ContentConfig, searc
for content_type in ["org", "markdown", "ledger", "music", "image"]:
# Act
response = client.get(f"/regenerate?t={content_type}")
response = client.get(f"/api/v1.0/update?force=true&t={content_type}")
# Assert
assert response.status_code == 200
@@ -104,7 +104,7 @@ def test_image_search(content_config: ContentConfig, search_config: SearchConfig
for query, expected_image_name in query_expected_image_pairs:
# Act
response = client.get(f"/search?q={query}&n=1&t=image")
response = client.get(f"/api/v1.0/search?q={query}&n=1&t=image")
# Assert
assert response.status_code == 200
@@ -122,7 +122,7 @@ def test_notes_search(content_config: ContentConfig, search_config: SearchConfig
user_query = quote("How to git install application?")
# Act
response = client.get(f"/search?q={user_query}&n=1&t=org&r=true")
response = client.get(f"/api/v1.0/search?q={user_query}&n=1&t=org&r=true")
# Assert
assert response.status_code == 200
@@ -139,7 +139,7 @@ def test_notes_search_with_only_filters(content_config: ContentConfig, search_co
user_query = quote('+"Emacs" file:"*.org"')
# Act
response = client.get(f"/search?q={user_query}&n=1&t=org")
response = client.get(f"/api/v1.0/search?q={user_query}&n=1&t=org")
# Assert
assert response.status_code == 200
@@ -156,7 +156,7 @@ def test_notes_search_with_include_filter(content_config: ContentConfig, search_
user_query = quote('How to git install application? +"Emacs"')
# Act
response = client.get(f"/search?q={user_query}&n=1&t=org")
response = client.get(f"/api/v1.0/search?q={user_query}&n=1&t=org")
# Assert
assert response.status_code == 200
@@ -173,7 +173,7 @@ def test_notes_search_with_exclude_filter(content_config: ContentConfig, search_
user_query = quote('How to git install application? -"clone"')
# Act
response = client.get(f"/search?q={user_query}&n=1&t=org")
response = client.get(f"/api/v1.0/search?q={user_query}&n=1&t=org")
# Assert
assert response.status_code == 200