def test_response_code_compare__with_code(self): response_code1 = ResponseCodeDto(ResponseCode()) response_code2 = ResponseCodeDto(ResponseCode()) response_code1.code = 1 response_code2.code = 2 self.assertEqual(response_code1, sorted([response_code2, response_code1])[0])
def test_method_message(self): method = Method() code = ResponseCode() code.code = 100 code.message = "foo" method.code = 100 method.response_codes = [code] self.assertEqual("foo", method.message)
def test_method_message__failled_when_no_code_found(self): method = Method() code = ResponseCode() code.code = 100 code.message = "foo" method.code = 300 method.response_codes = [code] with self.assertRaises(ValueError): method.message
def test_response_code_compare__with_description(self): response_code1 = ResponseCodeDto(ResponseCode()) response_code2 = ResponseCodeDto(ResponseCode()) response_code1.code = 1 response_code1.message = "a" response_code1.description = "a" response_code2.code = 1 response_code2.message = "a" response_code2.description = "b" self.assertEqual(response_code1, sorted([response_code2, response_code1])[0])
def test_response_code(self): parameter = ResponseCode() parameter.name = "a" parameter.description = "b" parameter.code = 300 parameter.message = "c" parameter_dto = ResponseCodeDto(parameter) self.assertEqual("a", parameter_dto.name) self.assertEqual("b", parameter_dto.description) self.assertEqual(300, parameter_dto.code) self.assertEqual("c", parameter_dto.message)
def create_from_dictionary(self, datas): """Return a populated object ResponseCode from dictionary datas """ if "code" not in datas: raise ValueError("A response code must contain a code in \"%s\"." % repr(datas)) code = ObjectResponseCode() self.set_common_datas(code, str(datas["code"]), datas) code.code = int(datas["code"]) if "message" in datas: code.message = str(datas["message"]) elif code.code in self.default_messages.keys(): code.message = self.default_messages[code.code] if "generic" in datas: code.generic = to_boolean(datas["generic"]) return code
def create_from_dictionary(self, datas): """Return a populated object ResponseCode from dictionary datas """ if "code" not in datas: raise ValueError("A response code must contain a code in \"%s\"." % repr(datas)) code = ObjectResponseCode() self.set_common_datas(code, str(datas["code"]), datas) code.code = int(datas["code"]) if "message" in datas: code.message = str(datas["message"]) elif code.code in self.default_messages.keys(): code.message = self.default_messages[code.code] if "generic" in datas: code.generic = to_bool(datas["generic"]) return code