Skip to content

Commit ddfa2e9

Browse files
committed
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.
1 parent d4a32b5 commit ddfa2e9

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ Roundup 2.4.0 is the last release to support Python 2.
1616
2025-XX-XX 2.5.0
1717

1818
Fixed:
19+
1920
- issue2551343 - Remove support for PySQLite. It is unmaintained
2021
and sqlite3 is used which is the default for a Python
2122
distribution. (John Rouillard)
2223
- replace use of os.listdir with os.scandir. Performance
2324
improvement. Using with Python 2 requires 'pip install
2425
scandir'. (John Rouillard)
26+
- issue2551131 - Return accept-patch if patch body not accepted
27+
(415 code). Accept-Patch returned with acceptable values. (John
28+
Rouillard)
2529

2630
Features:
2731

roundup/rest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,10 @@ def dispatch(self, method, uri, input):
24122412
except ValueError as msg:
24132413
output = self.error_obj(400, msg)
24142414
else:
2415+
if method.upper() == "PATCH":
2416+
self.client.setHeader("Accept-Patch",
2417+
"application/json, "
2418+
"application/x-www-form-urlencoded")
24152419
output = self.error_obj(415,
24162420
"Unable to process input of type %s" %
24172421
content_type_header)

test/rest_common.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,24 @@ def testDispatchBadContent(self):
18071807
json_dict = json.loads(b2s(results))
18081808
self.assertEqual(json_dict['error']['msg'],
18091809
"Unable to process input of type application/jzot")
1810+
self.assertNotIn("Accept-Patch",
1811+
self.server.client.additional_headers)
1812+
self.server.client.additional_headers = {}
1813+
1814+
1815+
# test with PATCH verb to verify Accept-Patch is correct
1816+
results = self.server.dispatch("PATCH",
1817+
"/rest/data/issue",
1818+
form)
1819+
self.assertEqual(self.server.client.response_code, 415)
1820+
json_dict = json.loads(b2s(results))
1821+
self.assertEqual(json_dict['error']['msg'],
1822+
"Unable to process input of type application/jzot")
1823+
self.assertIn("Accept-Patch",
1824+
self.server.client.additional_headers)
1825+
self.assertEqual(self.server.client.additional_headers["Accept-Patch"],
1826+
"application/json, application/x-www-form-urlencoded" )
1827+
self.server.client.additional_headers = {}
18101828

18111829
# Test GET as well. I am not sure if this should pass or not.
18121830
# Arguably GET doesn't use any form/json input but....
@@ -1815,8 +1833,9 @@ def testDispatchBadContent(self):
18151833
form)
18161834
print(results)
18171835
self.assertEqual(self.server.client.response_code, 415)
1818-
1819-
1836+
self.assertNotIn("Accept-Patch",
1837+
self.server.client.additional_headers)
1838+
self.server.client.additional_headers = {}
18201839

18211840
def testDispatchBadAccept(self):
18221841
# simulate: /rest/data/issue expect failure unknown accept settings

0 commit comments

Comments
 (0)