|
1 | 1 | import pytest |
| 2 | +from jsonschema.exceptions import RefResolutionError |
2 | 3 |
|
3 | 4 | from openapi_spec_validator.validation.exceptions import OpenAPIValidationError |
4 | 5 |
|
5 | 6 |
|
| 7 | +class TestLocalOpenAPIv2Validator: |
| 8 | + |
| 9 | + LOCAL_SOURCE_DIRECTORY = "data/v2.0/" |
| 10 | + |
| 11 | + def local_test_suite_file_path(self, test_file): |
| 12 | + return f"{self.LOCAL_SOURCE_DIRECTORY}{test_file}" |
| 13 | + |
| 14 | + @pytest.mark.parametrize( |
| 15 | + "spec_file", |
| 16 | + [ |
| 17 | + "petstore.yaml", |
| 18 | + ], |
| 19 | + ) |
| 20 | + def test_valid(self, factory, validator_v2, spec_file): |
| 21 | + spec_path = self.local_test_suite_file_path(spec_file) |
| 22 | + spec = factory.spec_from_file(spec_path) |
| 23 | + spec_url = factory.spec_file_url(spec_path) |
| 24 | + |
| 25 | + return validator_v2.validate(spec, spec_url=spec_url) |
| 26 | + |
| 27 | + @pytest.mark.parametrize( |
| 28 | + "spec_file", |
| 29 | + [ |
| 30 | + "empty.yaml", |
| 31 | + ], |
| 32 | + ) |
| 33 | + def test_validation_failed(self, factory, validator_v2, spec_file): |
| 34 | + spec_path = self.local_test_suite_file_path(spec_file) |
| 35 | + spec = factory.spec_from_file(spec_path) |
| 36 | + spec_url = factory.spec_file_url(spec_path) |
| 37 | + |
| 38 | + with pytest.raises(OpenAPIValidationError): |
| 39 | + validator_v2.validate(spec, spec_url=spec_url) |
| 40 | + |
| 41 | + @pytest.mark.parametrize( |
| 42 | + "spec_file", |
| 43 | + [ |
| 44 | + "missing-reference.yaml", |
| 45 | + ], |
| 46 | + ) |
| 47 | + def test_ref_failed(self, factory, validator_v2, spec_file): |
| 48 | + spec_path = self.local_test_suite_file_path(spec_file) |
| 49 | + spec = factory.spec_from_file(spec_path) |
| 50 | + spec_url = factory.spec_file_url(spec_path) |
| 51 | + |
| 52 | + with pytest.raises(RefResolutionError): |
| 53 | + validator_v2.validate(spec, spec_url=spec_url) |
| 54 | + |
| 55 | + |
6 | 56 | class TestLocalOpenAPIv30Validator: |
7 | 57 |
|
8 | 58 | LOCAL_SOURCE_DIRECTORY = "data/v3.0/" |
@@ -31,7 +81,7 @@ def test_valid(self, factory, validator_v30, spec_file): |
31 | 81 | "empty.yaml", |
32 | 82 | ], |
33 | 83 | ) |
34 | | - def test_falied(self, factory, validator_v30, spec_file): |
| 84 | + def test_failed(self, factory, validator_v30, spec_file): |
35 | 85 | spec_path = self.local_test_suite_file_path(spec_file) |
36 | 86 | spec = factory.spec_from_file(spec_path) |
37 | 87 | spec_url = factory.spec_file_url(spec_path) |
|
0 commit comments