Add a test to verify that a user without data sucessfully returns a respones to the /search endpoint

This commit is contained in:
sabaimran
2023-11-10 14:00:58 -08:00
parent e62788ad79
commit 262a8574d1
2 changed files with 48 additions and 1 deletions

View File

@@ -16,7 +16,7 @@ from khoj.utils.state import search_models, content_index, config
from khoj.search_type import text_search, image_search
from khoj.utils.rawconfig import ContentConfig, SearchConfig
from khoj.processor.org_mode.org_to_entries import OrgToEntries
from database.models import KhojUser
from database.models import KhojUser, KhojApiUser
from database.adapters import EntryAdapters
@@ -351,6 +351,24 @@ def test_different_user_data_not_accessed(client, sample_org_data, default_user:
assert len(response.json()) == 1 and response.json()["detail"] == "Forbidden"
# ----------------------------------------------------------------------------------------------------
@pytest.mark.django_db(transaction=True)
def test_user_no_data_returns_empty(client, sample_org_data, api_user3: KhojApiUser):
# Arrange
token = api_user3.token
headers = {"Authorization": "Bearer " + token}
user_query = quote("How to git install application?")
# Act
response = client.get(f"/api/search?q={user_query}&n=1&t=org", headers=headers)
# Assert
assert response.status_code == 200
# assert actual response has no data as the default_user3, though other users have data
assert len(response.json()) == 0
assert response.json() == []
def get_sample_files_data():
return [
("files", ("path/to/filename.org", "* practicing piano", "text/org")),