Mercurial > p > roundup > code
annotate test/test_rest.py @ 5591:a25d79e874cb REST-rebased
Added filtering and pagination
Adjust unittest to use empty cgi formfield instead of empty dict
committer: Ralf Schlatterbeck <rsc@runtux.com>
| author | Chau Nguyen <dangchau1991@yahoo.com> |
|---|---|
| date | Wed, 30 Jan 2019 10:26:35 +0100 |
| parents | 6b3a9655a7d9 |
| children | adcb5cbe82bd |
| rev | line source |
|---|---|
|
5586
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
1 import unittest |
|
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
2 import os |
|
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
3 import shutil |
|
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
4 import errno |
| 5583 | 5 |
| 6 from roundup.cgi.exceptions import * | |
|
5586
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
7 from roundup import password, hyperdb |
| 5583 | 8 from roundup.rest import RestfulInstance |
| 9 from roundup.backends import list_backends | |
|
5586
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
10 from roundup.cgi import client |
| 5583 | 11 |
| 12 import db_test_base | |
| 13 | |
| 14 NEEDS_INSTANCE = 1 | |
| 15 | |
|
5586
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
16 |
| 5583 | 17 class TestCase(unittest.TestCase): |
| 18 | |
| 19 backend = None | |
| 20 | |
| 21 def setUp(self): | |
| 22 self.dirname = '_test_rest' | |
| 23 # set up and open a tracker | |
| 24 self.instance = db_test_base.setupTracker(self.dirname, self.backend) | |
| 25 | |
| 26 # open the database | |
| 27 self.db = self.instance.open('admin') | |
| 28 | |
| 29 # Get user id (user4 maybe). Used later to get data from db. | |
| 30 self.joeid = self.db.user.create( | |
| 31 username='joe', | |
| 32 password=password.Password('random'), | |
| 33 address='random@home.org', | |
| 34 realname='Joe Random', | |
| 35 roles='User' | |
| 36 ) | |
| 37 | |
| 38 self.db.commit() | |
| 39 self.db.close() | |
| 40 self.db = self.instance.open('joe') | |
| 41 | |
| 42 self.db.tx_Source = 'web' | |
| 43 | |
| 44 self.db.issue.addprop(tx_Source=hyperdb.String()) | |
| 45 self.db.msg.addprop(tx_Source=hyperdb.String()) | |
| 46 | |
| 47 self.db.post_init() | |
| 48 | |
| 49 thisdir = os.path.dirname(__file__) | |
| 50 vars = {} | |
| 51 execfile(os.path.join(thisdir, "tx_Source_detector.py"), vars) | |
| 52 vars['init'](self.db) | |
| 53 | |
| 54 env = { | |
| 55 'PATH_INFO': 'http://localhost/rounduptest/rest/', | |
| 56 'HTTP_HOST': 'localhost', | |
| 57 'TRACKER_NAME': 'rounduptest' | |
| 58 } | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
59 self.dummy_client = client.Client(self.instance, None, env, [], None) |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
60 self.empty_form = cgi.FieldStorage() |
| 5583 | 61 |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
62 self.server = RestfulInstance(self.dummy_client, self.db) |
| 5583 | 63 |
| 64 def tearDown(self): | |
| 65 self.db.close() | |
| 66 try: | |
| 67 shutil.rmtree(self.dirname) | |
| 68 except OSError, error: | |
| 69 if error.errno not in (errno.ENOENT, errno.ESRCH): | |
| 70 raise | |
| 71 | |
| 72 def testGet(self): | |
| 73 """ | |
| 74 Retrieve all three users | |
| 75 obtain data for 'joe' | |
| 76 """ | |
| 77 # Retrieve all three users. | |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
78 results = self.server.get_collection('user', self.empty_form) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
79 self.assertEqual(self.dummy_client.response_code, 200) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
80 self.assertEqual(len(results['data']), 3) |
| 5583 | 81 |
| 82 # Obtain data for 'joe'. | |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
83 results = self.server.get_element('user', self.joeid, self.empty_form) |
|
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
84 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
85 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 86 self.assertEqual(results['attributes']['username'], 'joe') |
| 87 self.assertEqual(results['attributes']['realname'], 'Joe Random') | |
| 88 | |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
89 # Obtain data for 'joe'. |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
90 results = self.server.get_attribute( |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
91 'user', self.joeid, 'username', self.empty_form |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
92 ) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
93 self.assertEqual(self.dummy_client.response_code, 200) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
94 self.assertEqual(results['data']['data'], 'joe') |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
95 |
| 5583 | 96 def testPut(self): |
| 97 """ | |
| 98 Change joe's 'realname' | |
| 99 Check if we can't change admin's detail | |
| 100 """ | |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
101 # change Joe's realname via attribute uri |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
102 form = cgi.FieldStorage() |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
103 form.list = [ |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
104 cgi.MiniFieldStorage('data', 'Joe Doe Doe') |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
105 ] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
106 results = self.server.put_attribute( |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
107 'user', self.joeid, 'realname', form |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
108 ) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
109 results = self.server.get_attribute( |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
110 'user', self.joeid, 'realname', self.empty_form |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
111 ) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
112 self.assertEqual(self.dummy_client.response_code, 200) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
113 self.assertEqual(results['data']['data'], 'Joe Doe Doe') |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
114 |
| 5583 | 115 # Reset joe's 'realname'. |
| 116 form = cgi.FieldStorage() | |
| 117 form.list = [ | |
| 118 cgi.MiniFieldStorage('realname', 'Joe Doe') | |
| 119 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
120 results = self.server.put_element('user', self.joeid, form) |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
121 results = self.server.get_element('user', self.joeid, self.empty_form) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
122 self.assertEqual(self.dummy_client.response_code, 200) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
123 self.assertEqual(results['data']['attributes']['realname'], 'Joe Doe') |
| 5583 | 124 |
| 125 # check we can't change admin's details | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
126 results = self.server.put_element('user', '1', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
127 self.assertEqual(self.dummy_client.response_code, 403) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
128 self.assertEqual(results['error']['status'], 403) |
| 5583 | 129 |
| 130 def testPost(self): | |
| 131 """ | |
| 132 Post a new issue with title: foo | |
| 133 Verify the information of the created issue | |
| 134 """ | |
| 135 form = cgi.FieldStorage() | |
| 136 form.list = [ | |
| 137 cgi.MiniFieldStorage('title', 'foo') | |
| 138 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
139 results = self.server.post_collection('issue', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
140 self.assertEqual(self.dummy_client.response_code, 201) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
141 issueid = results['data']['id'] |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
142 results = self.server.get_element('issue', issueid, self.empty_form) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
143 self.assertEqual(self.dummy_client.response_code, 200) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
144 self.assertEqual(results['data']['attributes']['title'], 'foo') |
| 5583 | 145 self.assertEqual(self.db.issue.get(issueid, "tx_Source"), 'web') |
| 146 | |
| 147 def testPostFile(self): | |
| 148 """ | |
| 149 Post a new file with content: hello\r\nthere | |
| 150 Verify the information of the created file | |
| 151 """ | |
| 152 form = cgi.FieldStorage() | |
| 153 form.list = [ | |
| 154 cgi.MiniFieldStorage('content', 'hello\r\nthere') | |
| 155 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
156 results = self.server.post_collection('file', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
157 self.assertEqual(self.dummy_client.response_code, 201) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
158 fileid = results['data']['id'] |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
159 results = self.server.get_element('file', fileid, self.empty_form) |
|
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
160 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
161 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 162 self.assertEqual(results['attributes']['content'], 'hello\r\nthere') |
| 163 | |
| 164 def testAuthDeniedPut(self): | |
| 165 """ | |
| 166 Test unauthorized PUT request | |
| 167 """ | |
| 168 # Wrong permissions (caught by roundup security module). | |
| 169 form = cgi.FieldStorage() | |
| 170 form.list = [ | |
| 171 cgi.MiniFieldStorage('realname', 'someone') | |
| 172 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
173 results = self.server.put_element('user', '1', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
174 self.assertEqual(self.dummy_client.response_code, 403) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
175 self.assertEqual(results['error']['status'], 403) |
| 5583 | 176 |
| 177 def testAuthDeniedPost(self): | |
| 178 """ | |
| 179 Test unauthorized POST request | |
| 180 """ | |
| 181 form = cgi.FieldStorage() | |
| 182 form.list = [ | |
| 183 cgi.MiniFieldStorage('username', 'blah') | |
| 184 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
185 results = self.server.post_collection('user', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
186 self.assertEqual(self.dummy_client.response_code, 403) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
187 self.assertEqual(results['error']['status'], 403) |
| 5583 | 188 |
| 189 def testAuthAllowedPut(self): | |
| 190 """ | |
| 191 Test authorized PUT request | |
| 192 """ | |
| 193 self.db.setCurrentUser('admin') | |
| 194 form = cgi.FieldStorage() | |
| 195 form.list = [ | |
| 196 cgi.MiniFieldStorage('realname', 'someone') | |
| 197 ] | |
| 198 try: | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
199 self.server.put_element('user', '2', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
200 except Unauthorised, err: |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
201 self.fail('raised %s' % err) |
| 5583 | 202 finally: |
| 203 self.db.setCurrentUser('joe') | |
| 204 | |
| 205 def testAuthAllowedPost(self): | |
| 206 """ | |
| 207 Test authorized POST request | |
| 208 """ | |
| 209 self.db.setCurrentUser('admin') | |
| 210 form = cgi.FieldStorage() | |
| 211 form.list = [ | |
| 212 cgi.MiniFieldStorage('username', 'blah') | |
| 213 ] | |
| 214 try: | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
215 self.server.post_collection('user', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
216 except Unauthorised, err: |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
217 self.fail('raised %s' % err) |
| 5583 | 218 finally: |
| 219 self.db.setCurrentUser('joe') | |
| 220 | |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
221 def testDeleteAttributeUri(self): |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
222 """ |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
223 Test Delete an attribute |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
224 """ |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
225 # create a new issue with userid 1 in the nosy list |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
226 issue_id = self.db.issue.create(title='foo', nosy=['1']) |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
227 |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
228 # remove the title and nosy |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
229 results = self.server.delete_attribute( |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
230 'issue', issue_id, 'title', self.empty_form |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
231 ) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
232 self.assertEqual(self.dummy_client.response_code, 200) |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
233 |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
234 results = self.server.delete_attribute( |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
235 'issue', issue_id, 'nosy', self.empty_form |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
236 ) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
237 self.assertEqual(self.dummy_client.response_code, 200) |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
238 |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
239 # verify the result |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
240 results = self.server.get_element('issue', issue_id, self.empty_form) |
|
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
241 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
242 self.assertEqual(self.dummy_client.response_code, 200) |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
243 self.assertEqual(len(results['attributes']['nosy']), 0) |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
244 self.assertListEqual(results['attributes']['nosy'], []) |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
245 self.assertEqual(results['attributes']['title'], None) |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
246 |
| 5583 | 247 def testPatchAdd(self): |
| 248 """ | |
| 249 Test Patch op 'Add' | |
| 250 """ | |
| 251 # create a new issue with userid 1 in the nosy list | |
| 252 issue_id = self.db.issue.create(title='foo', nosy=['1']) | |
| 253 | |
| 254 # add userid 2 to the nosy list | |
| 255 form = cgi.FieldStorage() | |
| 256 form.list = [ | |
| 257 cgi.MiniFieldStorage('op', 'add'), | |
| 258 cgi.MiniFieldStorage('nosy', '2') | |
| 259 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
260 results = self.server.patch_element('issue', issue_id, form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
261 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 262 |
| 263 # verify the result | |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
264 results = self.server.get_element('issue', issue_id, self.empty_form) |
|
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
265 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
266 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 267 self.assertEqual(len(results['attributes']['nosy']), 2) |
| 268 self.assertListEqual(results['attributes']['nosy'], ['1', '2']) | |
| 269 | |
| 270 def testPatchReplace(self): | |
| 271 """ | |
| 272 Test Patch op 'Replace' | |
| 273 """ | |
| 274 # create a new issue with userid 1 in the nosy list and status = 1 | |
| 275 issue_id = self.db.issue.create(title='foo', nosy=['1'], status='1') | |
| 276 | |
| 277 # replace userid 2 to the nosy list and status = 3 | |
| 278 form = cgi.FieldStorage() | |
| 279 form.list = [ | |
| 280 cgi.MiniFieldStorage('op', 'replace'), | |
| 281 cgi.MiniFieldStorage('nosy', '2'), | |
| 282 cgi.MiniFieldStorage('status', '3') | |
| 283 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
284 results = self.server.patch_element('issue', issue_id, form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
285 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 286 |
| 287 # verify the result | |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
288 results = self.server.get_element('issue', issue_id, self.empty_form) |
|
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
289 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
290 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 291 self.assertEqual(results['attributes']['status'], '3') |
| 292 self.assertEqual(len(results['attributes']['nosy']), 1) | |
| 293 self.assertListEqual(results['attributes']['nosy'], ['2']) | |
| 294 | |
| 295 def testPatchRemoveAll(self): | |
| 296 """ | |
| 297 Test Patch Action 'Remove' | |
| 298 """ | |
| 299 # create a new issue with userid 1 in the nosy list | |
| 300 issue_id = self.db.issue.create(title='foo', nosy=['1', '2']) | |
| 301 | |
| 302 # remove the nosy list and the title | |
| 303 form = cgi.FieldStorage() | |
| 304 form.list = [ | |
| 305 cgi.MiniFieldStorage('op', 'remove'), | |
| 306 cgi.MiniFieldStorage('nosy', ''), | |
| 307 cgi.MiniFieldStorage('title', '') | |
| 308 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
309 results = self.server.patch_element('issue', issue_id, form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
310 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 311 |
| 312 # verify the result | |
|
5591
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
313 results = self.server.get_element('issue', issue_id, self.empty_form) |
|
a25d79e874cb
Added filtering and pagination
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5588
diff
changeset
|
314 results = results['data'] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
315 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 316 self.assertEqual(results['attributes']['title'], None) |
| 317 self.assertEqual(len(results['attributes']['nosy']), 0) | |
| 318 self.assertEqual(results['attributes']['nosy'], []) | |
| 319 | |
|
5586
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
320 |
| 5583 | 321 def test_suite(): |
| 322 suite = unittest.TestSuite() | |
| 323 for l in list_backends(): | |
| 324 dct = dict(backend=l) | |
| 325 subcls = type(TestCase)('TestCase_%s' % l, (TestCase,), dct) | |
| 326 suite.addTest(unittest.makeSuite(subcls)) | |
| 327 return suite | |
| 328 | |
| 329 if __name__ == '__main__': | |
| 330 runner = unittest.TextTestRunner() | |
| 331 unittest.main(testRunner=runner) |
