Skip to content

Commit

Permalink
Changed upload function to use Tapipy 1.3.2 files insert function (#859)
Browse files Browse the repository at this point in the history
* Changed upload function to use Tapis 1.3.2 files insert function

* updated unit tests, fixed linting, and updated agave function to tapis

* fixed variable snake case

---------

Co-authored-by: Asim Regmi <[email protected]>
Co-authored-by: Sal Tijerina <[email protected]>
  • Loading branch information
3 people authored Sep 21, 2023
1 parent 224e370 commit 64063f7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
2 changes: 1 addition & 1 deletion server/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 3 additions & 5 deletions server/portal/apps/datafiles/views_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 1 addition & 14 deletions server/portal/libs/agave/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 64063f7

Please sign in to comment.