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])
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)
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.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)
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)
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)
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_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_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())
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_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_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)
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_get_default_sample(self): test = Parameter() test.type = "number" self.assertEqual("13.37", test.get_default_sample())