| 333 | self.assertTrue(len(res.data['can_rerun_from']) == 0) |
| 334 | |
| 335 | def test_processingnodes(self): |
| 336 | client = APIClient() |
| 337 | |
| 338 | pnode = ProcessingNode.objects.create( |
| 339 | hostname="localhost", |
| 340 | port=999 |
| 341 | ) |
| 342 | |
| 343 | another_pnode = ProcessingNode.objects.create( |
| 344 | hostname="localhost", |
| 345 | port=998 |
| 346 | ) |
| 347 | |
| 348 | # Cannot list processing nodes as guest |
| 349 | res = client.get('/api/processingnodes/') |
| 350 | self.assertEqual(res.status_code, status.HTTP_403_FORBIDDEN) |
| 351 | |
| 352 | res = client.get('/api/processingnodes/{}/'.format(pnode.id)) |
| 353 | self.assertEqual(res.status_code, status.HTTP_403_FORBIDDEN) |
| 354 | |
| 355 | # Cannot get options as guest |
| 356 | res = client.get('/api/processingnodes/options/') |
| 357 | self.assertEqual(res.status_code, status.HTTP_403_FORBIDDEN) |
| 358 | |
| 359 | client.login(username="testuser", password="test1234") |
| 360 | |
| 361 | # Cannot list processing nodes, unless permissions have been granted |
| 362 | res = client.get('/api/processingnodes/') |
| 363 | self.assertEqual(res.status_code, status.HTTP_200_OK) |
| 364 | self.assertTrue(len(res.data) == 0) |
| 365 | |
| 366 | user = User.objects.get(username="testuser") |
| 367 | self.assertFalse(user.is_staff) |
| 368 | self.assertFalse(user.is_superuser) |
| 369 | self.assertFalse(user.has_perm('view_processingnode', pnode)) |
| 370 | assign_perm('view_processingnode', user, pnode) |
| 371 | self.assertTrue(user.has_perm('view_processingnode', pnode)) |
| 372 | |
| 373 | # Now we can list processing nodes as normal user |
| 374 | res = client.get('/api/processingnodes/') |
| 375 | self.assertEqual(res.status_code, status.HTTP_200_OK) |
| 376 | self.assertTrue(len(res.data) == 1) |
| 377 | self.assertTrue(res.data[0]["hostname"] == "localhost") |
| 378 | |
| 379 | # Can use filters |
| 380 | res = client.get('/api/processingnodes/?id={}'.format(pnode.id)) |
| 381 | self.assertEqual(res.status_code, status.HTTP_200_OK) |
| 382 | self.assertTrue(len(res.data) == 1) |
| 383 | |
| 384 | res = client.get('/api/processingnodes/?id={}'.format(another_pnode.id)) |
| 385 | self.assertEqual(res.status_code, status.HTTP_200_OK) |
| 386 | self.assertTrue(len(res.data) == 0) |
| 387 | |
| 388 | # Can filter nodes with valid options |
| 389 | res = client.get('/api/processingnodes/?has_available_options=true') |
| 390 | self.assertEqual(res.status_code, status.HTTP_200_OK) |
| 391 | self.assertTrue(len(res.data) == 0) |
| 392 | |