예제 #1
0
    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
예제 #2
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)
예제 #3
0
    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
예제 #4
0
    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
예제 #5
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)
예제 #6
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)