-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_user_information.py
104 lines (88 loc) · 3.87 KB
/
test_user_information.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from pathlib import Path
import pandas as pd
from pandas.testing import assert_frame_equal
from dsp_tools.commands.ingest_xmlupload.user_information import IngestInformation
class TestIngestInformation:
def test_no_problems(self) -> None:
expected = (
"All multimedia files referenced in the XML file were uploaded through dsp-ingest.\n"
"All multimedia files uploaded through dsp-ingest were referenced in the XML file."
)
assert IngestInformation([], []).ok_msg() == expected
def test_not_all_good(self) -> None:
assert not IngestInformation(["unused_media"], []).ok_msg()
def test_unused_media(self) -> None:
expected = (
"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"
" - unused_media"
)
res_info = IngestInformation(["unused_media"], [])._get_error_msg()
assert res_info == expected
def test_not_uploaded(self) -> None:
expected = (
"The upload cannot continue as there are problems with the multimedia files referenced in the XML.\n"
" The data XML file contains references to the following multimedia files "
"which were not previously uploaded through dsp-ingest:\n"
" - Resource ID: 'no upload id' | Filepath: 'media path'"
)
res_info = IngestInformation([], [("no upload id", "media path")])._get_error_msg()
assert res_info == expected
def test_all_problem_with_df_msg(self) -> None:
expected = (
"The upload cannot continue as there are problems with the multimedia files referenced in the XML.\n"
" The data XML file does not reference all the multimedia files "
"which were previously uploaded through dsp-ingest.\n"
" The file with the unused filenames was saved at 'UnusedMediaUploadedInSipi.csv'.\n"
" The data XML file contains references to multimedia files "
"which were not previously uploaded through dsp-ingest:\n"
" The file with the resource IDs and problematic filenames was saved at 'FilesNotUploadedToSipi.csv'."
)
res_info = IngestInformation(
[
"unused_media0",
"unused_media1",
],
[
("no_up0_id", "no_up0_file"),
("no_up1_id", "no_up1_file"),
],
csv_directory_path=Path(),
maximum_prints=1,
)._get_error_msg()
assert res_info == expected
def test_unused_media_to_df() -> None:
unused_media_list = [
"unused_media0",
"unused_media1",
]
expected = pd.DataFrame({"Multimedia Filenames": unused_media_list})
res_df = IngestInformation(unused_media_list, [], maximum_prints=1)._unused_mediafiles_to_df()
assert_frame_equal(res_df, expected)
def test_unused_media_to_df_not_enough() -> None:
assert not IngestInformation(["unused_media"], [], maximum_prints=1)._unused_mediafiles_to_df()
def test_no_id_to_df() -> None:
expected = pd.DataFrame(
{
"Resource ID": [
"ID_no_up0",
"ID_no_up1",
],
"Filepath": [
"fileno_up0.jpg",
"fileno_up1.jpg",
],
}
)
res_df = IngestInformation(
[],
[
("ID_no_up0", "fileno_up0.jpg"),
("ID_no_up1", "fileno_up1.jpg"),
],
maximum_prints=1,
)._mediafiles_no_id_to_df()
assert_frame_equal(res_df, expected)
def test_no_id_to_df_not_enough() -> None:
assert not IngestInformation([], [("ID_no_up0", "fileno_up0.jpg")])._unused_mediafiles_to_df()