Skip to content

Commit

Permalink
Use either of analysis or header check mime (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
maudetes authored Jan 15, 2024
1 parent a23b027 commit 26cf6de
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Current (in progress)

- Nothing yet
- Use either of analysis or header check mime [#32](https://github.com/opendatateam/udata-tabular-preview/pull/32)

## 3.0.4 (2024-01-09)

Expand Down
17 changes: 17 additions & 0 deletions tests/test_tabular_preview_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,23 @@ def test_display_preview_using_analysis_extras():
assert resource.preview_url == expected_url(resource.latest)


@pytest.mark.options(TABULAR_EXPLORE_URL='http://preview.me',
TABULAR_CSVAPI_URL='http://csvapi.me/',
TABULAR_MAX_SIZE=MAX_SIZE)
def test_display_preview_using_check_and_analysis_extras():
extras = {
'check:headers:content-type': MIME_TYPE,
'analysis:mime-type': 'incorrect/mime',
'analysis:content-length': MAX_SIZE - 1,
}
resource = ResourceFactory(
mime=None,
filesize=None,
extras=extras
)

assert resource.preview_url == expected_url(resource.latest)

@pytest.mark.options(TABULAR_EXPLORE_URL='http://preview.me',
TABULAR_CSVAPI_URL='http://csvapi.me/',
TABULAR_MAX_SIZE=MAX_SIZE)
Expand Down
7 changes: 4 additions & 3 deletions udata_tabular_preview/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ def can_preview(self, resource):
)

supported_mimes = current_app.config.get('TABULAR_SUPPORTED_MIME_TYPES')
extras_mime = resource.extras.get('analysis:mime-type') \
or resource.extras.get('check:headers:content-type')
extras_analysis_mime = resource.extras.get('analysis:mime-type')
extras_headers_mime = resource.extras.get('check:headers:content-type')
is_supported = (
extras_mime in supported_mimes
extras_analysis_mime in supported_mimes
or extras_headers_mime in supported_mimes
or resource.mime in supported_mimes
)

Expand Down

0 comments on commit 26cf6de

Please sign in to comment.