예제 #1
0
    def test_hydrate_type_changed(self):

        root = Root()
        version1 = Version()
        version1.name = "v1"
        version2 = Version()
        version2.name = "v2"
        type1 = Type()
        type1.name = "m1"
        type1.description = "b"
        type1.item = ObjectString()
        type2 = Type()
        type2.name = "m1"
        type2.description = "c"
        type2.item = ObjectString()

        root.versions = {"v1": version1, "v2": version2}
        version1.types = {"m1": type1}
        version2.types = {"m1": type2}

        root_dto = RootDto()

        Hydrator(version1, root.versions,
                 []).hydrate_type(root_dto, root, type1)
        Hydrator(version2, root.versions,
                 []).hydrate_type(root_dto, root, type2)

        self.assertEqual(1, len(root_dto.type_categories))
        self.assertEqual(1, len(root_dto.type_categories[0].types))
        self.assertEqual(2,
                         len(root_dto.type_categories[0].types[0].description))
        self.assertEqual(
            MultiVersion.Changes.updated,
            root_dto.type_categories[0].types[0].changes_status["v2"])
예제 #2
0
    def test_hydrate_type_changed(self):

        root = Root()
        version1 = Version()
        version1.name = "v1"
        version2 = Version()
        version2.name = "v2"
        type1 = Type()
        type1.name = "m1"
        type1.description = "b"
        type1.item = ObjectString()
        type2 = Type()
        type2.name = "m1"
        type2.description = "c"
        type2.item = ObjectString()

        root.versions = {"v1": version1, "v2": version2}
        version1.types = {"m1": type1}
        version2.types = {"m1": type2}

        root_dto = RootDto()

        Hydrator(version1, root.versions, []).hydrate_type(root_dto, root, type1)
        Hydrator(version2, root.versions, []).hydrate_type(root_dto, root, type2)

        self.assertEqual(1, len(root_dto.type_categories))
        self.assertEqual(1, len(root_dto.type_categories[0].types))
        self.assertEqual(2, len(root_dto.type_categories[0].types[0].description))
        self.assertEqual(MultiVersion.Changes.updated, root_dto.type_categories[0].types[0].changes_status["v2"])
예제 #3
0
    def test_create_from_root(self):
        root = Root()
        version = Version()
        version.name = "v"
        method = Method()
        method.category = "a"
        type = Type()
        type.category = "b"
        type.item = ObjectString()

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

        response = self.factory.create_from_root(root)

        self.assertIsInstance(response, RootDto)

        self.assertEqual(1, len(response.method_categories))
        self.assertEqual("a", response.method_categories[0].name)
        self.assertEqual(1, len(response.method_categories[0].methods))

        self.assertEqual(1, len(response.type_categories))
        self.assertEqual("b", response.type_categories[0].name)
        self.assertEqual(1, len(response.type_categories[0].types))
예제 #4
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)
예제 #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)
예제 #6
0
    def test_hydrate_type__with_known_category(self):

        root = Root()
        version = Version()
        version.name = "v"
        type = Type()
        type.category = "c"
        type.item = ObjectString()

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

        category = Category("c")
        category.description = "d"

        root.categories = {"c": category}

        root_dto = RootDto()

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

        hydrator.hydrate_type(root_dto, root, type)

        self.assertEqual("d", root_dto.type_categories[0].description)
예제 #7
0
    def test_create_from_root(self):
        root = Root()
        version = Version()
        version.name = "v"
        method = Method()
        method.category = "a"
        type = Type()
        type.category = "b"
        type.item = ObjectString()

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

        response = self.factory.create_from_root(root)

        self.assertIsInstance(response, RootDto)

        self.assertEqual(1, len(response.method_categories))
        self.assertEqual("a", response.method_categories[0].name)
        self.assertEqual(1, len(response.method_categories[0].methods))

        self.assertEqual(1, len(response.type_categories))
        self.assertEqual("b", response.type_categories[0].name)
        self.assertEqual(1, len(response.type_categories[0].types))
예제 #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)
예제 #9
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)
예제 #10
0
    def test_replace_references(self):
        root = Root()

        version1 = Version()

        method1 = Method()
        type1 = Type()

        object_reference1 = ObjectReference()
        object_reference1.reference_name = "r1"
        object_reference1.name = "a"

        object_reference2 = ObjectReference()
        object_reference2.reference_name = "r1"
        object_reference2.name = "a"

        object1 = ObjectObject()
        object1.description = "b"

        method1.request_body = object_reference1
        type1.item = object_reference2

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

        root.versions = {"v1": version1}

        self.source.replace_references(root)

        self.assertEqual("a", method1.request_body.name)
        self.assertEqual("b", method1.request_body.description)
        self.assertEqual("a", type1.item.name)
        self.assertEqual("b", type1.item.description)
예제 #11
0
    def test_hydrate_type__with_known_category(self):

        root = Root()
        version = Version()
        version.name = "v"
        type = Type()
        type.category = "c"
        type.item = ObjectString()

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

        category = Category("c")
        category.description = "d"

        root.categories = {"c": category}

        root_dto = RootDto()

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

        hydrator.hydrate_type(root_dto, root, type)

        self.assertEqual("d", root_dto.type_categories[0].description)
예제 #12
0
    def test_hydrate_type__with_multiple_methds(self):

        root = Root()
        version = Version()
        version.name = "v"
        type1 = Type()
        type1.category = "c"
        type1.item = ObjectString()
        type2 = Type()
        type2.category = "c"
        type2.item = ObjectString()

        root.versions = {"v": version}
        version.types = {"m1": type1, "m2": type2}
        version.types = {"m": type}

        root_dto = RootDto()

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

        hydrator.hydrate_type(root_dto, root, type1)
        hydrator.hydrate_type(root_dto, root, type2)

        self.assertEqual(1, len(root_dto.type_categories))
예제 #13
0
    def test_hydrate_type__with_multiple_methds(self):

        root = Root()
        version = Version()
        version.name = "v"
        type1 = Type()
        type1.category = "c"
        type1.item = ObjectString()
        type2 = Type()
        type2.category = "c"
        type2.item = ObjectString()

        root.versions = {"v": version}
        version.types = {"m1": type1, "m2": type2}
        version.types = {"m": type}

        root_dto = RootDto()

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

        hydrator.hydrate_type(root_dto, root, type1)
        hydrator.hydrate_type(root_dto, root, type2)

        self.assertEqual(1, len(root_dto.type_categories))
예제 #14
0
    def create_from_name_and_dictionary(self, name, datas):
        """Return a populated object Version from dictionary datas
        """
        version = ObjectVersion()
        self.set_common_datas(version, name, datas)

        if "uri" in datas:
            version.uri = str(datas["uri"])
        if "major" in datas:
            version.major = int(datas["major"])
        if "minor" in datas:
            version.minor = int(datas["minor"])
        if "status" in datas:
            version.status = self.get_enum("status", ObjectVersion.Status, datas)

        version.methods = self.method_factory.create_dictionary_of_element_from_dictionary("methods", datas)
        version.types = self.type_factory.create_dictionary_of_element_from_dictionary("types", datas)
        version.references = self.reference_factory.create_dictionary_of_element_from_dictionary("references", datas)

        return version
예제 #15
0
    def test_hydrate_type(self):

        root = Root()
        version = Version()
        version.name = "v"
        type = Type()
        type.category = "a"
        type.item = ObjectString()

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

        root_dto = RootDto()

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

        hydrator.hydrate_type(root_dto, root, type)

        self.assertEqual(0, len(root_dto.method_categories))
        self.assertEqual(1, len(root_dto.type_categories))
        self.assertEqual(1, len(root_dto.type_categories[0].types))
예제 #16
0
    def test_hydrate_type(self):

        root = Root()
        version = Version()
        version.name = "v"
        type = Type()
        type.category = "a"
        type.item = ObjectString()

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

        root_dto = RootDto()

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

        hydrator.hydrate_type(root_dto, root, type)

        self.assertEqual(0, len(root_dto.method_categories))
        self.assertEqual(1, len(root_dto.type_categories))
        self.assertEqual(1, len(root_dto.type_categories[0].types))
예제 #17
0
    def test_hydrate_method__with_multiple_methds(self):

        root = Root()
        version = Version()
        version.name = "v"
        method1 = Method()
        method1.category = "c"
        method2 = Method()
        method2.category = "c"

        root.versions = {"v": version}
        version.methods = {"m1": method1, "m2": method2}
        version.types = {"m": type}

        root_dto = RootDto()

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

        hydrator.hydrate_method(root_dto, root, method1)
        hydrator.hydrate_method(root_dto, root, method2)

        self.assertEqual(1, len(root_dto.method_categories))
예제 #18
0
    def test_hydrate_method__with_multiple_methds(self):

        root = Root()
        version = Version()
        version.name = "v"
        method1 = Method()
        method1.category = "c"
        method2 = Method()
        method2.category = "c"

        root.versions = {"v": version}
        version.methods = {"m1": method1, "m2": method2}
        version.types = {"m": type}

        root_dto = RootDto()

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

        hydrator.hydrate_method(root_dto, root, method1)
        hydrator.hydrate_method(root_dto, root, method2)

        self.assertEqual(1, len(root_dto.method_categories))
예제 #19
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)
예제 #20
0
    def test_hydrate_method__with_known_category(self):

        root = Root()
        version = Version()
        version.name = "v"
        method = Method()
        method.category = "c"

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

        category = Category("c")
        category.description = "d"

        root.categories = {"c": category}

        root_dto = RootDto()

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

        hydrator.hydrate_method(root_dto, root, method)

        self.assertEqual("d", root_dto.method_categories[0].description)
예제 #21
0
파일: version.py 프로젝트: lampard1010/mock
    def create_from_name_and_dictionary(self, name, datas):
        """Return a populated object Version from dictionary datas
        """
        version = ObjectVersion()
        self.set_common_datas(version, name, datas)

        if "uri" in datas:
            version.uri = str(datas["uri"])
        if "major" in datas:
            version.major = int(datas["major"])
        if "minor" in datas:
            version.minor = int(datas["minor"])
        if "status" in datas:
            version.status = self.get_enum("status", ObjectVersion.Status,
                                           datas)

        version.methods = self.method_factory.create_dictionary_of_element_from_dictionary(
            "methods", datas)
        version.types = self.type_factory.create_dictionary_of_element_from_dictionary(
            "types", datas)
        version.references = self.reference_factory.create_dictionary_of_element_from_dictionary(
            "references", datas)

        return version
예제 #22
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)
예제 #23
0
    def test_hydrate_method__with_known_category(self):

        root = Root()
        version = Version()
        version.name = "v"
        method = Method()
        method.category = "c"

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

        category = Category("c")
        category.description = "d"

        root.categories = {"c": category}

        root_dto = RootDto()

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

        hydrator.hydrate_method(root_dto, root, method)

        self.assertEqual("d", root_dto.method_categories[0].description)