|
1 | 1 | import pandas as pd
|
| 2 | +import dwcahandler |
2 | 3 | from dwcahandler.dwca import CsvFileType, CoreOrExtType
|
3 | 4 | from dwcahandler.dwca.core_dwca import Dwca
|
4 | 5 | from operator import attrgetter
|
| 6 | +import logging |
| 7 | +import pytest |
5 | 8 |
|
6 |
| -MIMETYPE_IMAGE_URL = 'https://www.gstatic.com/webp/gallery/1.webp' |
| 9 | +logging.basicConfig(level=logging.DEBUG) |
| 10 | +log = logging.getLogger("test_multimedia_content") |
| 11 | + |
| 12 | +MIMETYPE_IMAGE_URL = "https://www.gstatic.com/webp/gallery/1.webp" |
7 | 13 | INVALID_MIMETYPE_URL = "https://invalid.url.jpeg"
|
8 | 14 | IMAGE_URL = "https://images.ala.org.au/image/proxyImageThumbnailLarge?imageId=a36b5634-0277-47c7-b4e3-383e24ce8d1a"
|
9 | 15 | AUDIO_URL = "https://images.ala.org.au/image/proxyImage?imageId=480f5f5e-e96c-4ae3-8230-c53a37bc542e"
|
|
20 | 26 | keys=['occurrenceID'])
|
21 | 27 |
|
22 | 28 |
|
| 29 | +def mock_guess_type(url): |
| 30 | + if url == MIMETYPE_IMAGE_URL: |
| 31 | + return ('image/webp', None) |
| 32 | + elif url == INVALID_MIMETYPE_URL: |
| 33 | + return ('image/jpeg', None) |
| 34 | + return (None, None) |
| 35 | + |
| 36 | + |
| 37 | +@pytest.fixture |
| 38 | +def mock_mime_types(monkeypatch, request): |
| 39 | + if request.config.getoption("--github-action-run"): |
| 40 | + monkeypatch.setattr(dwcahandler.dwca.core_dwca.mimetypes, "guess_type", mock_guess_type) |
| 41 | + |
| 42 | + |
23 | 43 | class TestMultimediaExtension:
|
24 | 44 |
|
25 | 45 | def test_extract_associate_media(self):
|
26 | 46 | """
|
27 | 47 | Test for associated media to be expanded into multimedia extension
|
28 | 48 | """
|
29 |
| - |
30 | 49 | occ_associated_media_df = pd.DataFrame(data=[["1", "species1", IMAGE_URL],
|
31 | 50 | ["2", "species2", AUDIO_URL],
|
32 | 51 | ["3", "species3", f"{VIDEO_URL}|{MIMETYPE_IMAGE_URL}"]],
|
@@ -60,7 +79,7 @@ def test_extract_associate_media(self):
|
60 | 79 | assert sorted(list(map(attrgetter('field_name'), dwca.meta_content.meta_elements[1].fields))) == \
|
61 | 80 | sorted(['coreid', 'identifier'])
|
62 | 81 |
|
63 |
| - def test_fill_additional_multimedia_info(self): |
| 82 | + def test_fill_additional_multimedia_info(self, mock_mime_types): |
64 | 83 | """
|
65 | 84 | Test for fill additional multimedia info if format and type is not provided
|
66 | 85 | :return:
|
@@ -88,12 +107,14 @@ def test_fill_additional_multimedia_info(self):
|
88 | 107 | ["3", MIMETYPE_IMAGE_URL, 'image/webp', 'StillImage']],
|
89 | 108 | columns=['occurrenceID', 'identifier', 'format', 'type'])
|
90 | 109 |
|
| 110 | + dwca.ext_content[0].df_content.fillna('', inplace=True) |
| 111 | + expected_multimedia_df.fillna('', inplace=True) |
| 112 | + |
91 | 113 | # Test that the multimedia extension will now contain the format and type
|
92 | 114 | pd.testing.assert_frame_equal(dwca.ext_content[0].df_content.drop(
|
93 | 115 | columns=['coreid']), expected_multimedia_df)
|
94 | 116 |
|
95 |
| - |
96 |
| - def test_fill_multimedia_info_with_format_type_partially_supplied(self): |
| 117 | + def test_fill_multimedia_info_with_format_type_partially_supplied(self, mock_mime_types): |
97 | 118 | """
|
98 | 119 | Test fill_additional_multimedia_info if format or type is already present.
|
99 | 120 | Calling fill_additional_multimedia_info should not change the existing values in the content
|
@@ -156,8 +177,7 @@ def test_fill_multimedia_info_with_format_type_partially_supplied(self):
|
156 | 177 | pd.testing.assert_frame_equal(dwca.ext_content[0].df_content.drop(
|
157 | 178 | columns=['coreid']), expected_multimedia_df)
|
158 | 179 |
|
159 |
| - |
160 |
| - def test_fill_multimedia_info_type_from_forrmat(self): |
| 180 | + def test_fill_multimedia_info_type_from_forrmat(self, mock_mime_types): |
161 | 181 | """
|
162 | 182 | Test fill_additional_multimedia_info if only format is already present.
|
163 | 183 | Calling fill_additional_multimedia_info should not change the existing values in the content
|
|
0 commit comments