Exemple #1
0
    def test_replace_type(self):
        root = Root()

        version1 = Version()

        method1 = Method()

        object_type1 = ObjectType()
        object_type1.type_name = "t1"

        type1 = Type()

        parameter1 = Parameter()
        parameter1.type = "t1"

        parameter2 = Parameter()
        parameter2.type = "t1"

        method1.request_body = object_type1
        method1.request_parameters = {"p1": parameter1}
        method1.request_headers = {"p1": parameter2}

        version1.types = {"t1": type1}
        version1.methods = {"m1": method1}

        root.versions = {"v1": version1}

        self.source.replace_types(root)

        self.assertEqual(type1, method1.request_body.type_object)
        self.assertEqual(type1, method1.request_parameters["p1"].type_object)
        self.assertEqual(type1, method1.request_headers["p1"].type_object)
    def test_method(self):
        method = Method()
        method.name = "a"
        method.method = Method.Methods.post
        method.code = 200
        method.full_uri = "c"
        method.absolute_uri = "d"

        parameter = Parameter()
        parameter.type = "string"
        method.request_headers = {"e": parameter}
        method.request_parameters = {"f": parameter}
        method.request_body = ObjectObject()
        method.response_body = ObjectArray()

        method_sample = MethodSample(method)

        self.assertEqual("a", method_sample.name)
        self.assertEqual(Method.Methods.post, method_sample.method)
        self.assertEqual(200, method_sample.code)
        self.assertEqual("OK", method_sample.message)
        self.assertEqual("c", method_sample.full_uri)
        self.assertEqual("d", method_sample.absolute_uri)
        self.assertIsInstance(method_sample.request_headers, list)
        self.assertEqual(1, len(method_sample.request_headers))
        self.assertIsInstance(method_sample.request_headers[0],
                              ParameterSample)
        self.assertIsInstance(method_sample.request_parameters, dict)
        self.assertEqual(1, len(method_sample.request_parameters.values()))
        self.assertIsInstance(method_sample.request_parameters["f"],
                              ParameterSample)
        self.assertIsInstance(method_sample.request_body, ObjectObjectSample)
        self.assertIsInstance(method_sample.response_body, ObjectArraySample)
    def test_method(self):
        method = Method()
        method.name = "a"
        method.method = Method.Methods.post
        method.code = 200
        method.full_uri = "c"
        method.absolute_uri = "d"

        parameter = Parameter()
        parameter.type = "string"
        method.request_headers = {"e": parameter}
        method.request_parameters = {"f": parameter}
        method.request_body = ObjectObject()
        method.response_body = ObjectArray()

        method_sample = MethodSample(method)

        self.assertEqual("a", method_sample.name)
        self.assertEqual(Method.Methods.post, method_sample.method)
        self.assertEqual(200, method_sample.code)
        self.assertEqual("OK", method_sample.message)
        self.assertEqual("c", method_sample.full_uri)
        self.assertEqual("d", method_sample.absolute_uri)
        self.assertIsInstance(method_sample.request_headers, list)
        self.assertEqual(1, len(method_sample.request_headers))
        self.assertIsInstance(method_sample.request_headers[0], ParameterSample)
        self.assertIsInstance(method_sample.request_parameters, dict)
        self.assertEqual(1, len(method_sample.request_parameters.values()))
        self.assertIsInstance(method_sample.request_parameters["f"], ParameterSample)
        self.assertIsInstance(method_sample.request_body, ObjectObjectSample)
        self.assertIsInstance(method_sample.response_body, ObjectArraySample)
Exemple #4
0
    def create_from_name_and_dictionary(self, name, datas):
        """Return a populated object Method from dictionary datas
        """
        method = ObjectMethod()
        self.set_common_datas(method, name, datas)
        if "category" in datas:
            method.category = str(datas["category"])
        if "code" in datas:
            method.code = int(datas["code"])
        if "uri" in datas:
            method.uri = str(datas["uri"])
        if "method" in datas:
            method.method = self.get_enum("method", ObjectMethod.Methods,
                                          datas)

        method.request_headers = self.parameter_factory.create_dictionary_of_element_from_dictionary(
            "request_headers", datas)
        method.request_parameters = self.parameter_factory.create_dictionary_of_element_from_dictionary(
            "request_parameters", datas)
        method.response_codes = self.response_code_factory.create_list_of_element_from_dictionary(
            "response_codes", datas)

        if "request_body" in datas and datas["request_body"]:
            method.request_body = self.object_factory.create_from_name_and_dictionary(
                "request", datas["request_body"])
        if "response_body" in datas and datas["response_body"]:
            method.response_body = self.object_factory.create_from_name_and_dictionary(
                "response", datas["response_body"])
        return method
Exemple #5
0
    def create_from_name_and_dictionary(self, name, datas):
        """Return a populated object Method from dictionary datas
        """
        method = ObjectMethod()
        self.set_common_datas(method, name, datas)
        if "category" in datas:
            method.category = str(datas["category"])
        if "code" in datas:
            method.code = int(datas["code"])
        if "uri" in datas:
            method.uri = str(datas["uri"])
        if "method" in datas:
            method.method = self.get_enum("method", ObjectMethod.Methods, datas)

        method.request_headers = self.parameter_factory.create_dictionary_of_element_from_dictionary("request_headers", datas)
        method.request_parameters = self.parameter_factory.create_dictionary_of_element_from_dictionary("request_parameters", datas)
        method.response_codes = self.response_code_factory.create_list_of_element_from_dictionary("response_codes", datas)

        if "request_body" in datas and datas["request_body"]:
            method.request_body = self.object_factory.create_from_name_and_dictionary("request", datas["request_body"])
        if "response_body" in datas and datas["response_body"]:
            method.response_body = self.object_factory.create_from_name_and_dictionary("response", datas["response_body"])
        return method