Mercurial > p > roundup > code
annotate test/test_rest.py @ 5589:5a2de4c19109 REST-rebased
Fix an indentation bug
committer: Ralf Schlatterbeck <rsc@runtux.com>
| author | Chau Nguyen <dangchau1991@yahoo.com> |
|---|---|
| date | Wed, 30 Jan 2019 10:26:35 +0100 |
| parents | 6b3a9655a7d9 |
| children | a25d79e874cb |
| 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) |
| 5583 | 60 |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
61 self.server = RestfulInstance(self.dummy_client, self.db) |
| 5583 | 62 |
| 63 def tearDown(self): | |
| 64 self.db.close() | |
| 65 try: | |
| 66 shutil.rmtree(self.dirname) | |
| 67 except OSError, error: | |
| 68 if error.errno not in (errno.ENOENT, errno.ESRCH): | |
| 69 raise | |
| 70 | |
| 71 def testGet(self): | |
| 72 """ | |
| 73 Retrieve all three users | |
| 74 obtain data for 'joe' | |
| 75 """ | |
| 76 # Retrieve all three users. | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
77 results = self.server.get_collection('user', {}) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
78 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
|
79 self.assertEqual(len(results['data']), 3) |
| 5583 | 80 |
| 81 # Obtain data for 'joe'. | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
82 results = self.server.get_element('user', self.joeid, {})['data'] |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
83 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 84 self.assertEqual(results['attributes']['username'], 'joe') |
| 85 self.assertEqual(results['attributes']['realname'], 'Joe Random') | |
| 86 | |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
87 # Obtain data for 'joe'. |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
88 results = self.server.get_attribute( |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
89 'user', self.joeid, 'username', {} |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
90 ) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
91 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
|
92 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
|
93 |
| 5583 | 94 def testPut(self): |
| 95 """ | |
| 96 Change joe's 'realname' | |
| 97 Check if we can't change admin's detail | |
| 98 """ | |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
99 # 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
|
100 form = cgi.FieldStorage() |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
101 form.list = [ |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
102 cgi.MiniFieldStorage('data', 'Joe Doe Doe') |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
103 ] |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
104 results = self.server.put_attribute( |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
105 'user', self.joeid, 'realname', form |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
106 ) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
107 results = self.server.get_attribute( |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
108 'user', self.joeid, 'realname', {} |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
109 ) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
110 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
|
111 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
|
112 |
| 5583 | 113 # Reset joe's 'realname'. |
| 114 form = cgi.FieldStorage() | |
| 115 form.list = [ | |
| 116 cgi.MiniFieldStorage('realname', 'Joe Doe') | |
| 117 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
118 results = self.server.put_element('user', self.joeid, form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
119 results = self.server.get_element('user', self.joeid, {}) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
120 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
|
121 self.assertEqual(results['data']['attributes']['realname'], 'Joe Doe') |
| 5583 | 122 |
| 123 # 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
|
124 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
|
125 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
|
126 self.assertEqual(results['error']['status'], 403) |
| 5583 | 127 |
| 128 def testPost(self): | |
| 129 """ | |
| 130 Post a new issue with title: foo | |
| 131 Verify the information of the created issue | |
| 132 """ | |
| 133 form = cgi.FieldStorage() | |
| 134 form.list = [ | |
| 135 cgi.MiniFieldStorage('title', 'foo') | |
| 136 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
137 results = self.server.post_collection('issue', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
138 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
|
139 issueid = results['data']['id'] |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
140 results = self.server.get_element('issue', issueid, {}) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
141 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
|
142 self.assertEqual(results['data']['attributes']['title'], 'foo') |
| 5583 | 143 self.assertEqual(self.db.issue.get(issueid, "tx_Source"), 'web') |
| 144 | |
| 145 def testPostFile(self): | |
| 146 """ | |
| 147 Post a new file with content: hello\r\nthere | |
| 148 Verify the information of the created file | |
| 149 """ | |
| 150 form = cgi.FieldStorage() | |
| 151 form.list = [ | |
| 152 cgi.MiniFieldStorage('content', 'hello\r\nthere') | |
| 153 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
154 results = self.server.post_collection('file', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
155 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
|
156 fileid = results['data']['id'] |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
157 results = self.server.get_element('file', fileid, {})['data'] |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
158 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 159 self.assertEqual(results['attributes']['content'], 'hello\r\nthere') |
| 160 | |
| 161 def testAuthDeniedPut(self): | |
| 162 """ | |
| 163 Test unauthorized PUT request | |
| 164 """ | |
| 165 # Wrong permissions (caught by roundup security module). | |
| 166 form = cgi.FieldStorage() | |
| 167 form.list = [ | |
| 168 cgi.MiniFieldStorage('realname', 'someone') | |
| 169 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
170 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
|
171 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
|
172 self.assertEqual(results['error']['status'], 403) |
| 5583 | 173 |
| 174 def testAuthDeniedPost(self): | |
| 175 """ | |
| 176 Test unauthorized POST request | |
| 177 """ | |
| 178 form = cgi.FieldStorage() | |
| 179 form.list = [ | |
| 180 cgi.MiniFieldStorage('username', 'blah') | |
| 181 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
182 results = self.server.post_collection('user', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
183 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
|
184 self.assertEqual(results['error']['status'], 403) |
| 5583 | 185 |
| 186 def testAuthAllowedPut(self): | |
| 187 """ | |
| 188 Test authorized PUT request | |
| 189 """ | |
| 190 self.db.setCurrentUser('admin') | |
| 191 form = cgi.FieldStorage() | |
| 192 form.list = [ | |
| 193 cgi.MiniFieldStorage('realname', 'someone') | |
| 194 ] | |
| 195 try: | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
196 self.server.put_element('user', '2', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
197 except Unauthorised, err: |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
198 self.fail('raised %s' % err) |
| 5583 | 199 finally: |
| 200 self.db.setCurrentUser('joe') | |
| 201 | |
| 202 def testAuthAllowedPost(self): | |
| 203 """ | |
| 204 Test authorized POST request | |
| 205 """ | |
| 206 self.db.setCurrentUser('admin') | |
| 207 form = cgi.FieldStorage() | |
| 208 form.list = [ | |
| 209 cgi.MiniFieldStorage('username', 'blah') | |
| 210 ] | |
| 211 try: | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
212 self.server.post_collection('user', form) |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
213 except Unauthorised, err: |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
214 self.fail('raised %s' % err) |
| 5583 | 215 finally: |
| 216 self.db.setCurrentUser('joe') | |
| 217 | |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
218 def testDeleteAttributeUri(self): |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
219 """ |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
220 Test Delete an attribute |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
221 """ |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
222 # 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
|
223 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
|
224 |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
225 # remove the title and nosy |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
226 results = self.server.delete_attribute( |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
227 'issue', issue_id, 'title', {} |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
228 ) |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
229 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
|
230 |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
231 results = self.server.delete_attribute( |
|
5585
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
232 'issue', issue_id, 'nosy', {} |
|
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 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
|
235 |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
236 # verify the result |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
237 results = self.server.get_element('issue', issue_id, {})['data'] |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
238 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
|
239 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
|
240 self.assertListEqual(results['attributes']['nosy'], []) |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
241 self.assertEqual(results['attributes']['title'], None) |
|
8725c09802b8
Added test cases for the element URI methods
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5583
diff
changeset
|
242 |
| 5583 | 243 def testPatchAdd(self): |
| 244 """ | |
| 245 Test Patch op 'Add' | |
| 246 """ | |
| 247 # create a new issue with userid 1 in the nosy list | |
| 248 issue_id = self.db.issue.create(title='foo', nosy=['1']) | |
| 249 | |
| 250 # add userid 2 to the nosy list | |
| 251 form = cgi.FieldStorage() | |
| 252 form.list = [ | |
| 253 cgi.MiniFieldStorage('op', 'add'), | |
| 254 cgi.MiniFieldStorage('nosy', '2') | |
| 255 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
256 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
|
257 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 258 |
| 259 # verify the result | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
260 results = self.server.get_element('issue', issue_id, {})['data'] |
|
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 self.assertEqual(len(results['attributes']['nosy']), 2) |
| 263 self.assertListEqual(results['attributes']['nosy'], ['1', '2']) | |
| 264 | |
| 265 def testPatchReplace(self): | |
| 266 """ | |
| 267 Test Patch op 'Replace' | |
| 268 """ | |
| 269 # create a new issue with userid 1 in the nosy list and status = 1 | |
| 270 issue_id = self.db.issue.create(title='foo', nosy=['1'], status='1') | |
| 271 | |
| 272 # replace userid 2 to the nosy list and status = 3 | |
| 273 form = cgi.FieldStorage() | |
| 274 form.list = [ | |
| 275 cgi.MiniFieldStorage('op', 'replace'), | |
| 276 cgi.MiniFieldStorage('nosy', '2'), | |
| 277 cgi.MiniFieldStorage('status', '3') | |
| 278 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
279 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
|
280 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 281 |
| 282 # verify the result | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
283 results = self.server.get_element('issue', issue_id, {})['data'] |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
284 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 285 self.assertEqual(results['attributes']['status'], '3') |
| 286 self.assertEqual(len(results['attributes']['nosy']), 1) | |
| 287 self.assertListEqual(results['attributes']['nosy'], ['2']) | |
| 288 | |
| 289 def testPatchRemoveAll(self): | |
| 290 """ | |
| 291 Test Patch Action 'Remove' | |
| 292 """ | |
| 293 # create a new issue with userid 1 in the nosy list | |
| 294 issue_id = self.db.issue.create(title='foo', nosy=['1', '2']) | |
| 295 | |
| 296 # remove the nosy list and the title | |
| 297 form = cgi.FieldStorage() | |
| 298 form.list = [ | |
| 299 cgi.MiniFieldStorage('op', 'remove'), | |
| 300 cgi.MiniFieldStorage('nosy', ''), | |
| 301 cgi.MiniFieldStorage('title', '') | |
| 302 ] | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
303 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
|
304 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 305 |
| 306 # verify the result | |
|
5588
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
307 results = self.server.get_element('issue', issue_id, {})['data'] |
|
6b3a9655a7d9
Move decorator to outside of the class
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5586
diff
changeset
|
308 self.assertEqual(self.dummy_client.response_code, 200) |
| 5583 | 309 self.assertEqual(results['attributes']['title'], None) |
| 310 self.assertEqual(len(results['attributes']['nosy']), 0) | |
| 311 self.assertEqual(results['attributes']['nosy'], []) | |
| 312 | |
|
5586
8f2fbc88e155
Fixed code convention
Chau Nguyen <dangchau1991@yahoo.com>
parents:
5585
diff
changeset
|
313 |
| 5583 | 314 def test_suite(): |
| 315 suite = unittest.TestSuite() | |
| 316 for l in list_backends(): | |
| 317 dct = dict(backend=l) | |
| 318 subcls = type(TestCase)('TestCase_%s' % l, (TestCase,), dct) | |
| 319 suite.addTest(unittest.makeSuite(subcls)) | |
| 320 return suite | |
| 321 | |
| 322 if __name__ == '__main__': | |
| 323 runner = unittest.TextTestRunner() | |
| 324 unittest.main(testRunner=runner) |
