Skip to content

Commit

Permalink
bug/WP-297: Fix site search for public and community data (#870)
Browse files Browse the repository at this point in the history
* fix site search for pub/community data

* fix unit tests

---------

Co-authored-by: Jake Rosenberg <[email protected]>
  • Loading branch information
rstijerina and Jake Rosenberg authored Oct 3, 2023
1 parent 78bb6e0 commit 3c7ebf1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
16 changes: 11 additions & 5 deletions server/portal/apps/site_search/api/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def mock_cms_search(mocker):
yield mocked_fn


@pytest.fixture
def mock_service_account(mocker):
yield mocker.patch('portal.apps.site_search.api.views.service_account', autospec=True)


@pytest.fixture
def mock_files_search(mocker):
mocked_fn = mocker.patch('portal.apps.site_search.api.views.files_search')
Expand Down Expand Up @@ -76,7 +81,7 @@ def test_search_with_auth(regular_user, client, mock_cms_search,
'include': True}}


def test_search_no_auth(client, mock_cms_search, mock_files_search):
def test_search_no_auth(client, mock_cms_search, mock_files_search, mock_service_account):
response = client.get('/api/site-search/?page=0&query_string=test')

assert response.json() == {
Expand All @@ -93,7 +98,7 @@ def test_search_no_auth(client, mock_cms_search, mock_files_search):


def test_search_public(client, configure_public, mock_cms_search,
mock_files_search):
mock_files_search, mock_service_account):
response = client.get('/api/site-search/?page=0&query_string=test')

assert response.json() == {
Expand Down Expand Up @@ -132,15 +137,16 @@ def test_cms_search_util(mock_dsl_search):
'highlight': {'body': ['highlight 1']}}])


def test_file_search_util(mock_file_search):
def test_file_search_util(mock_file_search, regular_user):
from portal.apps.site_search.api.views import files_search
mock_file_search.return_value = {'count': 1,
'listing':
[{'name': 'testfile',
'path': '/path/to/testfile'}]}
res = files_search('test_query', 'test_system')
client = regular_user.tapis_oauth.client
res = files_search(client, 'test_query', 'test_system')

mock_file_search.assert_called_with(None, 'test_system', '/',
mock_file_search.assert_called_with(client, 'test_system', '/',
query_string='test_query',
filter=None,
offset=0,
Expand Down
11 changes: 7 additions & 4 deletions server/portal/apps/site_search/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from portal.libs.agave.operations import search as search_operation
from portal.views.base import BaseApiView
from django.conf import settings
from portal.libs.agave.utils import service_account
import logging
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -35,8 +36,8 @@ def cms_search(query_string, offset=0, limit=10):
return total, results


def files_search(query_string, system, filter=None, offset=0, limit=10):
res = search_operation(None, system, '/', offset=offset, limit=limit,
def files_search(client, query_string, system, filter=None, offset=0, limit=10):
res = search_operation(client, system, '/', offset=offset, limit=limit,
query_string=query_string, filter=filter)
return (res['count'], res['listing'])

Expand All @@ -62,8 +63,9 @@ def get(self, request, *args, **kwargs):
in settings.PORTAL_DATAFILES_STORAGE_SYSTEMS
if conf['scheme'] == 'public'
and ('siteSearchPriority' in conf and conf['siteSearchPriority'] is not None))
client = request.user.tapis_oauth.client if (request.user.is_authenticated and request.user.profile.setup_complete) else service_account()
(public_total, public_results) = \
files_search(qs, public_conf['system'], filter=filter,
files_search(client, qs, public_conf['system'], filter=filter,
offset=offset, limit=limit)
response['public'] = {'count': public_total,
'listing': public_results,
Expand All @@ -80,8 +82,9 @@ def get(self, request, *args, **kwargs):
in settings.PORTAL_DATAFILES_STORAGE_SYSTEMS
if conf['scheme'] == 'community'
and ('siteSearchPriority' in conf and conf['siteSearchPriority'] is not None))
client = request.user.tapis_oauth.client
(community_total, community_results) = \
files_search(qs, community_conf['system'], filter=filter,
files_search(client, qs, community_conf['system'], filter=filter,
offset=offset,
limit=limit)
response['community'] = {'count': community_total,
Expand Down
5 changes: 3 additions & 2 deletions server/portal/libs/agave/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def listing(client, system, path, offset=0, limit=100, *args, **kwargs):
Params
------
client: agavepy.agave.Agave
client: tapipy.tapis.Tapis
Tapis client to use for the listing.
system: str
Tapis system ID.
Expand Down Expand Up @@ -92,7 +92,8 @@ def search(client, system, path='', offset=0, limit=100, query_string='', filter
Params
------
client: NoneType
client: tapipy.tapis.Tapis
Tapis client to use for the listing.
system: str
Tapis system ID to filter on.
path: NoneType
Expand Down

0 comments on commit 3c7ebf1

Please sign in to comment.