Mercurial > p > roundup > code
comparison test/test_rest.py @ 5595:65caddd54da2 REST-rebased
Handle operation for patch separately
Patch remove operation is now able to remove element from list and dict,
Added more test on new changes
committer: Ralf Schlatterbeck <rsc@runtux.com>
| author | Chau Nguyen <dangchau1991@yahoo.com> |
|---|---|
| date | Wed, 30 Jan 2019 10:26:35 +0100 |
| parents | adcb5cbe82bd |
| children | a76d88673375 |
comparison
equal
deleted
inserted
replaced
| 5594:864cf6cb5790 | 5595:65caddd54da2 |
|---|---|
| 438 | 438 |
| 439 def testPatchRemoveAll(self): | 439 def testPatchRemoveAll(self): |
| 440 """ | 440 """ |
| 441 Test Patch Action 'Remove' | 441 Test Patch Action 'Remove' |
| 442 """ | 442 """ |
| 443 # create a new issue with userid 1 in the nosy list | 443 # create a new issue with userid 1 and 2 in the nosy list |
| 444 issue_id = self.db.issue.create(title='foo', nosy=['1', '2']) | 444 issue_id = self.db.issue.create(title='foo', nosy=['1', '2']) |
| 445 | 445 |
| 446 # remove the nosy list and the title | 446 # remove the nosy list and the title |
| 447 form = cgi.FieldStorage() | 447 form = cgi.FieldStorage() |
| 448 form.list = [ | 448 form.list = [ |
| 458 results = results['data'] | 458 results = results['data'] |
| 459 self.assertEqual(self.dummy_client.response_code, 200) | 459 self.assertEqual(self.dummy_client.response_code, 200) |
| 460 self.assertEqual(results['attributes']['title'], None) | 460 self.assertEqual(results['attributes']['title'], None) |
| 461 self.assertEqual(len(results['attributes']['nosy']), 0) | 461 self.assertEqual(len(results['attributes']['nosy']), 0) |
| 462 self.assertEqual(results['attributes']['nosy'], []) | 462 self.assertEqual(results['attributes']['nosy'], []) |
| 463 | |
| 464 def testPatchRemove(self): | |
| 465 """ | |
| 466 Test Patch Action 'Remove' only some element from a list | |
| 467 """ | |
| 468 # create a new issue with userid 1, 2, 3 in the nosy list | |
| 469 issue_id = self.db.issue.create(title='foo', nosy=['1', '2', '3']) | |
| 470 | |
| 471 # remove the nosy list and the title | |
| 472 form = cgi.FieldStorage() | |
| 473 form.list = [ | |
| 474 cgi.MiniFieldStorage('op', 'remove'), | |
| 475 cgi.MiniFieldStorage('nosy', '1, 2'), | |
| 476 ] | |
| 477 results = self.server.patch_element('issue', issue_id, form) | |
| 478 self.assertEqual(self.dummy_client.response_code, 200) | |
| 479 | |
| 480 # verify the result | |
| 481 results = self.server.get_element('issue', issue_id, self.empty_form) | |
| 482 results = results['data'] | |
| 483 self.assertEqual(self.dummy_client.response_code, 200) | |
| 484 self.assertEqual(len(results['attributes']['nosy']), 1) | |
| 485 self.assertEqual(results['attributes']['nosy'], ['3']) | |
| 463 | 486 |
| 464 | 487 |
| 465 def get_obj(path, id): | 488 def get_obj(path, id): |
| 466 return { | 489 return { |
| 467 'id': id, | 490 'id': id, |
