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_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 create_from_name_and_dictionary(self, name, datas): """Return a populated object Method from dictionary datas """ method = ObjectMethod() self.set_common_datas(method, name, datas) if "category" in datas: method.category = str(datas["category"]) if "code" in datas: method.code = int(datas["code"]) if "uri" in datas: method.uri = str(datas["uri"]) if "method" in datas: method.method = self.get_enum("method", ObjectMethod.Methods, datas) method.request_headers = self.parameter_factory.create_dictionary_of_element_from_dictionary( "request_headers", datas) method.request_parameters = self.parameter_factory.create_dictionary_of_element_from_dictionary( "request_parameters", datas) method.response_codes = self.response_code_factory.create_list_of_element_from_dictionary( "response_codes", datas) if "request_body" in datas and datas["request_body"]: method.request_body = self.object_factory.create_from_name_and_dictionary( "request", datas["request_body"]) if "response_body" in datas and datas["response_body"]: method.response_body = self.object_factory.create_from_name_and_dictionary( "response", datas["response_body"]) return method
def create_from_name_and_dictionary(self, name, datas): """Return a populated object Method from dictionary datas """ method = ObjectMethod() self.set_common_datas(method, name, datas) if "category" in datas: method.category = str(datas["category"]) if "code" in datas: method.code = int(datas["code"]) if "uri" in datas: method.uri = str(datas["uri"]) if "method" in datas: method.method = self.get_enum("method", ObjectMethod.Methods, datas) method.request_headers = self.parameter_factory.create_dictionary_of_element_from_dictionary("request_headers", datas) method.request_parameters = self.parameter_factory.create_dictionary_of_element_from_dictionary("request_parameters", datas) method.response_codes = self.response_code_factory.create_list_of_element_from_dictionary("response_codes", datas) if "request_body" in datas and datas["request_body"]: method.request_body = self.object_factory.create_from_name_and_dictionary("request", datas["request_body"]) if "response_body" in datas and datas["response_body"]: method.response_body = self.object_factory.create_from_name_and_dictionary("response", datas["response_body"]) return method