-
Notifications
You must be signed in to change notification settings - Fork 77
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
[SVCS-353] Look for Dataverse renamed files on upload #300
base: develop
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import pytest | ||
|
||
from waterbutler.providers.dataverse import utils as dv_utils | ||
|
||
|
||
@pytest.fixture | ||
def format_dict(): | ||
return { | ||
'xlsx': { | ||
'originalFileFormat': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', | ||
'originalFormatLabel': 'MS Excel (XLSX)', | ||
'contentType': 'text/tab-separated-values', | ||
}, | ||
'RData': { | ||
'originalFileFormat': 'application/x-rlang-transport', | ||
'originalFormatLabel': 'R Data', | ||
'contentType': 'text/tab-separated-values' | ||
}, | ||
'sav': { | ||
'originalFileFormat': 'application/x-spss-sav', | ||
'originalFormatLabel': 'SPSS SAV', | ||
'contentType': 'text/tab-separated-values' | ||
}, | ||
'dta': { | ||
'originalFileFormat': 'application/x-stata', | ||
'originalFormatLabel': 'Stata Binary', | ||
'contentType': 'text/tab-separated-values' | ||
}, | ||
'por': { | ||
'originalFileFormat': 'application/x-spss-por', | ||
'originalFormatLabel': 'SPSS Portable', | ||
'contentType': 'text/tab-separated-values' | ||
}, | ||
'csv': { | ||
'originalFileFormat': 'text/csv', | ||
'originalFormatLabel': 'Comma Separated Values', | ||
'contentType': 'text/tab-separated-values' | ||
} | ||
} | ||
|
||
|
||
class TestUtils: | ||
|
||
def test_original_ext_from_raw_metadata(self, format_dict): | ||
for key in format_dict: | ||
assert key in dv_utils.original_ext_from_raw_metadata(format_dict[key]) | ||
|
||
def test_original_ext_from_raw_metadata_none_case(self, format_dict): | ||
for key in format_dict: | ||
format_dict[key]['originalFormatLabel'] = 'blarg' | ||
assert dv_utils.original_ext_from_raw_metadata(format_dict[key]) is None |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from http import HTTPStatus | ||
|
||
from waterbutler.core.exceptions import UploadError | ||
|
||
|
||
class DataverseIngestionLockError(UploadError): | ||
def __init__(self, message, code=HTTPStatus.BAD_REQUEST): | ||
"""``dummy`` argument is because children of ``WaterButlerError`` must be instantiable with | ||
a single integer argument. See :class:`waterbutler.core.exceptions.WaterButlerError` | ||
for details. | ||
""" | ||
super().__init__( | ||
'Some uploads to Dataverse will lock uploading for a time. Please wait' | ||
' a few seconds and try again.', | ||
code=code) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
ORIGINAL_FORMATS = { | ||
|
||
'RData': { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See two previous comments regarding multiple 'original_label': 'R Data' |
||
'original_format': 'application/x-rlang-transport', | ||
'original_label': 'R Data', | ||
'content_type': 'text/tab-separated-values', | ||
'all_extensions': ['rdata', 'Rdata', 'RData'] | ||
}, | ||
'sav': { | ||
'original_format': 'application/x-spss-sav', | ||
'original_label': 'SPSS SAV', | ||
'content_type': 'text/tab-separated-values', | ||
'all_extensions': ['sav'] | ||
}, | ||
'dta': { | ||
'original_format': 'application/x-stata', | ||
'original_label': 'Stata Binary', | ||
'content_type': 'text/tab-separated-values', | ||
'all_extensions': ['dta'] | ||
}, | ||
'por': { | ||
'original_format': 'application/x-spss-por', | ||
'original_label': 'SPSS Portable', | ||
'content_type': 'text/tab-separated-values', | ||
'all_extensions': ['por'] | ||
}, | ||
'csv': { | ||
'original_format': 'text/csv', | ||
'original_label': 'Comma Separated Values', | ||
'content_type': 'text/tab-separated-values', | ||
'all_extensions': ['csv', 'CSV'] | ||
}, | ||
'xlsx': { | ||
'original_format': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', | ||
'original_label': 'MS Excel (XLSX)', | ||
'content_type': 'text/tab-separated-values', | ||
'all_extensions': ['xlsx'] | ||
} | ||
} | ||
|
||
|
||
def original_ext_from_raw_metadata(data): | ||
"""Use the raw metadata to figure out possible original extensions.""" | ||
label = data.get('originalFormatLabel', None) | ||
file_format = data.get('originalFileFormat', None) | ||
content_type = data.get('contentType', None) | ||
|
||
if not label or not file_format or not content_type: | ||
return None | ||
|
||
for key in ORIGINAL_FORMATS: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably better as:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can apply the above to TestUtils class as well. |
||
if (label == ORIGINAL_FORMATS[key]['original_label'] and | ||
file_format == ORIGINAL_FORMATS[key]['original_format'] and | ||
content_type == ORIGINAL_FORMATS[key]['content_type']): | ||
|
||
return ORIGINAL_FORMATS[key]['all_extensions'] | ||
|
||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not just use a list comprehension here?