Mercurial > p > roundup > code
comparison test/rest_common.py @ 6317:ea0becc9fdb9
Test delete of class and use of @protected.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 01 Jan 2021 23:37:38 -0500 |
| parents | 323661f7c89c |
| children | ec853cef2f09 |
comparison
equal
deleted
inserted
replaced
| 6316:323661f7c89c | 6317:ea0becc9fdb9 |
|---|---|
| 1329 self.assertEqual(len(json_dict['data']['attributes']['nosy']), 3) | 1329 self.assertEqual(len(json_dict['data']['attributes']['nosy']), 3) |
| 1330 self.assertEqual(json_dict['data']['attributes']\ | 1330 self.assertEqual(json_dict['data']['attributes']\ |
| 1331 ['assignedto']['link'], | 1331 ['assignedto']['link'], |
| 1332 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/2") | 1332 "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/user/2") |
| 1333 | 1333 |
| 1334 | |
| 1335 def testDispatchDelete(self): | |
| 1336 """ | |
| 1337 run Delete through rest dispatch(). | |
| 1338 """ | |
| 1339 | |
| 1340 # TEST #0 | |
| 1341 # Delete class raises unauthorized error | |
| 1342 # simulate: /rest/data/issue | |
| 1343 env = { "REQUEST_METHOD": "DELETE" | |
| 1344 } | |
| 1345 headers={"accept": "application/json; version=1", | |
| 1346 } | |
| 1347 self.headers=headers | |
| 1348 self.server.client.request.headers.get=self.get_header | |
| 1349 results = self.server.dispatch(env["REQUEST_METHOD"], | |
| 1350 "/rest/data/issue", | |
| 1351 self.empty_form) | |
| 1352 | |
| 1353 print(results) | |
| 1354 self.assertEqual(self.server.client.response_code, 403) | |
| 1355 json_dict = json.loads(b2s(results)) | |
| 1356 | |
| 1357 self.assertEqual(json_dict['error']['msg'], | |
| 1358 "Deletion of a whole class disabled") | |
| 1359 | |
| 1360 | |
| 1334 def testDispatchBadContent(self): | 1361 def testDispatchBadContent(self): |
| 1335 """ | 1362 """ |
| 1336 runthrough rest dispatch() with bad content_type patterns. | 1363 runthrough rest dispatch() with bad content_type patterns. |
| 1337 """ | 1364 """ |
| 1338 | 1365 |
| 2741 {'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/file1/'}) | 2768 {'link': 'http://tracker.example/cgi-bin/roundup.cgi/bugs/file1/'}) |
| 2742 | 2769 |
| 2743 # File content is only shown with verbose=3 | 2770 # File content is only shown with verbose=3 |
| 2744 form = cgi.FieldStorage() | 2771 form = cgi.FieldStorage() |
| 2745 form.list = [ | 2772 form.list = [ |
| 2746 cgi.MiniFieldStorage('@verbose', '3') | 2773 cgi.MiniFieldStorage('@verbose', '3'), |
| 2774 cgi.MiniFieldStorage('@protected', 'true') | |
| 2747 ] | 2775 ] |
| 2748 results = self.server.get_element('file', fileid, form) | 2776 results = self.server.get_element('file', fileid, form) |
| 2749 results = results['data'] | 2777 results = results['data'] |
| 2750 self.assertEqual(self.dummy_client.response_code, 200) | 2778 self.assertEqual(self.dummy_client.response_code, 200) |
| 2751 self.assertEqual(results['attributes']['content'], 'hello\r\nthere') | 2779 self.assertEqual(results['attributes']['content'], 'hello\r\nthere') |
| 2780 self.assertIn('creator', results['attributes']) # added by @protected | |
| 2781 self.assertEqual(results['attributes']['creator']['username'], "joe") | |
| 2752 | 2782 |
| 2753 def testAuthDeniedPut(self): | 2783 def testAuthDeniedPut(self): |
| 2754 """ | 2784 """ |
| 2755 Test unauthorized PUT request | 2785 Test unauthorized PUT request |
| 2756 """ | 2786 """ |
