Skip to content

Commit 98bb60e

Browse files
Create test_notice_operations.py
1 parent 26e76e1 commit 98bb60e

1 file changed

Lines changed: 375 additions & 0 deletions

File tree

Lines changed: 375 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,375 @@
1+
import pytest
2+
from pytest_bdd import scenario, given, when, then, parsers
3+
4+
from ted_sws.core.model.manifestation import RDFManifestation, RDFValidationManifestation, METSManifestation
5+
from ted_sws.core.model.metadata import NormalisedMetadata
6+
from ted_sws.core.model.notice import NoticeStatus
7+
8+
9+
def str2bool(value: str) -> bool:
10+
"""
11+
Parse a string value and cast it into its boolean value
12+
:param value:
13+
:return:
14+
"""
15+
if value in ["y", "yes", "t", "true", "on", "1"]: return True
16+
if value in ["n", "no", "f", "false", "off", "0"]: return False
17+
raise ValueError("boolean value unrecognised")
18+
19+
20+
@scenario("test_notice_operations.feature", "add normalised metadata")
21+
def test_add_normalised_metadata():
22+
pass
23+
24+
25+
@scenario("test_notice_operations.feature", "overwrite normalised metadata")
26+
def test_overwrite_normalised_metadata():
27+
pass
28+
29+
30+
@scenario("test_notice_operations.feature", "add RDF manifestation")
31+
def test_add_rdf_manifestation():
32+
pass
33+
34+
35+
@scenario("test_notice_operations.feature", "overwrite RDF manifestation")
36+
def test_overwrite_rdf_manifestation():
37+
pass
38+
39+
40+
@scenario("test_notice_operations.feature", "add validation report for a transformation")
41+
def test_add_validation_report_for_a_transformation():
42+
pass
43+
44+
45+
@scenario("test_notice_operations.feature", "cannot add a validation report when there is no transformation")
46+
def test_cannot_add_a_validation_report_when_there_is_no_transformation():
47+
pass
48+
49+
50+
@scenario("test_notice_operations.feature", "add METS manifestation")
51+
def test_add_mets_manifestation():
52+
pass
53+
54+
55+
@scenario("test_notice_operations.feature", "overwrite METS manifestation")
56+
def test_overwrite_mets_manifestation():
57+
pass
58+
59+
60+
@scenario("test_notice_operations.feature", "set notice eligibility for transformation before transformation")
61+
def test_set_notice_eligibility_for_transformation_before_transformation():
62+
pass
63+
64+
65+
@scenario("test_notice_operations.feature", "set notice eligibility for transformation after transformation")
66+
def test_set_notice_eligibility_for_transformation_after_transformation():
67+
pass
68+
69+
70+
@scenario("test_notice_operations.feature", "set notice eligibility for packaging before packaging")
71+
def test_set_notice_eligibility_for_packaging_when_validated():
72+
pass
73+
74+
75+
@scenario("test_notice_operations.feature", "set notice eligibility for packaging after packaging")
76+
def test_set_notice_eligibility_for_packaging_when_not_validated():
77+
pass
78+
79+
80+
@scenario("test_notice_operations.feature", "set notice eligibility for publishing after packaging")
81+
def test_set_mets_package_validity_when_package_is_available():
82+
pass
83+
84+
85+
@scenario("test_notice_operations.feature", "set notice eligibility for publishing after publishing")
86+
def test_set_mets_package_validity_when_package_is_missing():
87+
pass
88+
89+
90+
@scenario("test_notice_operations.feature", "mark notice as published if eligible")
91+
def test_mark_notice_as_published_if_eligible():
92+
pass
93+
94+
95+
@scenario("test_notice_operations.feature", "set notice public availability after publishing")
96+
def test_set_notice_public_availability_after_publishing():
97+
pass
98+
99+
100+
# --------------------------------
101+
# Step implementations
102+
# --------------------------------
103+
104+
@given("a notice", target_fixture="a_notice")
105+
def step_impl(publicly_available_notice):
106+
return publicly_available_notice
107+
108+
109+
@given("normalised metadata", target_fixture="normalised_metadata")
110+
def step_impl(normalised_metadata_dict):
111+
return NormalisedMetadata(**normalised_metadata_dict)
112+
113+
114+
@when("normalised metadata is added")
115+
def step_impl(indexed_notice, normalised_metadata):
116+
indexed_notice.set_normalised_metadata(normalised_metadata=normalised_metadata)
117+
118+
119+
@then("the notice object contains the normalised metadata")
120+
def step_impl(indexed_notice):
121+
assert indexed_notice.normalised_metadata is not None
122+
123+
124+
@then("the notice status is NORMALISED_METADATA")
125+
def step_impl(indexed_notice):
126+
assert indexed_notice.status is NoticeStatus.NORMALISED_METADATA
127+
128+
129+
@given("the notice already contains normalised metadata")
130+
def step_impl(indexed_notice, normalised_metadata_dict):
131+
indexed_notice.set_normalised_metadata(NormalisedMetadata(**normalised_metadata_dict))
132+
assert indexed_notice.normalised_metadata is not None
133+
134+
135+
@when("normalised metadata is overwritten", target_fixture="old_normalised_metadata")
136+
def step_impl(indexed_notice, normalised_metadata):
137+
assert indexed_notice.normalised_metadata is not None
138+
old = indexed_notice.normalised_metadata
139+
normalised_metadata.notice_publication_number = "something else"
140+
indexed_notice.set_normalised_metadata(normalised_metadata=normalised_metadata)
141+
return old
142+
143+
144+
@then("the notice object contains the new normalised metadata")
145+
def step_impl(indexed_notice, normalised_metadata, old_normalised_metadata):
146+
assert indexed_notice.normalised_metadata == normalised_metadata
147+
assert indexed_notice.normalised_metadata != old_normalised_metadata
148+
149+
150+
@then("normalised notice contains no RDF manifestation")
151+
def step_impl(indexed_notice):
152+
assert indexed_notice.rdf_manifestation is None
153+
154+
155+
@then("notice contains no RDF validation")
156+
def step_impl(transformation_eligible_notice):
157+
assert transformation_eligible_notice
158+
print(
159+
f"transformation_eligible_notice.get_rdf_validation() = {transformation_eligible_notice.get_rdf_validation()}")
160+
assert transformation_eligible_notice.get_rdf_validation() == []
161+
162+
163+
@then("notice not contains RDF validation")
164+
def step_impl(transformation_eligible_notice):
165+
assert transformation_eligible_notice
166+
print(
167+
f"transformation_eligible_notice.get_rdf_validation() = {transformation_eligible_notice.get_rdf_validation()}")
168+
assert transformation_eligible_notice.get_rdf_validation() is None
169+
170+
171+
@then("notice contains no METS manifestation")
172+
def step_impl(transformation_eligible_notice):
173+
assert transformation_eligible_notice.mets_manifestation is None
174+
175+
176+
@given("RDF manifestation", target_fixture="rdf_manifestation")
177+
def step_impl():
178+
return RDFManifestation(object_data="featured object data of the RDF manifestation")
179+
180+
181+
@when("RDF manifestation is added")
182+
def step_impl(transformation_eligible_notice, rdf_manifestation):
183+
transformation_eligible_notice.set_rdf_manifestation(rdf_manifestation)
184+
185+
186+
@then("the notice object contains the RDF manifestation")
187+
def step_impl(transformation_eligible_notice, rdf_manifestation):
188+
assert transformation_eligible_notice.rdf_manifestation == rdf_manifestation
189+
190+
191+
@then("the notice status is TRANSFORMED")
192+
def step_impl(transformation_eligible_notice):
193+
assert transformation_eligible_notice.status is NoticeStatus.TRANSFORMED
194+
195+
196+
@given("the notice already contains an RDF manifestation")
197+
def step_impl(transformation_eligible_notice, rdf_manifestation):
198+
transformation_eligible_notice.set_rdf_manifestation(
199+
rdf_manifestation=RDFManifestation(object_data="data some data"))
200+
201+
202+
@when("the RDF manifestation is overwritten", target_fixture="old_rdf_manifestation")
203+
def step_impl(transformation_eligible_notice, rdf_manifestation):
204+
old_manifestation = transformation_eligible_notice.rdf_manifestation
205+
transformation_eligible_notice.set_rdf_manifestation(rdf_manifestation)
206+
return old_manifestation
207+
208+
209+
@then("the notice object contains the new RDF manifestation")
210+
def step_impl(transformation_eligible_notice, old_rdf_manifestation, rdf_manifestation):
211+
assert transformation_eligible_notice.rdf_manifestation != old_rdf_manifestation
212+
assert transformation_eligible_notice.rdf_manifestation == rdf_manifestation
213+
214+
215+
@given("RDF validation report", target_fixture="rdf_validation")
216+
def step_impl():
217+
return RDFValidationManifestation(object_data="this is another validation report",
218+
test_suite_identifier="test_suite_id",
219+
mapping_suite_identifier="mapping_suite_id"
220+
)
221+
222+
223+
@given("the notice contains an RDF manifestation")
224+
def step_impl(transformation_eligible_notice):
225+
transformation_eligible_notice.set_rdf_manifestation(
226+
rdf_manifestation=RDFManifestation(object_data="data some data"))
227+
228+
229+
@when("RDF validation report is added an exception is raised")
230+
def step_impl(transformation_eligible_notice, rdf_validation):
231+
with pytest.raises(Exception):
232+
transformation_eligible_notice.set_rdf_validation(rdf_validation)
233+
234+
235+
@then("the notice object contains the RDF validation report")
236+
def step_impl(transformation_eligible_notice):
237+
assert transformation_eligible_notice.get_rdf_validation() is not None
238+
239+
240+
@then("the notice status is VALIDATED")
241+
def step_impl(transformation_eligible_notice):
242+
# TODO: Change feature text and tests, once the SPARQL test suite was refactor
243+
# assert transformation_eligible_notice.status is NoticeStatus.VALIDATED
244+
assert transformation_eligible_notice.status is NoticeStatus.DISTILLED
245+
transformation_eligible_notice.update_status_to(new_status=NoticeStatus.VALIDATED)
246+
247+
248+
@given("the notice does not contains an RDF manifestation")
249+
def step_impl(transformation_eligible_notice):
250+
transformation_eligible_notice._rdf_manifestation = None
251+
252+
253+
@given("METS manifestation", target_fixture="mets_manifestation")
254+
def step_impl():
255+
return METSManifestation(object_data="THE METS manifestation")
256+
257+
258+
@when("METS manifestation is added")
259+
def step_impl(packaging_eligible_notice, mets_manifestation):
260+
packaging_eligible_notice.set_mets_manifestation(mets_manifestation=mets_manifestation)
261+
262+
263+
@then("the notice object contains the METS manifestation")
264+
def step_impl(packaging_eligible_notice, mets_manifestation):
265+
assert packaging_eligible_notice.mets_manifestation == mets_manifestation
266+
267+
268+
@then("the notice status is PACKAGED")
269+
def step_impl(packaging_eligible_notice):
270+
assert packaging_eligible_notice.status is NoticeStatus.PACKAGED
271+
272+
273+
@given("the notice already contains an METS manifestation", target_fixture="packaging_eligible_notice")
274+
def step_impl(publicly_available_notice):
275+
publicly_available_notice.update_status_to(NoticeStatus.PACKAGED)
276+
return publicly_available_notice
277+
278+
279+
@then("the notice object contains the new METS manifestation")
280+
def step_impl(packaging_eligible_notice, mets_manifestation):
281+
assert packaging_eligible_notice.mets_manifestation == mets_manifestation
282+
283+
284+
@given(parsers.parse("eligibility check result is {eligibility}"),
285+
target_fixture="eligibility")
286+
def step_impl(eligibility):
287+
return str2bool(eligibility)
288+
289+
290+
@given("the notice status is lower than TRANSFORMED")
291+
def step_impl(a_notice):
292+
a_notice.update_status_to(NoticeStatus.NORMALISED_METADATA)
293+
294+
295+
@when("eligibility for transformation is set")
296+
def step_impl(a_notice, eligibility):
297+
a_notice.set_is_eligible_for_transformation(eligibility)
298+
299+
300+
@then(parsers.parse("notice status is {notice_status}"))
301+
def step_impl(a_notice, notice_status):
302+
assert a_notice.status == NoticeStatus[notice_status]
303+
304+
305+
@given("the notice status is equal or greater than TRANSFORMED")
306+
def step_impl(a_notice):
307+
a_notice.update_status_to(NoticeStatus.VALIDATED)
308+
309+
310+
@when("eligibility for packaging is set")
311+
def step_impl(a_notice, eligibility):
312+
a_notice.set_is_eligible_for_packaging(eligibility)
313+
314+
315+
@given("notice contains a METS package")
316+
def step_impl(a_notice):
317+
a_notice.update_status_to(NoticeStatus.PACKAGED)
318+
319+
320+
@when("the package validity is set")
321+
def step_impl(a_notice, eligibility):
322+
a_notice.set_is_eligible_for_publishing(eligibility)
323+
324+
325+
@when("the notice is marked as published")
326+
def step_impl(a_notice):
327+
a_notice.mark_as_published()
328+
329+
330+
@when("public availability is set")
331+
def step_impl(a_notice, availability):
332+
a_notice.set_is_publicly_available(availability)
333+
334+
335+
@given("a notice eligible for transformation", )
336+
def step_impl(transformation_eligible_notice):
337+
assert transformation_eligible_notice.status is NoticeStatus.PREPROCESSED_FOR_TRANSFORMATION
338+
339+
340+
@when("RDF validation report is added")
341+
def step_impl(transformation_eligible_notice, rdf_validation):
342+
transformation_eligible_notice.update_status_to(NoticeStatus.DISTILLED)
343+
transformation_eligible_notice.set_rdf_validation(rdf_validation)
344+
345+
346+
@given("a packaging eligible notice", target_fixture="packaging_eligible_notice")
347+
def step_impl(publicly_available_notice):
348+
publicly_available_notice.update_status_to(NoticeStatus.ELIGIBLE_FOR_PACKAGING)
349+
return publicly_available_notice
350+
351+
352+
@given("the notice is validated")
353+
def step_impl(a_notice):
354+
a_notice.update_status_to(NoticeStatus.VALIDATED)
355+
356+
357+
@given("the notice is published")
358+
def step_impl(a_notice):
359+
a_notice.update_status_to(NoticeStatus.PUBLISHED)
360+
361+
362+
@given("the notice is packaged")
363+
def step_impl(a_notice):
364+
a_notice.update_status_to(NoticeStatus.PACKAGED)
365+
366+
367+
@then("the notice cannot be marked as published")
368+
def step_impl(a_notice):
369+
with pytest.raises(Exception):
370+
a_notice.mark_as_published()
371+
372+
373+
@given(parsers.parse("availability check result is {availability}"), target_fixture="availability")
374+
def step_impl(availability):
375+
return str2bool(availability)

0 commit comments

Comments
 (0)