def test_exception_to_dict_with_global_traceback(): activate_traceback() try: raise Problem() except Problem as e: exception_as_dict = e.to_dict() assert "Traceback (most recent call last):" in exception_as_dict[ 'traceback'] del exception_as_dict['traceback'] assert exception_as_dict == {}
def test_exception_to_http_response_with_traceback_param(): deactivate_traceback() try: raise Problem() except Problem as e: response = e.to_http_response(with_traceback=True) body = json.loads(response['body']) assert "Traceback (most recent call last):" in body['traceback'] del body['traceback'] assert body == {}
def test_exception_to_dict(): deactivate_traceback() try: raise Problem(1000, 'test_title', 'test_detail', 'test_type', 'test_instance', custom='test_custom') except Problem as e: exception_as_dict = e.to_dict() assert exception_as_dict == { 'status': 1000, 'title': 'test_title', 'detail': 'test_detail', 'type': 'test_type', 'instance': 'test_instance', 'custom': 'test_custom' }
def test_exception_to_http_response(): deactivate_traceback() try: raise Problem(1000, 'test_title', 'test_detail', 'test_type', 'test_instance', custom='test_custom') except Problem as e: response = e.to_http_response() assert response['statusCode'] == 1000 assert response['headers'] == { 'Content-Type': 'application/problem+json' } assert json.loads(response['body']) == { 'status': 1000, 'title': 'test_title', 'detail': 'test_detail', 'type': 'test_type', 'instance': 'test_instance', 'custom': 'test_custom' }
def test_repr(): assert repr(Problem(400)) == "{'status': 400, 'title': 'Bad Request'}"