def test_should_map_dict(self): method_name = "api_method_name" response = dict() response["error"] = {} response["error"]["code"] = 777 response["error"]["name"] = "error_name" response["error"]["message"] = "error_message" api_error = ApiServerError(method_name, json.dumps(response)) self.assertEqual(api_error.error_name, response["error"]["name"]) self.assertEqual(api_error.error_code, response["error"]["code"]) self.assertEqual(api_error.message, response["error"]["message"]) self.assertEqual(api_error.method_name, method_name)
def test_repr_evals(self): api_error = ApiServerError( 'aMethod', '{ \ "error" : { \ "name": "error_name", \ "code": 505, \ "message": "aMessage" \ } \ }', ) assert_that(eval(repr(api_error)), api_error)
def test_should_map_provided_json(self): api_error = ApiServerError( 'aMethod', '{ \ "error" : { \ "name": "error_name", \ "code": 505, \ "message": "aMessage" \ } \ }', ) self.assertEqual(api_error.error_name, 'error_name') self.assertEqual(api_error.error_code, 505) self.assertEqual(api_error.message, 'aMessage')
def test_should_map_provided_json(self): api_error = ApiServerError( 'aMethod', '{ \ "error" : { \ "name": "error_name", \ "code": 505, \ "message": "aMessage" \ } \ }', ) assert_that(api_error.error_name, equal_to('error_name')) assert_that(api_error.error_code, equal_to(505)) assert_that(api_error.message, equal_to('aMessage'))
def test_should_convert_code_to_int(self): api_error = ApiServerError('aMethod', '{"error": {"code": "404"}}') self.assertEqual(api_error.error_code, 404)
def test_should_handle_dict(self): api_error = ApiServerError('aMethod', {}) self.assertEqual(api_error.error_name, 'Unknown') self.assertEqual(api_error.error_code, 500) self.assertEqual(api_error.message, None)
def test_should_provide_defaults(self): api_error = ApiServerError('aMethod', '{}') self.assertEqual(api_error.error_name, 'Unknown') self.assertEqual(api_error.error_code, 500) self.assertEqual(api_error.message, None)
def test_repr_evals_no_json(self): api_error = ApiServerError('aMethod', json.loads('{}', )) assert_that(eval(repr(api_error)), api_error)
def test_should_convert_code_to_int(self): api_error = ApiServerError('aMethod', '{"code": "404"}') assert_that(api_error.error_code, equal_to(404) and not (equal_to("404")))
def test_should_provide_defaults(self): api_error = ApiServerError('aMethod', '{}') assert_that(api_error.error_name, equal_to('Unknown')) assert_that(api_error.error_code, equal_to(500)) assert_that(api_error.message, equal_to(None))