Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows uploading files with absolute paths #14

Merged
merged 7 commits into from
May 3, 2021
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
4 changes: 3 additions & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ on:
jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7]
platform: [ubuntu-latest]

runs-on: ${{ matrix.platform }}

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ docs-serve:

.PHONY: test
test:
pytest -n 8 tests
pytest -n 4 tests

.PHONY: test-cov
test-cov:
pytest -n 8 --cov=hsclient --cov-report html
pytest -n 4 --cov=hsclient --cov-report html
4 changes: 2 additions & 2 deletions hsclient/hydroshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import tempfile
import time
from datetime import datetime
from posixpath import basename, dirname, join as urljoin, splitext
from posixpath import join as urljoin, splitext, basename, dirname
from typing import Dict, List, Union
from urllib.parse import urlparse, quote, unquote
from zipfile import ZipFile
Expand Down Expand Up @@ -578,7 +578,7 @@ def file_upload(self, *files: str, destination_path: str = "") -> None:
zipped_file = os.path.join(tmpdir, 'files.zip')
with ZipFile(zipped_file, 'w') as zipped:
for file in files:
zipped.write(file, basename(file))
zipped.write(file, os.path.basename(file))
self._upload(zipped_file, destination_path=destination_path)
unzip_path = urljoin(
self._hsapi_path, "functions", "unzip", "data", "contents", destination_path, 'files.zip'
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='hsclient',
version='0.1.6',
version='0.1.7',
packages=find_packages(include=['hsclient', 'hsclient.*'],
exclude=("tests",)),
install_requires=[
Expand Down
1 change: 1 addition & 0 deletions tests/data/another.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
another hello dude
22 changes: 19 additions & 3 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,26 @@ def timeseries_resource(new_resource):
"ODM2_Multi_Site_One_Variable_meta.xml",
]
root_path = "data/test_resource_metadata_files/"
new_resource.file_upload(*[root_path + file for file in files])
new_resource.file_upload(*[os.path.join(root_path, file) for file in files])
return new_resource


def test_absolute_path_multiple_file_upload(new_resource):
files = [
"other.txt",
"another.txt",
]
root_path = "data"
new_resource.file_upload(*[os.path.abspath(os.path.join(root_path, file)) for file in files])
assert len(new_resource.files()) == 2


def test_absolute_path_single_file_upload(new_resource):
rel_path = os.path.join("data", "other.txt")
new_resource.file_upload(os.path.abspath(rel_path))
assert len(new_resource.files()) == 1


def test_filtering_aggregations(timeseries_resource):
assert len(timeseries_resource.aggregations(type=AggregationType.TimeSeriesAggregation)) == 1
timeseries = timeseries_resource.aggregation(type=AggregationType.TimeSeriesAggregation)
Expand Down Expand Up @@ -387,7 +403,7 @@ def test_user_info(hydroshare):
def test_aggregations(new_resource, files):
root_path = "data/test_resource_metadata_files/"
file_count = len(files) - 2 # exclude rdf/xml file
new_resource.file_upload(*[root_path + file for file in files])
new_resource.file_upload(*[os.path.join(root_path, file) for file in files])
assert len(new_resource.aggregations()) == 1
assert len(new_resource.files()) == 0
agg = new_resource.aggregations()[0]
Expand Down Expand Up @@ -425,7 +441,7 @@ def test_aggregation_fileset(new_resource, files):
root_path = "data/test_resource_metadata_files/"
file_count = len(files) - 2 # exclude rdf/xml file
new_resource.folder_create("asdf")
new_resource.file_upload(*[root_path + file for file in files], destination_path="asdf")
new_resource.file_upload(*[os.path.join(root_path, file) for file in files], destination_path="asdf")
assert len(new_resource.aggregations()) == 1
assert len(new_resource.files()) == 0
agg = new_resource.aggregations()[0]
Expand Down