-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest_standard.py
165 lines (154 loc) · 6.24 KB
/
test_standard.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2017-2019 CERN.
#
# Invenio is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Invenio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02D111-1307, USA.
"""Book fields tests."""
from __future__ import absolute_import, print_function, unicode_literals
from copy import deepcopy
from cds_dojson.marc21.models.books.base import get_migration_dict
from cds_dojson.marc21.models.books.standard import model
from cds_dojson.marc21.utils import create_record
marcxml = ("""<collection xmlns="http://www.loc.gov/MARC21/slim">"""
"""<record>{0}</record></collection>""")
def check_transformation(marcxml_body, json_body):
blob = create_record(marcxml.format(marcxml_body))
record = {'_migration': {**get_migration_dict()}}
record.update(**model.do(blob, ignore_missing=False))
expected = {
'$schema': 'https://127.0.0.1:5000/schemas/documents/document-v1.0.0.json',
'_migration': {**get_migration_dict()}
}
expected.update(**json_body)
assert record == expected
def test_title(app):
with app.app_context():
check_transformation(
"""
<datafield tag="245" ind1=" " ind2=" ">
<subfield code="a">Incoterms 2010</subfield>
<subfield code="b">les règles de l'ICC</subfield>
</datafield>
""",
{
'title': 'Incoterms 2010',
'alternative_titles': [
{'value': "les règles de l'ICC", 'type': 'SUBTITLE'},
]
}
)
check_transformation(
"""
<datafield tag="690" ind1="C" ind2=" ">
<subfield code="a">STANDARD</subfield>
</datafield>
<datafield tag="245" ind1=" " ind2=" ">
<subfield code="a">Test</subfield>
<subfield code="b">Subtitle</subfield>
</datafield>
<datafield tag="246" ind1=" " ind2=" ">
<subfield code="a">Water quality — sampling</subfield>
<subfield code="b">
part 15: guidance on the preservation and handling of sludge
</subfield>
</datafield>
""",
{
'document_type': 'STANDARD',
'title': 'Test',
'alternative_titles': [
{'value': 'Subtitle', 'type': 'SUBTITLE'},
{'value': 'Water quality — sampling',
'type': 'TRANSLATED_TITLE',
'language': 'fr',
},
{
'type': 'TRANSLATED_SUBTITLE',
'value': u"""part 15: guidance on the preservation and handling of sludge""",
'language': 'fr',
}
],
}
)
check_transformation(
"""
<datafield tag="690" ind1="C" ind2=" ">
<subfield code="a">STANDARD</subfield>
</datafield>
<datafield tag="245" ind1=" " ind2=" ">
<subfield code="a">Test</subfield>
<subfield code="b">Subtitle</subfield>
</datafield>
<datafield tag="246" ind1=" " ind2=" ">
<subfield code="a">Water quality — sampling</subfield>
<subfield code="b">
part 15: guidance on the preservation and handling of sludge
</subfield>
</datafield>
<datafield tag="300" ind1=" " ind2=" ">
<subfield code="a">373 p</subfield>
</datafield>
""", {
'document_type': 'STANDARD',
'title': 'Test',
'alternative_titles': [
{'value': 'Subtitle', 'type': 'SUBTITLE'},
{'value': 'Water quality — sampling',
'type': 'TRANSLATED_TITLE',
'language': 'fr',
},
{
'type': 'TRANSLATED_SUBTITLE',
'value': u"""part 15: guidance on the preservation and handling of sludge""",
'language': 'fr',
}
],
'number_of_pages': 373,
})
check_transformation(
"""
<datafield tag="690" ind1="C" ind2=" ">
<subfield code="a">STANDARD</subfield>
</datafield>
<datafield tag="245" ind1=" " ind2=" ">
<subfield code="a">Test</subfield>
<subfield code="b">Subtitle</subfield>
</datafield>
<datafield tag="246" ind1=" " ind2=" ">
<subfield code="a">Water quality — sampling</subfield>
<subfield code="b">
part 15: guidance on the preservation and handling of sludge
</subfield>
</datafield>
<datafield tag="300" ind1=" " ind2=" ">
<subfield code="a">mult. p</subfield>
</datafield>
""", {
'document_type': 'STANDARD',
'title': 'Test',
'alternative_titles': [
{'value': 'Subtitle', 'type': 'SUBTITLE'},
{'value': 'Water quality — sampling',
'type': 'TRANSLATED_TITLE',
'language': 'fr',
},
{
'type': 'TRANSLATED_SUBTITLE',
'value': u"""part 15: guidance on the preservation and handling of sludge""",
'language': 'fr',
}
],
})