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