-
Notifications
You must be signed in to change notification settings - Fork 76
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
Open
AddisonSchiller
wants to merge
3
commits into
CenterForOpenScience:develop
Choose a base branch
from
AddisonSchiller:feature/SVCS-353-davaverse-csv-bug
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, ext in format_dict.items(): | ||
ext['originalFormatLabel'] = 'blarg' | ||
assert dv_utils.original_ext_from_raw_metadata(ext) is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
ORIGINAL_FORMATS = { | ||
|
||
'RData': { | ||
'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, ext in ORIGINAL_FORMATS.items(): | ||
if (label == ext['original_label'] and | ||
file_format == ext['original_format'] and | ||
content_type == ext['content_type']): | ||
|
||
return ext['all_extensions'] | ||
|
||
return None |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?