示例#1
0
    def test_parse_request_parameters_with_ref(self, patched_reference,
                                               instance):

        interface = OpenAPITaskInterface()
        interface.method = constants.POST
        interface.url = "url"
        interface.parameters = {"param_1": {constants.REF: "some_ref"}}

        instance.parse_request_parameters(interface, {})

        patched_reference.assert_called()
示例#2
0
    def test_functionality(self, patched_print, instance):
        inter_1 = OpenAPITaskInterface()
        inter_1.parameters = {
            # Resource, with path param, which has pure producers
            "param_1": {
                constants.RESOURCE: "resource_1",
                constants.IN_: constants.PATH_PARAM
            },
            # Resource but no path param
            "param_2": {
                constants.RESOURCE: "resource_2",
                constants.IN_: constants.BODY_PARAM
            },
            # No resource
            "param_3": {
                constants.IN_: constants.PATH_PARAM
            },
            # Resource with path param, does not have any pure producers
            "param_4": {
                constants.RESOURCE: "resource_4",
                constants.IN_: constants.PATH_PARAM
            },
        }

        instance.interfaces = [inter_1]

        res_1 = self.get_resource("resource_1")
        res_2 = self.get_resource("resource_2")
        res_3 = self.get_resource("resource_3")
        res_4 = self.get_resource("resource_4")
        res_5 = self.get_resource("resource_5")

        res_4.consumers.add("b")

        res_graph = ResourceGraph({})
        res_graph.nodes = {
            "res_1": res_1,
            "res_2": res_2,
            "res_3": res_3,
            "res_4": res_4,
            "res_5": res_5
        }

        instance.resource_graph = res_graph

        assert instance.get_resources_with_no_producers() == {"resource_4"}

        instance.validate()
        patched_print.assert_called()
示例#3
0
    def test_parse_request_parameters_with_destructor_resource(self, instance):
        interface = OpenAPITaskInterface()
        interface.method = constants.POST
        interface.url = "url"
        interface.parameters = {
            "param_1": {
                constants.RESOURCE: "some_resource"
            }
        }
        instance.is_delete_resource = mock.MagicMock(return_value=True)

        ref_graph = {}
        instance.parse_request_parameters(interface, ref_graph)

        assert ref_graph == {"some_resource": "destructor"}
示例#4
0
    def test_parse_request_parameters_with_body_params(self, instance):
        interface = OpenAPITaskInterface()
        interface.method = constants.POST
        interface.url = "url"
        interface.parameters = {
            "param_1": {
                constants.IN_: constants.BODY_PARAM
            }
        }
        instance.get_schema_refs = mock.MagicMock(
            return_value=["ref_1", "ref_2"])

        ref_graph = {"ref_1": "producer", "ref_3": "producer"}
        instance.parse_request_parameters(interface, ref_graph)

        assert ref_graph == {
            "ref_1": "producer",
            "ref_2": "consumer",
            "ref_3": "producer"
        }