Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/utils/aggregated.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def search_item(project_code, zone, folder_relative_path, item_type, container_t
res = requests.get(url, params=params, headers=headers)
if res.status_code == 403:
SrvErrorHandler.customized_handle(ECustomizedError.PERMISSION_DENIED, project_code)
elif res.status_code != 200:
SrvErrorHandler.default_handle(res.text, True)

return res.json()

Expand Down
32 changes: 32 additions & 0 deletions tests/app/utils/test_aggregated.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#
# Contact Indoc Research for any questions regarding the use of this source code.

import pytest

from app.utils.aggregated import search_item

test_project_code = 'testproject'
Expand Down Expand Up @@ -55,3 +57,33 @@ def test_search_file_should_return_200(requests_mock, mocker):
}
res = search_item(test_project_code, 'zone', 'folder_relative_path', 'file', 'project')
assert res['result'] == expected_result


def test_search_file_error_handling_with_403(requests_mock, mocker, capsys):
mocker.patch('app.services.user_authentication.token_manager.SrvTokenManager.check_valid', return_value=0)
requests_mock.get(
f'http://bff_cli/v1/project/{test_project_code}/search',
json={},
status_code=403,
)
with pytest.raises(SystemExit):
search_item(test_project_code, 'zone', 'folder_relative_path', 'file', 'project')
out, _ = capsys.readouterr()
assert (
out.rstrip()
== 'Permission denied. Please verify your role in the Project has permission to perform this action.'
)


def test_search_file_error_handling_with_401(requests_mock, mocker, capsys):
mocker.patch('app.services.user_authentication.token_manager.SrvTokenManager.check_valid', return_value=0)
requests_mock.get(
f'http://bff_cli/v1/project/{test_project_code}/search',
text='Authentication failed.',
status_code=401,
)
with pytest.raises(SystemExit):
search_item(test_project_code, 'zone', 'folder_relative_path', 'file', 'project')
out, _ = capsys.readouterr()
out = out.rstrip()
assert out == 'Authentication failed.'