diff --git a/acceptance_tests/app/c2cwsgiutils_app/services.py b/acceptance_tests/app/c2cwsgiutils_app/services.py index baabf307e..5326de1f8 100644 --- a/acceptance_tests/app/c2cwsgiutils_app/services.py +++ b/acceptance_tests/app/c2cwsgiutils_app/services.py @@ -12,6 +12,7 @@ hello_service = services.create("hello", "/hello", cors_credentials=True) error_service = services.create("error", "/error") tracking_service = services.create("tracking", "/tracking/{depth:[01]}") +empty_service = services.create("empty", "/empty") leaked_objects = [] @@ -77,3 +78,9 @@ def tracking(request): if depth > 0: result['sub'] = requests.get('http://localhost/api/tracking/%d' % (depth - 1)).json() return result + + +@empty_service.put() +def empty(request): + request.response.status_code = 204 + return request.response diff --git a/acceptance_tests/tests/tests/test_connection.py b/acceptance_tests/tests/tests/test_connection.py new file mode 100644 index 000000000..6e3864ebe --- /dev/null +++ b/acceptance_tests/tests/tests/test_connection.py @@ -0,0 +1,2 @@ +def test_empty_response(app_connection): + assert app_connection.put_json("empty", expected_status=204) is None diff --git a/c2cwsgiutils/acceptance/connection.py b/c2cwsgiutils/acceptance/connection.py index f5a9902ab..bdf41afcd 100644 --- a/c2cwsgiutils/acceptance/connection.py +++ b/c2cwsgiutils/acceptance/connection.py @@ -13,7 +13,7 @@ def __init__(self, base_url: str, origin: str) -> None: self.origin = origin def get(self, url: str, expected_status: int=200, params: Mapping[str, str]=None, - headers: Mapping[str, str]=None, cors: bool=True, cache_allowed: bool=False) -> str: + headers: Mapping[str, str]=None, cors: bool=True, cache_allowed: bool=False) -> Optional[str]: """ get the given URL (relative to the root of API). """ @@ -21,7 +21,7 @@ def get(self, url: str, expected_status: int=200, params: Mapping[str, str]=None headers=self._merge_headers(headers, cors)) as r: check_response(r, expected_status, cache_allowed=cache_allowed) self._check_cors(cors, r) - return r.text + return None if r.status_code == 204 else r.text def get_raw(self, url: str, expected_status: int=200, params: Mapping[str, str]=None, headers: Mapping[str, str]=None, cors: bool=True, @@ -44,7 +44,7 @@ def get_json(self, url: str, expected_status: int=200, params: Mapping[str, str] headers=self._merge_headers(headers, cors)) as r: check_response(r, expected_status, cache_allowed=cache_allowed) self._check_cors(cors, r) - return r.json() + return None if r.status_code == 204 else r.json() def get_xml(self, url: str, schema: Optional[str]=None, expected_status: int=200, params: Mapping[str, str]=None, headers: Mapping[str, str]=None, cors: bool=True, @@ -74,7 +74,7 @@ def post_json(self, url: str, data: Any=None, json: Any=None, expected_status: i headers=self._merge_headers(headers, cors)) as r: check_response(r, expected_status, cache_allowed=cache_allowed) self._check_cors(cors, r) - return r.json() + return None if r.status_code == 204 else r.json() def post_files(self, url: str, data: Any=None, files: Optional[Mapping[str, Any]]=None, expected_status: int=200, params: Mapping[str, str]=None, headers: Mapping[str, str]=None, @@ -86,10 +86,10 @@ def post_files(self, url: str, data: Any=None, files: Optional[Mapping[str, Any] headers=self._merge_headers(headers, cors)) as r: check_response(r, expected_status, cache_allowed) self._check_cors(cors, r) - return r.json() + return None if r.status_code == 204 else r.json() def post(self, url: str, data: Any=None, expected_status: int=200, params: Mapping[str, str]=None, - headers: Mapping[str, str]=None, cors: bool=True, cache_allowed: bool=False) -> str: + headers: Mapping[str, str]=None, cors: bool=True, cache_allowed: bool=False) -> Optional[str]: """ POST the given URL (relative to the root of API). """ @@ -98,7 +98,7 @@ def post(self, url: str, data: Any=None, expected_status: int=200, params: Mappi data=data, params=params) as r: check_response(r, expected_status, cache_allowed) self._check_cors(cors, r) - return r.text + return None if r.status_code == 204 else r.text def put_json(self, url: str, json: Any=None, expected_status: int=200, params: Mapping[str, str]=None, headers: Mapping[str, str]=None, cors: bool=True, cache_allowed: bool=False) -> Any: @@ -109,7 +109,7 @@ def put_json(self, url: str, json: Any=None, expected_status: int=200, params: M headers=self._merge_headers(headers, cors)) as r: check_response(r, expected_status, cache_allowed) self._check_cors(cors, r) - return r.json() + return None if r.status_code == 204 else r.json() def delete(self, url: str, expected_status: int=204, params: Mapping[str, str]=None, headers: Mapping[str, str]=None, cors: bool=True, diff --git a/setup.py b/setup.py index a8d418e8b..0c1b32efe 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages -VERSION = '1.7.0' +VERSION = '1.7.1' HERE = os.path.abspath(os.path.dirname(__file__)) INSTALL_REQUIRES = [ pkg.split('==')[0]