-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_utils.py
115 lines (105 loc) · 3.93 KB
/
test_utils.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
105
106
107
108
109
110
111
112
113
114
115
import pytest
from harvester.utils.ckan_utils import munge_tag, munge_title_to_name
from harvester.utils.general_utils import (
parse_args,
prepare_transform_msg,
query_filter_builder,
)
class TestCKANUtils:
"""These tests are copied from
# https://github.com/ckan/ckan/blob/master/ckan/tests/lib/test_munge.py
"""
@pytest.mark.parametrize(
"original,expected",
[
("unchanged", "unchanged"),
("s", "s_"), # too short
("some spaces here", "some-spaces--here"),
("random:other%characters&_.here", "randomothercharactershere"),
("river-water-dashes", "river-water-dashes"),
],
)
def test_munge_tag_multiple_pass(self, original, expected):
"""Munge a list of tags muliple times gives expected results."""
first_munge = munge_tag(original)
assert first_munge == expected
second_munge = munge_tag(first_munge)
assert second_munge == expected
@pytest.mark.parametrize(
"original,expected",
[
("unchanged", "unchanged"),
("some spaces here &here", "some-spaces-here-here"),
("s", "s_"), # too short
("random:other%character&", "random-othercharacter"),
("u with umlaut \xfc", "u-with-umlaut-u"),
("reallylong" * 12, "reallylong" * 9),
("reallylong" * 12 + " - 2012", "reallylong" * 8 + "reall" + "-2012"),
(
"10cm - 50cm Near InfraRed (NI) Digital Aerial Photography (AfA142)",
"10cm-50cm-near-infrared-ni-digital-aerial-photography-afa142",
),
],
)
def test_munge_title_to_name(self, original, expected):
"""Munge a list of names gives expected results."""
munge = munge_title_to_name(original)
assert munge == expected
class TestGeneralUtils:
def test_args_parsing(self):
args = parse_args(["test-id", "test-type"])
assert args.jobId == "test-id"
assert args.jobType == "test-type"
@pytest.mark.parametrize(
"base,facets,expected",
[
("1", "", "1"),
("1", "234", "1 AND 234"),
("1", "2,3,4", "1 AND 2 AND 3 AND 4"),
("1", "2,3,4,", "1 AND 2 AND 3 AND 4"),
("1", "2 != 3,3 <= 4,", "1 AND 2 != 3 AND 3 <= 4"),
(None, "1,", "1"),
(None, "1 AND 2", "1 AND 2"),
(None, "1,2", "1 AND 2"),
(None, "1 , 2", "1 AND 2"),
(None, "1 OR 2", "1 OR 2"),
(None, ", facet_key = 'facet_val'", "facet_key = 'facet_val'"),
],
)
def test_facet_builder(self, base, facets, expected):
assert expected == query_filter_builder(base, facets)
@pytest.mark.parametrize(
"original,expected",
[
(
{
"readerStructureMessages": ["WARNING", "INFO"],
"readerValidationMessages": ["ERROR", "INFO"],
},
"structure messages: WARNING \nvalidation messages: ERROR",
),
(
{
"readerStructureMessages": ["WARNING", "INFO"],
"readerValidationMessages": ["INFO"],
},
"structure messages: WARNING \nvalidation messages: ",
),
(
{
"readerStructureMessages": [],
"readerValidationMessages": ["ERROR"],
},
"structure messages: \nvalidation messages: ERROR",
),
(
{
"readerStructureMessages": ["INFO"],
"readerValidationMessages": [],
},
"structure messages: \nvalidation messages: ",
),
],
)
def test_prepare_mdt_messages(self, original, expected):
assert prepare_transform_msg(original) == expected