-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_ingest_xmlupload.py
54 lines (44 loc) · 1.88 KB
/
test_ingest_xmlupload.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import shutil
from pathlib import Path
from typing import Iterator
import pytest
import regex
from dsp_tools.commands.ingest_xmlupload.upload_xml import ingest_xmlupload
from dsp_tools.models.exceptions import InputError
@pytest.fixture(autouse=True)
def _retrieve_mapping_file() -> Iterator[None]:
"""Put the mapping file into the cwd."""
mapping_file = Path("testdata/dsp-ingest-data/mapping-00A2.csv")
shutil.copy(mapping_file, ".")
yield
Path(mapping_file.name).unlink()
def test_ingest_xmlupload() -> None:
expected_msg = regex.escape(
"The upload cannot continue as there are problems with the multimedia files referenced in the XML.\n"
" The data XML file does not reference the following multimedia files "
"which were previously uploaded through dsp-ingest:\n"
" - extra.jpg\n"
" The data XML file contains references to the following multimedia files "
"which were not previously uploaded through dsp-ingest:\n"
" - Resource ID: 'GoodGirlImage' | Filepath: 'images/GoodGirl.jpg'"
)
with pytest.raises(InputError, match=expected_msg):
ingest_xmlupload(
xml_file=Path("testdata/dsp-ingest-data/dsp-ingest.xml"),
user="root@example.com",
password="test",
dsp_url="http://0.0.0.0:3333",
sipi_url="http://0.0.0.0:1024",
)
def test_ingest_xmlupload_no_mapping() -> None:
expected_msg = regex.escape("No mapping CSV file was found at mapping-00A5.csv.")
with pytest.raises(InputError, match=expected_msg):
ingest_xmlupload(
xml_file=Path("testdata/dsp-ingest-data/dsp_ingest_no_mapping.xml"),
user="root@example.com",
password="test",
dsp_url="http://0.0.0.0:3333",
sipi_url="http://0.0.0.0:1024",
)
if __name__ == "__main__":
pytest.main([__file__])