예제 #1
0
    def test_hosts(self, factory, server, spec_path):
        spec_dict = factory.spec_from_file(spec_path)
        spec = Spec.create(spec_dict)
        validator = RequestValidator(spec)
        request = MockRequest(server, "get", "/status")

        result = validator.validate(request)

        assert not result.errors
예제 #2
0
    def test_invalid_path(self, factory, server, spec_path):
        spec_dict = factory.spec_from_file(spec_path)
        spec = Spec.create(spec_dict)
        validator = RequestValidator(spec)
        request = MockRequest(server, "get", "/nonexistent")

        result = validator.validate(request)

        assert len(result.errors) == 1
        assert isinstance(result.errors[0], PathNotFound)
        assert result.body is None
        assert result.parameters == Parameters()
예제 #3
0
    def test_param_present(self, factory, spec_path):
        spec_dict = factory.spec_from_file(spec_path)
        spec = Spec.create(spec_dict)

        path = spec / "paths#/resource/{resId}"

        parameters = path / "parameters"
        assert len(parameters) == 1

        param = parameters[0]
        assert param["name"] == "resId"
        assert param["required"]
        assert param["in"] == "path"
예제 #4
0
    def test_no_param(self, factory):
        spec_dict = factory.spec_from_file("data/v3.0/links.yaml")
        spec = Spec.create(spec_dict)
        resp = spec / "paths#/status#get#responses#default"

        links = resp / "links"
        assert len(links) == 1

        link = links / "noParamLink"
        assert link["operationId"] == "noParOp"
        assert "server" not in link
        assert "requestBody" not in link
        assert "parameters" not in link
예제 #5
0
    def test_param(self, factory):
        spec_dict = factory.spec_from_file("data/v3.0/links.yaml")
        spec = Spec.create(spec_dict)
        resp = spec / "paths#/status/{resourceId}#get#responses#default"

        links = resp / "links"
        assert len(links) == 1

        link = links / "paramLink"
        assert link["operationId"] == "paramOp"
        assert "server" not in link
        assert link["requestBody"] == "test"

        parameters = link["parameters"]
        assert len(parameters) == 1

        param = parameters["opParam"]
        assert param == "$request.path.resourceId"
예제 #6
0
    def test_request_override_param(self, spec_dict):
        # override path parameter on operation
        spec_dict["paths"]["/resource"]["get"]["parameters"] = [{
            # full valid parameter object required
            "name": "resId",
            "in": "query",
            "required": False,
            "schema": {
                "type": "integer",
            },
        }]
        validator = RequestValidator(Spec.create(spec_dict),
                                     base_url="http://example.com")
        request = MockRequest("http://example.com", "get", "/resource")
        result = validator.validate(request)

        assert len(result.errors) == 0
        assert result.body is None
        assert result.parameters == Parameters()
예제 #7
0
    def test_request_override_param_uniqueness(self, spec_dict):
        # add parameter on operation with same name as on path but
        # different location
        spec_dict["paths"]["/resource"]["get"]["parameters"] = [{
            # full valid parameter object required
            "name": "resId",
            "in": "header",
            "required": False,
            "schema": {
                "type": "integer",
            },
        }]
        validator = RequestValidator(Spec.create(spec_dict),
                                     base_url="http://example.com")
        request = MockRequest("http://example.com", "get", "/resource")
        result = validator.validate(request)

        assert len(result.errors) == 1
        assert type(result.errors[0]) == MissingRequiredParameter
        assert result.body is None
        assert result.parameters == Parameters()
예제 #8
0
 def flask_spec(self, factory):
     specfile = "contrib/flask/data/v3.0/flask_factory.yaml"
     return Spec.create(factory.spec_from_file(specfile))
예제 #9
0
 def spec(self, spec_dict):
     return Spec.create(spec_dict)
예제 #10
0
def spec(factory):
    spec_dict = factory.spec_from_file("data/v3.0/security_override.yaml")
    return Spec.create(spec_dict)
예제 #11
0
 def spec(self, spec_dict, spec_uri):
     return Spec.create(spec_dict, url=spec_uri)
def spec(factory):
    spec_dict = factory.spec_from_file("data/v3.0/read_only_write_only.yaml")
    return Spec.create(spec_dict)
예제 #13
0
 def test_raises_on_invalid(self, spec_dict):
     with pytest.raises(ValidationError):
         Spec.create(spec_dict)
 def spec(self, factory):
     specfile = "contrib/requests/data/v3.0/requests_factory.yaml"
     return Spec.create(factory.spec_from_file(specfile))