1+ import pytest
2+
3+ from ted_sws .core .model .manifestation import RDFManifestation
4+ from ted_sws .core .model .notice import NoticeStatus
5+ from ted_sws .core .model .transform import FileResource , SPARQLTestSuite , MetadataConstraints , TransformationRuleSet , \
6+ SHACLTestSuite , TransformationTestData , MappingSuite
7+ from tests import TEST_DATA_PATH
8+
9+ @pytest .fixture
10+ def query_content ():
11+ return """# title: Official name
12+ # description: this is a description
13+ PREFIX epo: <http://data.europa.eu/a4g/ontology#>
14+ ASK
15+ WHERE
16+ {
17+ ?this epo:playedBy / epo:hasDefaultContactPoint / epo:hasFax ?organisationContactPointFax .
18+ }
19+ """
20+
21+
22+ @pytest .fixture
23+ def query_content_without_description ():
24+ return """
25+
26+ # title : Official name
27+
28+ PREFIX epo: <http://data.europa.eu/a4g/ontology#>
29+ ASK
30+ WHERE
31+ {
32+ ?this epo:playedBy / epo:hasDefaultContactPoint / epo:hasFax ?organisationContactPointFax .
33+ }
34+ """
35+
36+
37+ @pytest .fixture
38+ def query_content_with_xpath ():
39+ return """
40+ # title: Official name
41+ #xpath: //some/xpath/goes/here
42+ # description: this is a description
43+
44+ PREFIX epo: <http://data.europa.eu/a4g/ontology#>
45+ ASK
46+ WHERE
47+ {
48+ ?this epo:playedBy / epo:hasDefaultContactPoint / epo:hasFax ?organisationContactPointFax .
49+ }
50+ """
51+
52+
53+ @pytest .fixture
54+ def rdf_file_content ():
55+ path = TEST_DATA_PATH / "example.ttl"
56+ return path .read_text ()
57+
58+
59+ @pytest .fixture
60+ def shacl_file_content ():
61+ path = TEST_DATA_PATH / "ePO_shacl_shapes.xml"
62+ return path .read_text ()
63+
64+
65+ @pytest .fixture
66+ def shacl_file_two_content ():
67+ path = TEST_DATA_PATH / "ePO_shacl_shapes_two.xml"
68+ return path .read_text ()
69+
70+
71+ @pytest .fixture
72+ def list_of_shacl_files (shacl_file_content , shacl_file_two_content ):
73+ return [
74+ FileResource (file_name = "shacl_file_one.xml" , file_content = shacl_file_content ),
75+ FileResource (file_name = "shacl_file_two.xml" , file_content = shacl_file_two_content )
76+ ]
77+
78+
79+ @pytest .fixture
80+ def shacl_file_one (shacl_file_content ):
81+ return FileResource (file_name = "shacl_file_one.xml" , file_content = shacl_file_content )
82+
83+
84+ @pytest .fixture
85+ def shacl_file_two (shacl_file_two_content ):
86+ return FileResource (file_name = "shacl_file_two.xml" , file_content = shacl_file_two_content )
87+
88+
89+ @pytest .fixture
90+ def shacl_file_with_error ():
91+ return FileResource (file_name = "shacl_file_with_error" , file_content = "something fishy" )
92+
93+
94+ @pytest .fixture
95+ def validator_query ():
96+ return """
97+ prefix dash: <http://datashapes.org/dash#>
98+ prefix sh: <http://www.w3.org/ns/shacl#>
99+ prefix message: <http://www.w3.org/ns/shacl#message>
100+
101+ SELECT ?focusNode ?message ?resultPath ?resultSeverity ?sourceConstraintComponent ?sourceShape ?value
102+ WHERE {
103+ ?vr a sh:ValidationResult .
104+ ?vr sh:focusNode ?focusNode .
105+ OPTIONAL {
106+ ?vr sh:message ?message .
107+ }
108+ OPTIONAL {
109+ ?vr sh:resultPath ?resultPath .
110+ }
111+ OPTIONAL {
112+ ?vr sh:resultSeverity ?resultSeverity .
113+ }
114+ OPTIONAL {
115+ ?vr sh:sourceConstraintComponent ?sourceConstraintComponent .
116+ }
117+ OPTIONAL {
118+ ?vr sh:sourceShape ?sourceShape .
119+ }
120+ OPTIONAL {
121+ ?vr sh:value ?value .
122+ }
123+ }
124+ ORDER BY ?focusNode ?resultSeverity ?sourceConstraintComponent
125+ """
126+
127+
128+ @pytest .fixture
129+ def sparql_file_one ():
130+ query = """# title: Title One
131+ # description: this is a description
132+ PREFIX epo: <http://data.europa.eu/a4g/ontology#>
133+ ASK
134+ WHERE
135+ {
136+ ?this epo:playedBy / epo:hasDefaultContactPoint / epo:hasFax ?organisationContactPointFax .
137+ }
138+ """
139+ return FileResource (file_name = "good_file" , file_content = query )
140+
141+
142+ @pytest .fixture
143+ def sparql_file_two ():
144+ query = """# title: Title Two
145+ # description: this is a description
146+ PREFIX epo: <http://data.europa.eu/a4g/ontology#>
147+ ASK
148+ WHERE
149+ {
150+ ?this epo:IsRoleOf / epo:hasName ?value .
151+ }
152+ """
153+ return FileResource (file_name = "better_file" , file_content = query )
154+
155+
156+ @pytest .fixture
157+ def invalid_sparql_file ():
158+ query = """# title: Title Two
159+ # description: this is a description
160+ ASK
161+ WHERE
162+ {
163+ ?this hasName ?value .
164+ }
165+ """
166+ return FileResource (file_name = "some_file" , file_content = query )
167+
168+
169+ @pytest .fixture
170+ def sparql_test_suite (sparql_file_one , sparql_file_two ):
171+ return SPARQLTestSuite (identifier = "sparql_test_package" , sparql_tests = [sparql_file_one , sparql_file_two ])
172+
173+
174+ @pytest .fixture
175+ def shacl_test_suite (shacl_file_one , shacl_file_two ):
176+ return SHACLTestSuite (identifier = "shacl_test_package" , shacl_tests = [shacl_file_one , shacl_file_two ])
177+
178+
179+ @pytest .fixture
180+ def bad_shacl_test_suite (shacl_file_one , shacl_file_with_error ):
181+ return SHACLTestSuite (identifier = "bad_shacl_test_package" , shacl_tests = [shacl_file_one , shacl_file_with_error ])
182+
183+
184+ @pytest .fixture
185+ def sparql_test_suite_with_invalid_query (invalid_sparql_file ):
186+ return SPARQLTestSuite (identifier = "sparql_test_package" , sparql_tests = [invalid_sparql_file ])
187+
188+
189+ @pytest .fixture
190+ def dummy_mapping_suite (sparql_test_suite , shacl_test_suite ):
191+ metadata_constrains = MetadataConstraints (constraints = dict ())
192+ file_name = "fake_title.txt"
193+ empty_file_resource = FileResource (file_name = file_name , file_content = "no content here" , original_name = file_name )
194+ transformation_rule_set = TransformationRuleSet (resources = [empty_file_resource ],
195+ rml_mapping_rules = [empty_file_resource ]
196+ )
197+ shacl_test_suite = shacl_test_suite
198+ sparql_test_suite = sparql_test_suite
199+ transformation_test_data = TransformationTestData (test_data = [empty_file_resource ])
200+ mapping_suite = MappingSuite (metadata_constraints = metadata_constrains ,
201+ transformation_rule_set = transformation_rule_set ,
202+ shacl_test_suites = [shacl_test_suite ],
203+ sparql_test_suites = [sparql_test_suite ],
204+ transformation_test_data = transformation_test_data
205+ )
206+ return mapping_suite
207+
208+
209+ @pytest .fixture
210+ def path_to_file_system_repository ():
211+ return TEST_DATA_PATH / "notice_transformer" / "test_repository"
212+
213+
214+ @pytest .fixture
215+ def notice_with_distilled_status (notice_2020 , rdf_file_content ):
216+
217+ notice_2020 .update_status_to (new_status = NoticeStatus .NORMALISED_METADATA )
218+ notice_2020 .update_status_to (new_status = NoticeStatus .ELIGIBLE_FOR_TRANSFORMATION )
219+ notice_2020 .update_status_to (new_status = NoticeStatus .PREPROCESSED_FOR_TRANSFORMATION )
220+ notice_2020 .set_rdf_manifestation (rdf_manifestation = RDFManifestation (object_data = rdf_file_content ))
221+ notice_2020 .set_distilled_rdf_manifestation (
222+ distilled_rdf_manifestation = RDFManifestation (object_data = rdf_file_content ))
223+ notice_2020 .update_status_to (new_status = NoticeStatus .DISTILLED )
224+
225+ return notice_2020
226+
227+
228+ @pytest .fixture
229+ def fake_repository_path ():
230+ return TEST_DATA_PATH / "notice_validator" / "test_repository"
231+
232+
233+ @pytest .fixture
234+ def invalid_mapping_suite_id () -> str :
235+ return "test_invalid_package"
236+
237+
238+ @pytest .fixture
239+ def cellar_sparql_endpoint ():
240+ return "https://publications.europa.eu/webapi/rdf/sparql"
0 commit comments