-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,49 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
from salinic.session import Session | ||
|
||
from papermerge.core.models import User | ||
from papermerge.search.schema import IndexEntity | ||
from papermerge.test.types import AuthTestClient | ||
|
||
|
||
@pytest.mark.django_db(transaction=True) | ||
def test_basic( | ||
auth_api_client: AuthTestClient, | ||
session: Session | ||
): | ||
"""Checks that search returns only documents belonging to current user """ | ||
current_user: User = auth_api_client.user | ||
|
||
# document belong to current user | ||
doc_1 = IndexEntity( | ||
id='one', | ||
document_id='doc_1', | ||
title='Anmeldung', | ||
user_id=str(current_user.id), | ||
parent_id='parent_id', | ||
entity_type='page', | ||
breadcrumb=[('home', 'home_id')] | ||
) | ||
session.add(doc_1) | ||
|
||
# document does not belong to current user | ||
doc_2 = IndexEntity( | ||
id='two', | ||
document_id='doc_2', | ||
title='Anmeldung', | ||
user_id='i-belong-to-other-user', | ||
parent_id='parent_id_2', | ||
entity_type='page', | ||
breadcrumb=[('home', 'home_id')] | ||
) | ||
session.add(doc_2) | ||
|
||
response = auth_api_client.get("/search?q=Anmeldung") | ||
|
||
@pytest.mark.django_db | ||
def test_basic(auth_api_client: TestClient): | ||
response = auth_api_client.get("/search?q=one") | ||
assert response.status_code == 200 | ||
assert response.json() == {"msg": "Hello World"} | ||
|
||
returned_models = response.json() | ||
assert len(returned_models) == 1 | ||
|
||
returned_model = returned_models[0] | ||
assert returned_model['id'] == doc_1.model_dump()['id'] |