def test_define_changes_status__updated(self): root_dto = RootDto() version1 = Version() version1.name = "v1" version1.major = 1 version1 = VersionDto(version1) version2 = Version() version2.name = "v2" version2.major = 2 version2 = VersionDto(version2) category1 = MethodCategory(Category("c1")) method1 = Method() method1.changes_status = { "v1": MultiVersion.Changes.new, "v2": MultiVersion.Changes.updated } category1.methods = [method1] root_dto.versions = [version1, version2] root_dto.method_categories = [category1] self.factory.define_changes_status(root_dto) self.assertEqual(MultiVersion.Changes.new, method1.changes_status["v1"]) self.assertEqual(MultiVersion.Changes.updated, method1.changes_status["v2"])
def test_root(self): root_dto = RootDto() self.assertEqual(None, root_dto.configuration) self.assertEqual([], root_dto.versions) self.assertEqual([], root_dto.method_categories) self.assertEqual([], root_dto.type_categories)
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"])
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)
def test_hydrate_method_changed(self): root = Root() version1 = Version() version1.name = "v1" version2 = Version() version2.name = "v2" method1 = Method() method1.name = "m1" method1.description = "b" method2 = Method() method2.name = "m1" method2.description = "c" root.versions = {"v1": version1, "v2": version2} version1.methods = {"m1": method1} version2.methods = {"m1": method2} root_dto = RootDto() Hydrator(version1, root.versions, []).hydrate_method(root_dto, root, method1) Hydrator(version2, root.versions, []).hydrate_method(root_dto, root, method2) self.assertEqual(1, len(root_dto.method_categories)) self.assertEqual(1, len(root_dto.method_categories[0].methods)) self.assertEqual( 2, len(root_dto.method_categories[0].methods[0].description)) self.assertEqual( MultiVersion.Changes.updated, root_dto.method_categories[0].methods[0].changes_status["v2"])
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)
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))
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))
def test_define_changes_status(self): root_dto = RootDto() version1 = Version() version1.name = "v1" version1.major = 1 version1 = VersionDto(version1) version2 = Version() version2.name = "v2" version2.major = 2 version2 = VersionDto(version2) category1 = MethodCategory(Category("c1")) category2 = TypeCategory(Category("c2")) method1 = Method() method1.changes_status = {"v1": MultiVersion.Changes.none} method2 = Method() method2.changes_status = {"v1": MultiVersion.Changes.new} method3 = Method() method3.changes_status = {"v2": MultiVersion.Changes.new} category1.methods = [method1, method2, method3] root_dto.versions = [version1, version2] root_dto.method_categories = [category1] root_dto.type_categories = [category2] self.factory.define_changes_status(root_dto) self.assertEqual(MultiVersion.Changes.new, method1.changes_status["v1"]) self.assertEqual(MultiVersion.Changes.deleted, method2.changes_status["v2"]) self.assertEqual(MultiVersion.Changes.none, method3.changes_status["v1"])
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))
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)
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)
def test_validate(self): self.source.validate(RootDto())