diff test/rest_common.py @ 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 171ff2e487df
children 2967f37e73e4
line wrap: on
line diff
--- 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

Roundup Issue Tracker: http://roundup-tracker.org/