|
| 1 | +"""Notice Validator feature tests.""" |
| 2 | + |
| 3 | +from pytest_bdd import ( |
| 4 | + given, |
| 5 | + scenario, |
| 6 | + then, |
| 7 | + when, |
| 8 | +) |
| 9 | + |
| 10 | +from ted_sws.core.model.manifestation import SHACLTestSuiteValidationReport, \ |
| 11 | + SPARQLTestSuiteValidationReport |
| 12 | +from ted_sws.core.model.notice import Notice, NoticeStatus |
| 13 | +from ted_sws.core.model.transform import MappingSuite |
| 14 | +from ted_sws.notice_validator.services.shacl_test_suite_runner import validate_notice_with_shacl_suite |
| 15 | +from ted_sws.notice_validator.services.sparql_test_suite_runner import validate_notice_with_sparql_suite |
| 16 | + |
| 17 | + |
| 18 | +@scenario('test_notice_validator.feature', 'SHACL validation') |
| 19 | +def test_shacl_validation(): |
| 20 | + """SHACL validation.""" |
| 21 | + |
| 22 | + |
| 23 | +@scenario('test_notice_validator.feature', 'SPARQL validation') |
| 24 | +def test_sparql_validation(): |
| 25 | + """SPARQL validation.""" |
| 26 | + |
| 27 | + |
| 28 | +@given('a mapping suite package') |
| 29 | +def a_mapping_suite_package(mapping_suite): |
| 30 | + """a mapping suite package.""" |
| 31 | + assert mapping_suite |
| 32 | + assert isinstance(mapping_suite, MappingSuite) |
| 33 | + |
| 34 | + |
| 35 | +@given('a notice') |
| 36 | +def a_notice(notice_with_distilled_status): |
| 37 | + """a notice.""" |
| 38 | + assert notice_with_distilled_status |
| 39 | + assert isinstance(notice_with_distilled_status, Notice) |
| 40 | + |
| 41 | + |
| 42 | +@given('at least one SHACL test suite is available') |
| 43 | +def at_least_one_shacl_test_suite_is_available(mapping_suite): |
| 44 | + """at least one SHACL test suite is available.""" |
| 45 | + assert mapping_suite.shacl_test_suites |
| 46 | + assert len(mapping_suite.shacl_test_suites) |
| 47 | + |
| 48 | + |
| 49 | +@given('at least one SPARQL test suite is available') |
| 50 | +def at_least_one_sparql_test_suite_is_available(mapping_suite): |
| 51 | + """at least one SPARQL test suite is available.""" |
| 52 | + assert mapping_suite.sparql_test_suites |
| 53 | + assert len(mapping_suite.sparql_test_suites) |
| 54 | + |
| 55 | + |
| 56 | +@given('the notice status is DISTILLED') |
| 57 | +def the_notice_status_is_distilled(notice_with_distilled_status): |
| 58 | + """the notice status is DISTILLED.""" |
| 59 | + assert notice_with_distilled_status.status == NoticeStatus.DISTILLED |
| 60 | + |
| 61 | + |
| 62 | +@when('the notice shacl validation is executed', target_fixture="shacl_validated_notice") |
| 63 | +def the_notice_shacl_validation_is_executed(notice_with_distilled_status, mapping_suite): |
| 64 | + """the notice shacl validation is executed.""" |
| 65 | + validate_notice_with_shacl_suite(notice=notice_with_distilled_status, mapping_suite_package=mapping_suite) |
| 66 | + return notice_with_distilled_status |
| 67 | + |
| 68 | + |
| 69 | +@when('the notice sparql validation is executed', target_fixture="sparql_validated_notice") |
| 70 | +def the_notice_sparql_validation_is_executed(notice_with_distilled_status, mapping_suite): |
| 71 | + """the notice sparql validation is executed.""" |
| 72 | + validate_notice_with_sparql_suite(notice=notice_with_distilled_status, mapping_suite_package=mapping_suite) |
| 73 | + return notice_with_distilled_status |
| 74 | + |
| 75 | + |
| 76 | +@then('the notice have SHACL validation reports for each RDF manifestation') |
| 77 | +def the_notice_have_shacl_validation_reports_for_each_rdf_manifestation(shacl_validated_notice): |
| 78 | + """the notice have SHACL validation reports for each RDF manifestation.""" |
| 79 | + notice = shacl_validated_notice |
| 80 | + rdf_validation = notice.get_rdf_validation() |
| 81 | + distilled_rdf_validation = notice.get_distilled_rdf_validation() |
| 82 | + assert notice.status == NoticeStatus.DISTILLED |
| 83 | + assert isinstance(rdf_validation, list) |
| 84 | + assert len(rdf_validation) == 1 |
| 85 | + assert isinstance(rdf_validation[0], SHACLTestSuiteValidationReport) |
| 86 | + assert rdf_validation[0].object_data |
| 87 | + assert rdf_validation[0].validation_results |
| 88 | + assert isinstance(distilled_rdf_validation, list) |
| 89 | + assert len(distilled_rdf_validation) == 1 |
| 90 | + assert isinstance(distilled_rdf_validation[0], SHACLTestSuiteValidationReport) |
| 91 | + assert distilled_rdf_validation[0].object_data |
| 92 | + assert distilled_rdf_validation[0].validation_results |
| 93 | + |
| 94 | + |
| 95 | +@then('the notice have SPARQL validation reports for each RDF manifestation') |
| 96 | +def the_notice_have_sparql_validation_reports_for_each_rdf_manifestation(sparql_validated_notice): |
| 97 | + """the notice have SPARQL validation reports for each RDF manifestation.""" |
| 98 | + notice = sparql_validated_notice |
| 99 | + rdf_validation = notice.get_rdf_validation() |
| 100 | + distilled_rdf_validation = notice.get_distilled_rdf_validation() |
| 101 | + assert notice.status == NoticeStatus.DISTILLED |
| 102 | + assert isinstance(rdf_validation, list) |
| 103 | + assert len(rdf_validation) == 1 |
| 104 | + assert isinstance(rdf_validation[0], SPARQLTestSuiteValidationReport) |
| 105 | + assert rdf_validation[0].object_data |
| 106 | + assert rdf_validation[0].validation_results |
| 107 | + assert isinstance(distilled_rdf_validation, list) |
| 108 | + assert len(distilled_rdf_validation) == 1 |
| 109 | + assert isinstance(distilled_rdf_validation[0], SPARQLTestSuiteValidationReport) |
| 110 | + assert distilled_rdf_validation[0].object_data |
| 111 | + assert distilled_rdf_validation[0].validation_results |
0 commit comments