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_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_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_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)
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)
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)
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)
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)
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)
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)