Mercurial > p > roundup > code
changeset 8094:8e310a7b5e09
issue2551131 - Return accept-patch if patch body not accepted (415 code)
Now returns:
Accept-Patch: application/json, application/x-www-form-urlencoded
for PATCH verb.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 16 Jul 2024 20:23:36 -0400 |
| parents | d913db0ab498 |
| children | 5aed4911836b |
| files | CHANGES.txt roundup/rest.py test/rest_common.py |
| diffstat | 3 files changed, 29 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGES.txt Tue Jul 16 11:12:24 2024 -0400 +++ b/CHANGES.txt Tue Jul 16 20:23:36 2024 -0400 @@ -16,12 +16,16 @@ 2025-XX-XX 2.5.0 Fixed: + - issue2551343 - Remove support for PySQLite. It is unmaintained and sqlite3 is used which is the default for a Python distribution. (John Rouillard) - replace use of os.listdir with os.scandir. Performance improvement. Using with Python 2 requires 'pip install scandir'. (John Rouillard) +- issue2551131 - Return accept-patch if patch body not accepted + (415 code). Accept-Patch returned with acceptable values. (John + Rouillard) Features:
--- a/roundup/rest.py Tue Jul 16 11:12:24 2024 -0400 +++ b/roundup/rest.py Tue Jul 16 20:23:36 2024 -0400 @@ -2412,6 +2412,10 @@ except ValueError as msg: output = self.error_obj(400, msg) else: + if method.upper() == "PATCH": + self.client.setHeader("Accept-Patch", + "application/json, " + "application/x-www-form-urlencoded") output = self.error_obj(415, "Unable to process input of type %s" % content_type_header)
--- a/test/rest_common.py Tue Jul 16 11:12:24 2024 -0400 +++ b/test/rest_common.py Tue Jul 16 20:23:36 2024 -0400 @@ -1807,6 +1807,24 @@ json_dict = json.loads(b2s(results)) self.assertEqual(json_dict['error']['msg'], "Unable to process input of type application/jzot") + self.assertNotIn("Accept-Patch", + self.server.client.additional_headers) + self.server.client.additional_headers = {} + + + # test with PATCH verb to verify Accept-Patch is correct + results = self.server.dispatch("PATCH", + "/rest/data/issue", + form) + self.assertEqual(self.server.client.response_code, 415) + json_dict = json.loads(b2s(results)) + self.assertEqual(json_dict['error']['msg'], + "Unable to process input of type application/jzot") + self.assertIn("Accept-Patch", + self.server.client.additional_headers) + self.assertEqual(self.server.client.additional_headers["Accept-Patch"], + "application/json, application/x-www-form-urlencoded" ) + self.server.client.additional_headers = {} # Test GET as well. I am not sure if this should pass or not. # Arguably GET doesn't use any form/json input but.... @@ -1815,8 +1833,9 @@ form) print(results) self.assertEqual(self.server.client.response_code, 415) - - + self.assertNotIn("Accept-Patch", + self.server.client.additional_headers) + self.server.client.additional_headers = {} def testDispatchBadAccept(self): # simulate: /rest/data/issue expect failure unknown accept settings
