# HG changeset patch # User John Rouillard # Date 1721175816 14400 # Node ID 8e310a7b5e0997da864376193c3156f302fe53b0 # Parent d913db0ab498bc0929f1654b45d25862b548a6f8 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. diff -r d913db0ab498 -r 8e310a7b5e09 CHANGES.txt --- 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: diff -r d913db0ab498 -r 8e310a7b5e09 roundup/rest.py --- 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) diff -r d913db0ab498 -r 8e310a7b5e09 test/rest_common.py --- 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