-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Update tests for users and admin
- Loading branch information
1 parent
a481568
commit 5080d8e
Showing
2 changed files
with
46 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,50 +54,67 @@ def test_search_public_users(user_service, user_pub): | |
assert res["hits"]["total"] == 2 # 2 public users in conftest | ||
|
||
|
||
# Admin search | ||
@pytest.mark.parametrize( | ||
"query", | ||
[ | ||
"affiliations:CERN", | ||
"affiliation:CERN", | ||
"name:Jose affiliation:CERN", | ||
"+name:Jose +affiliation:CERN", | ||
"CERN", | ||
"Tim", | ||
"Tim CERN", | ||
"Jose", | ||
"Jos", | ||
"Jose CERN", | ||
"email:[email protected]", | ||
"username:pub", | ||
], | ||
) | ||
def test_admin_search_field(user_service, user_moderator, query): | ||
"""Make sure certain fields ARE searchable.""" | ||
res = user_service.search_all(user_moderator.identity, q=query).to_dict() | ||
assert res["hits"]["total"] > 0 | ||
|
||
|
||
# User search | ||
@pytest.mark.parametrize( | ||
"query", | ||
[ | ||
"email:[email protected]", | ||
"[email protected]", | ||
"email:[email protected]", | ||
"[email protected]", | ||
"Plazi", | ||
"+name:Jose -affiliation:CERN", | ||
"name:Jose AND NOT affiliation:CERN", | ||
"username:inactive", | ||
"username:unconfirmed", | ||
"preferences.visibility:public", | ||
"preferences.email_visibility:restricted", | ||
"profile.affiliations:Plazi", | ||
"invalid:test", | ||
"inactive", | ||
"unconfirmed", | ||
"restricted", | ||
"Plazi", | ||
"test", | ||
], | ||
) | ||
def test_search_field_not_searchable(user_service, user_pub, query): | ||
def test_user_search_field_not_searchable(user_service, user_pub, query): | ||
"""Make sure certain fields are NOT searchable.""" | ||
res = user_service.search(user_pub.identity, q=query).to_dict() | ||
res = user_service.search(user_pub.identity, suggest=query).to_dict() | ||
assert res["hits"]["total"] == 0 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"query", | ||
[ | ||
"affiliations:CERN", | ||
"affiliation:CERN", | ||
"name:Jose affiliation:CERN", | ||
"+name:Jose +affiliation:CERN", | ||
"CERN", | ||
"Jose CERN", | ||
"Jose AND CERN", | ||
"Tim", | ||
"Tim CERN", | ||
"Jose", | ||
"Jos", | ||
"Jose CERN", | ||
"email:[email protected]", | ||
"username:pub", | ||
"[email protected]", | ||
"pub", | ||
], | ||
) | ||
def test_search_field(user_service, user_pub, query): | ||
def test_user_search_field(user_service, user_pub, query): | ||
"""Make sure certain fields ARE searchable.""" | ||
res = user_service.search(user_pub.identity, q=query).to_dict() | ||
res = user_service.search(user_pub.identity, suggest=query).to_dict() | ||
assert res["hits"]["total"] > 0 | ||
|
||
|
||
|
@@ -162,7 +179,9 @@ def test_search_permissions(app, db, user_service, user_moderator, user_res): | |
"""Test service search for permissions.""" | ||
# User can search for himself | ||
search = user_service.search( | ||
user_res.identity, q=f"username:{user_res._user.username}" | ||
user_res.identity, | ||
q=user_res._user.username, | ||
fields=["username"], | ||
) | ||
assert search.total > 0 | ||
|
||
|