Example #1
0
    def test_positionable_parameter_compare__with_position_negative(self):
        parameter1 = RequestParameterDto(Parameter())
        parameter2 = RequestParameterDto(Parameter())
        parameter1.position = -1
        parameter2.position = 2

        self.assertTrue(parameter1 > parameter2)
Example #2
0
    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)
Example #3
0
    def test_parameter_compare__with_name(self):
        parameter1 = ParameterDto(Parameter())
        parameter2 = ParameterDto(Parameter())
        parameter1.name = "a"
        parameter2.name = "b"

        self.assertEqual(parameter1, sorted([parameter2, parameter1])[0])
Example #4
0
    def test_get_uri_with_missing_parameters(self):
        root = Root()
        version = Version()
        version.name = "v"
        method = Method()
        method.name = "m"
        method.category = "a"
        method.full_uri = "/{foo}/{p}"

        parameter = Parameter()
        parameter.name = "p"
        parameter.type = "string"
        method.request_parameters = {"p": parameter}

        root.versions = {"v": version}
        version.methods = {"m": method}
        version.types = {"m": type}

        root_dto = RootDto()

        hydrator = Hydrator(version, {"v": version}, [])
        hydrator.hydrate_method(root_dto, root, method)

        parameters = self.source.validate(root_dto)
        parameters = self.source.get_uri_with_missing_parameters(root_dto)

        self.assertEqual([
            {
                "name": "foo",
                "uri": "/{foo}/{p}",
                "method": "m",
                "version": "v"
            },
        ], parameters)
Example #5
0
    def test_get_uri_with_missing_parameters(self):
        root = Root()
        version = Version()
        version.name = "v"
        method = Method()
        method.name = "m"
        method.category = "a"
        method.full_uri = "/{foo}/{p}"

        parameter = Parameter()
        parameter.name = "p"
        parameter.type = "string"
        method.request_parameters = {"p": parameter}

        root.versions = {"v": version}
        version.methods = {"m": method}
        version.types = {"m": type}

        root_dto = RootDto()

        hydrator = Hydrator(version, {"v": version}, [])
        hydrator.hydrate_method(root_dto, root, method)

        parameters = self.source.validate(root_dto)
        parameters = self.source.get_uri_with_missing_parameters(root_dto)

        self.assertEqual([
            {"name": "foo", "uri": "/{foo}/{p}", "method": "m", "version": "v"},
        ], parameters)
Example #6
0
    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)
Example #7
0
    def test_replace_types_in_parameter___scalara(self):
        object = Parameter()
        object.type = "string"

        response = self.source.replace_types_in_parameter(object, {})

        self.assertEqual(object, response)
Example #8
0
    def test_hydrate_method(self):

        root = Root()
        version = Version()
        version.name = "v"
        method = Method()
        method.category = "a"
        method.full_uri = "/{p}/"

        parameter = Parameter()
        parameter.name = "p"
        parameter.type = "string"
        method.request_parameters = {"p": parameter}

        root.versions = {"v": version}
        version.methods = {"m": method}
        version.types = {"m": type}

        root_dto = RootDto()

        hydrator = Hydrator(version, {"v": version}, [])

        hydrator.hydrate_method(root_dto, root, method)

        self.assertEqual(1, len(root_dto.method_categories))
        self.assertEqual(0, len(root_dto.type_categories))
        self.assertEqual(1, len(root_dto.method_categories[0].methods))
        self.assertEqual(1, len(root_dto.method_categories[0].methods[0].request_parameters))
        self.assertIsInstance(root_dto.method_categories[0].methods[0].request_parameters[0].value, RequestParameter)
        self.assertEqual(1, root_dto.method_categories[0].methods[0].request_parameters[0].value.position)
Example #9
0
    def test_method(self):
        method = Method()
        method.name = "a"
        method.description = "b"
        method.method = Method.Methods.put

        parameter1 = RequestParameterDto(Parameter())
        parameter1.position = 2
        parameter2 = RequestParameterDto(Parameter())
        parameter2.position = -1
        method.parameter = {"p1": parameter1, "p2": parameter2}

        method_dto = MethodDto(method)

        self.assertEqual("a", method_dto.name)
        self.assertEqual("put", str(method_dto.method))
        self.assertEqual([], method_dto.description)

        self.assertEqual([], method_dto.code)
        self.assertEqual([], method_dto.full_uri)
        self.assertEqual([], method_dto.absolute_uri)
        self.assertEqual([], method_dto.request_headers)
        self.assertEqual([], method_dto.request_parameters)
        self.assertEqual([], method_dto.request_body)
        self.assertEqual([], method_dto.response_codes)
        self.assertEqual([], method_dto.response_body)
        self.assertEqual([], method_dto.versions)
        self.assertEqual({}, method_dto.changes_status)
        self.assertEqual({}, method_dto.samples)

        m1 = MultiVersionDto(parameter1, "v1")
        m2 = MultiVersionDto(parameter2, "v1")
        method_dto.request_parameters = [m1, m2]
        self.assertEqual([m1], method_dto.request_uri_parameters)
        self.assertEqual([m2], method_dto.request_query_string_parameters)
Example #10
0
    def test_positionable_parameter_compare__with_position(self):
        parameter1 = RequestParameterDto(Parameter())
        parameter2 = RequestParameterDto(Parameter())
        parameter1.position = 1
        parameter2.position = 2

        self.assertTrue(parameter1 < parameter2)
        self.assertEqual(parameter1, parameter2)
Example #11
0
    def test_parameter_get_default_sample__for_type(self):
        test = Parameter()

        type = Type()
        type.item = ObjectString()
        type.item.name = "a"

        test.type = "b"
        test.type_object = type

        self.assertEqual("my_a", test.get_default_sample())
Example #12
0
    def test_parameter(self):
        parameter = Parameter()
        parameter.name = "a"
        parameter.type = "string"
        parameter.optional = True
        parameter.position = 0

        parameter_sample = ParameterSample(parameter)

        self.assertEqual("a", parameter_sample.name)
        self.assertTrue(parameter_sample.optional)
        self.assertEqual("my_a", parameter_sample.sample)
        self.assertFalse(parameter_sample.is_query_string)
Example #13
0
    def create_from_name_and_dictionary(self, name, datas):
        """Return a populated object Parameter from dictionary datas
        """
        parameter = ObjectParameter()
        self.set_common_datas(parameter, name, datas)

        if "optional" in datas:
            parameter.optional = to_boolean(datas["optional"])
        if "type" in datas:
            parameter.type = str(datas["type"])
        if "generic" in datas:
            parameter.generic = to_boolean(datas["generic"])

        return parameter
Example #14
0
    def test_parameter_compare__with_name(self):
        parameter = Parameter()
        parameter.name = "a"
        parameter.type = "string"
        parameter.optional = True
        parameter.position = 0

        parameter_sample1 = ParameterSample(parameter)
        parameter_sample2 = ParameterSample(parameter)

        parameter_sample1.name = "a"
        parameter_sample2.name = "b"

        self.assertTrue(parameter_sample1 < parameter_sample2)
Example #15
0
    def create_from_name_and_dictionary(self, name, datas):
        """Return a populated object Parameter from dictionary datas
        """
        parameter = ObjectParameter()
        self.set_common_datas(parameter, name, datas)

        if "optional" in datas:
            parameter.optional = to_bool(datas["optional"])
        if "type" in datas:
            parameter.type = str(datas["type"])
        if "generic" in datas:
            parameter.generic = to_bool(datas["generic"])

        return parameter
Example #16
0
    def test_positionable_parameter(self):
        parameter = Parameter()
        parameter.name = "a"
        parameter.description = "b"
        parameter.type = "foo"
        parameter.optional = False

        parameter_dto = RequestParameterDto(parameter)

        self.assertEqual("a", parameter_dto.name)
        self.assertEqual("b", parameter_dto.description)
        self.assertEqual(False, parameter_dto.optional)
        self.assertEqual(False, parameter_dto.is_internal)
        self.assertEqual(0, parameter_dto.position)
        self.assertEqual(False, parameter_dto.is_query_string)
Example #17
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)
Example #18
0
    def test_remove_unused_types(self):
        root = Root()

        version1 = Version()

        type1 = Type()
        type2 = Type()

        method1 = Method()

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

        method1.request_parameters = {"p1": parameter1}

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

        root.versions = {"v1": version1}

        self.source.remove_unused_types(root)

        self.assertEqual({"t1": type1}, version1.types)
Example #19
0
    def test_hydrate_method(self):

        root = Root()
        version = Version()
        version.name = "v"
        method = Method()
        method.category = "a"
        method.full_uri = "/{p}/"

        parameter = Parameter()
        parameter.name = "p"
        parameter.type = "string"
        method.request_parameters = {"p": parameter}

        root.versions = {"v": version}
        version.methods = {"m": method}
        version.types = {"m": type}

        root_dto = RootDto()

        hydrator = Hydrator(version, {"v": version}, [])

        hydrator.hydrate_method(root_dto, root, method)

        self.assertEqual(1, len(root_dto.method_categories))
        self.assertEqual(0, len(root_dto.type_categories))
        self.assertEqual(1, len(root_dto.method_categories[0].methods))
        self.assertEqual(
            1,
            len(root_dto.method_categories[0].methods[0].request_parameters))
        self.assertIsInstance(
            root_dto.method_categories[0].methods[0].request_parameters[0].
            value, RequestParameter)
        self.assertEqual(
            1, root_dto.method_categories[0].methods[0].request_parameters[0].
            value.position)
Example #20
0
    def test_parameter(self):
        parameter = Parameter()
        parameter.name = "a"
        parameter.description = "b"
        parameter.type = "foo"
        parameter.optional = False
        parameter.position = 1

        parameter_dto = RequestParameterDto(parameter)

        self.assertEqual("a", parameter_dto.name)
        self.assertEqual("b", parameter_dto.description)
        self.assertEqual(False, parameter_dto.optional)
        self.assertEqual(False, parameter_dto.is_internal)
        self.assertFalse(parameter_dto.is_query_string)
Example #21
0
    def test_parameter(self):
        parameter = Parameter()
        parameter.name = "a"
        parameter.type = "string"
        parameter.optional = True
        parameter.position = 0

        parameter_sample = ParameterSample(parameter)

        self.assertEqual("a", parameter_sample.name)
        self.assertTrue(parameter_sample.optional)
        self.assertEqual("my_a", parameter_sample.sample)
        self.assertFalse(parameter_sample.is_query_string)
Example #22
0
    def test_parameter_compare__with_name(self):
        parameter = Parameter()
        parameter.name = "a"
        parameter.type = "string"
        parameter.optional = True
        parameter.position = 0

        parameter_sample1 = ParameterSample(parameter)
        parameter_sample2 = ParameterSample(parameter)

        parameter_sample1.name = "a"
        parameter_sample2.name = "b"

        self.assertTrue(parameter_sample1 < parameter_sample2)
Example #23
0
    def test_parameter_get_default_sample(self):
        test = Parameter()
        test.type = "number"

        self.assertEqual("13.37", test.get_default_sample())