diff --git a/server/conftest.py b/server/conftest.py index 361e77367..c27ca68ca 100644 --- a/server/conftest.py +++ b/server/conftest.py @@ -117,7 +117,7 @@ def agave_storage_system_mock(): @pytest.fixture -def agave_file_mock(): +def tapis_file_mock(): with open(os.path.join(settings.BASE_DIR, 'fixtures/agave/files/file.json')) as f: yield json.load(f) diff --git a/server/portal/apps/datafiles/views_unit_test.py b/server/portal/apps/datafiles/views_unit_test.py index d16cd5cd6..af10bc4f7 100644 --- a/server/portal/apps/datafiles/views_unit_test.py +++ b/server/portal/apps/datafiles/views_unit_test.py @@ -224,17 +224,15 @@ def test_tapis_file_view_put_is_logged_for_metrics(mock_indexer, client, authent @patch('portal.libs.agave.operations.tapis_indexer') def test_tapis_file_view_post_is_logged_for_metrics(mock_indexer, client, authenticated_user, mock_tapis_client, logging_metric_mock, - agave_file_mock, requests_mock, text_file_fixture): + tapis_file_mock, requests_mock, text_file_fixture): - mock_tapis_client.access_token.access_token = "my_access_token" - requests_mock.post(f'{settings.TAPIS_TENANT_BASEURL}/v3/files/ops/frontera.home.username/text_file.txt', - json=agave_file_mock) + mock_tapis_client.files.insert.return_value = tapis_file_mock response = client.post("/api/datafiles/tapis/upload/private/frontera.home.username/", data={"uploaded_file": text_file_fixture}) assert response.status_code == 200 - assert response.json() == {"data": agave_file_mock} + assert response.json() == {"data": tapis_file_mock} # Ensure metric-related logging is being performed logging_metric_mock.assert_called_with( diff --git a/server/portal/libs/agave/operations.py b/server/portal/libs/agave/operations.py index 1603039ee..78e730cff 100644 --- a/server/portal/libs/agave/operations.py +++ b/server/portal/libs/agave/operations.py @@ -10,7 +10,6 @@ from portal.libs.agave.filter_mapping import filter_mapping from pathlib import Path from tapipy.errors import BaseTapyException -import requests as r logger = logging.getLogger(__name__) @@ -448,20 +447,8 @@ def upload(client, system, path, uploaded_file): file_listing = client.files.listFiles(systemId=system, path=path) uploaded_file.name = increment_file_name(listing=file_listing, file_name=uploaded_file.name) - base_url = settings.TAPIS_TENANT_BASEURL - token = client.access_token.access_token - systemId = system dest_path = os.path.join(path.strip('/'), uploaded_file.name) - - res = r.post( - url=f'{base_url}/v3/files/ops/{systemId}/{dest_path}', - files={"file": uploaded_file.file}, - headers={"X-Tapis-Token": token}) - - res.raise_for_status() - - response_json = res.json() - + response_json = client.files.insert(systemId=system, path=dest_path, file=uploaded_file) tapis_indexer.apply_async(kwargs={'access_token': client.access_token.access_token, 'systemId': system, 'filePath': path,