|
3 | 3 | import json |
4 | 4 |
|
5 | 5 | from django.test import TestCase |
| 6 | +from django.test.utils import override_settings |
6 | 7 |
|
7 | 8 |
|
| 9 | +@override_settings(CELERY_ALWAYS_EAGER=True) |
8 | 10 | class TestAdminPerms(TestCase): |
9 | 11 |
|
10 | 12 | def test_first_signup(self): |
@@ -132,6 +134,7 @@ def test_delete(self): |
132 | 134 | self.assertNotIn('two', str(response.data['results'])) |
133 | 135 |
|
134 | 136 |
|
| 137 | +@override_settings(CELERY_ALWAYS_EAGER=True) |
135 | 138 | class TestAppPerms(TestCase): |
136 | 139 |
|
137 | 140 | fixtures = ['test_sharing.json'] |
@@ -215,120 +218,3 @@ def test_list(self): |
215 | 218 | response = self.client.get( |
216 | 219 | "/api/apps/{}/perms".format(app_id), content_type='application/json') |
217 | 220 | self.assertEqual(response.data, {'users': ['autotest-2']}) |
218 | | - |
219 | | - |
220 | | -class TestFormationPerms(TestCase): |
221 | | - |
222 | | - fixtures = ['test_sharing.json'] |
223 | | - |
224 | | - def setUp(self): |
225 | | - self.assertTrue( |
226 | | - self.client.login(username='autotest-1', password='password')) |
227 | | - |
228 | | - def test_create(self): |
229 | | - # check that user 1 sees her lone formation |
230 | | - response = self.client.get('/api/formations') |
231 | | - self.assertEqual(response.status_code, 200) |
232 | | - self.assertEqual(len(response.data['results']), 1) |
233 | | - formation_id = response.data['results'][0]['id'] |
234 | | - # check that user 2 can't see any formations |
235 | | - self.assertTrue( |
236 | | - self.client.login(username='autotest-2', password='password')) |
237 | | - response = self.client.get('/api/formations') |
238 | | - self.assertEqual(response.status_code, 200) |
239 | | - self.assertEqual(len(response.data['results']), 0) |
240 | | - # give user 2 permission to user 1's formation |
241 | | - self.assertTrue( |
242 | | - self.client.login(username='autotest-1', password='password')) |
243 | | - url = '/api/formations/{formation_id}/perms'.format(**locals()) |
244 | | - body = {'username': 'autotest-2'} |
245 | | - response = self.client.post( |
246 | | - url, json.dumps(body), content_type='application/json') |
247 | | - self.assertEqual(response.status_code, 201) |
248 | | - # check that user 1 can see a formation |
249 | | - self.assertTrue( |
250 | | - self.client.login(username='autotest-2', password='password')) |
251 | | - response = self.client.get('/api/formations') |
252 | | - self.assertEqual(response.status_code, 200) |
253 | | - self.assertEqual(len(response.data['results']), 1) |
254 | | - self.assertEqual(response.data['results'][0]['id'], formation_id) |
255 | | - # revoke user 2's permission to user 1's formation |
256 | | - self.assertTrue( |
257 | | - self.client.login(username='autotest-1', password='password')) |
258 | | - username = 'autotest-2' |
259 | | - url = '/api/formations/{formation_id}/perms/{username}/'.format(**locals()) |
260 | | - response = self.client.delete(url) |
261 | | - self.assertEqual(response.status_code, 204) |
262 | | - |
263 | | - def test_create_errors(self): |
264 | | - response = self.client.get('/api/formations') |
265 | | - formation_id = response.data['results'][0]['id'] |
266 | | - # try to give user 2 permission to user 1's formation as user 2 |
267 | | - self.assertTrue( |
268 | | - self.client.login(username='autotest-2', password='password')) |
269 | | - url = '/api/formations/{formation_id}/perms'.format(**locals()) |
270 | | - body = {'username': 'autotest-2'} |
271 | | - response = self.client.post( |
272 | | - url, json.dumps(body), content_type='application/json') |
273 | | - self.assertEqual(response.status_code, 403) |
274 | | - # try to give user 1 permission to user 1's formation as user 2 |
275 | | - url = '/api/formations/{formation_id}/perms'.format(**locals()) |
276 | | - body = {'username': 'autotest-1'} |
277 | | - response = self.client.post( |
278 | | - url, json.dumps(body), content_type='application/json') |
279 | | - self.assertEqual(response.status_code, 403) |
280 | | - |
281 | | - def test_delete(self): |
282 | | - # give user 2 permission to user 1's formation |
283 | | - response = self.client.get('/api/formations') |
284 | | - formation_id = response.data['results'][0]['id'] |
285 | | - url = '/api/formations/{formation_id}/perms'.format(**locals()) |
286 | | - body = {'username': 'autotest-2'} |
287 | | - response = self.client.post( |
288 | | - url, json.dumps(body), content_type='application/json') |
289 | | - self.assertEqual(response.status_code, 201) |
290 | | - # check that user 1 can see a formation |
291 | | - self.assertTrue( |
292 | | - self.client.login(username='autotest-2', password='password')) |
293 | | - response = self.client.get('/api/formations') |
294 | | - self.assertEqual(response.status_code, 200) |
295 | | - self.assertEqual(len(response.data['results']), 1) |
296 | | - self.assertEqual(response.data['results'][0]['id'], formation_id) |
297 | | - # revoke user 2's permission to user 1's formation |
298 | | - self.assertTrue( |
299 | | - self.client.login(username='autotest-1', password='password')) |
300 | | - username = 'autotest-2' |
301 | | - url = '/api/formations/{formation_id}/perms/{username}/'.format(**locals()) |
302 | | - response = self.client.delete(url) |
303 | | - self.assertEqual(response.status_code, 204) |
304 | | - # check that user 1 can't see any formations |
305 | | - self.assertTrue( |
306 | | - self.client.login(username='autotest-2', password='password')) |
307 | | - response = self.client.get('/api/formations') |
308 | | - self.assertEqual(response.status_code, 200) |
309 | | - self.assertEqual(len(response.data['results']), 0) |
310 | | - |
311 | | - def test_delete_errors(self): |
312 | | - # revoke user 2's permission to user 1's formation |
313 | | - response = self.client.get('/api/formations') |
314 | | - formation_id = response.data['results'][0]['id'] |
315 | | - username = 'autotest-2' |
316 | | - url = '/api/formations/{formation_id}/perms/{username}/'.format(**locals()) |
317 | | - response = self.client.delete(url) |
318 | | - self.assertEqual(response.status_code, 404) |
319 | | - |
320 | | - def test_list(self): |
321 | | - # check that user 1 sees her lone formation |
322 | | - response = self.client.get('/api/formations') |
323 | | - self.assertEqual(response.status_code, 200) |
324 | | - self.assertEqual(len(response.data['results']), 1) |
325 | | - formation_id = response.data['results'][0]['id'] |
326 | | - # create a new object permission |
327 | | - url = "/api/formations/{}/perms".format(formation_id) |
328 | | - body = {'username': 'autotest-2'} |
329 | | - response = self.client.post(url, json.dumps(body), content_type='application/json') |
330 | | - self.assertEqual(response.status_code, 201) |
331 | | - # list perms on the app |
332 | | - response = self.client.get( |
333 | | - "/api/formations/{}/perms".format(formation_id), content_type='application/json') |
334 | | - self.assertEqual(response.data, {'users': ['autotest-2']}) |
0 commit comments