@@ 522-587 (lines=66) @@ | ||
519 | status=400 |
|
520 | ) |
|
521 | ||
522 | def test_api__undelete_workspace__ok_200__admin(self) -> None: |
|
523 | """ |
|
524 | Test undelete workspace as admin |
|
525 | """ |
|
526 | self.testapp.authorization = ( |
|
527 | 'Basic', |
|
528 | ( |
|
529 | '[email protected]', |
|
530 | '[email protected]' |
|
531 | ) |
|
532 | ) |
|
533 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
534 | admin = dbsession.query(models.User) \ |
|
535 | .filter(models.User.email == '[email protected]') \ |
|
536 | .one() |
|
537 | uapi = UserApi( |
|
538 | current_user=admin, |
|
539 | session=dbsession, |
|
540 | config=self.app_config, |
|
541 | ) |
|
542 | gapi = GroupApi( |
|
543 | current_user=admin, |
|
544 | session=dbsession, |
|
545 | config=self.app_config, |
|
546 | ) |
|
547 | groups = [gapi.get_one_with_name('administrators')] |
|
548 | user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups) # nopep8 |
|
549 | workspace_api = WorkspaceApi( |
|
550 | current_user=admin, |
|
551 | session=dbsession, |
|
552 | config=self.app_config, |
|
553 | show_deleted=True, |
|
554 | ) |
|
555 | workspace = workspace_api.create_workspace('test', save_now=True) # nopep8 |
|
556 | workspace_api.delete(workspace, flush=True) |
|
557 | transaction.commit() |
|
558 | workspace_id = int(workspace.workspace_id) |
|
559 | self.testapp.authorization = ( |
|
560 | 'Basic', |
|
561 | ( |
|
562 | '[email protected]', |
|
563 | '[email protected]' |
|
564 | ) |
|
565 | ) |
|
566 | # delete |
|
567 | res = self.testapp.put( |
|
568 | '/api/v2/workspaces/{}/undelete'.format(workspace_id), |
|
569 | status=204 |
|
570 | ) |
|
571 | res = self.testapp.get( |
|
572 | '/api/v2/workspaces/{}'.format(workspace_id), |
|
573 | status=403 |
|
574 | ) |
|
575 | self.testapp.authorization = ( |
|
576 | 'Basic', |
|
577 | ( |
|
578 | '[email protected]', |
|
579 | '[email protected]' |
|
580 | ) |
|
581 | ) |
|
582 | res = self.testapp.get( |
|
583 | '/api/v2/workspaces/{}'.format(workspace_id), |
|
584 | status=200 |
|
585 | ) |
|
586 | workspace = res.json_body |
|
587 | assert workspace['is_deleted'] is False |
|
588 | ||
589 | def test_api__undelete_workspace__ok_200__manager_workspace_manager(self) -> None: |
|
590 | """ |
|
@@ 713-773 (lines=61) @@ | ||
710 | workspace = res.json_body |
|
711 | assert workspace['is_deleted'] is True |
|
712 | ||
713 | def test_api__undelete_workspace__err_403__manager_reader(self) -> None: |
|
714 | """ |
|
715 | Test undelete workspace as manager and reader of the workspace |
|
716 | """ |
|
717 | self.testapp.authorization = ( |
|
718 | 'Basic', |
|
719 | ( |
|
720 | '[email protected]', |
|
721 | '[email protected]' |
|
722 | ) |
|
723 | ) |
|
724 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
725 | admin = dbsession.query(models.User) \ |
|
726 | .filter(models.User.email == '[email protected]') \ |
|
727 | .one() |
|
728 | uapi = UserApi( |
|
729 | current_user=admin, |
|
730 | session=dbsession, |
|
731 | config=self.app_config, |
|
732 | ) |
|
733 | gapi = GroupApi( |
|
734 | current_user=admin, |
|
735 | session=dbsession, |
|
736 | config=self.app_config, |
|
737 | ) |
|
738 | groups = [gapi.get_one_with_name('managers')] |
|
739 | user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False) # nopep8 |
|
740 | workspace_api = WorkspaceApi( |
|
741 | current_user=admin, |
|
742 | session=dbsession, |
|
743 | config=self.app_config, |
|
744 | show_deleted=True, |
|
745 | ) |
|
746 | workspace = workspace_api.create_workspace('test', save_now=True) # nopep8 |
|
747 | workspace_api.delete(workspace, flush=True) |
|
748 | rapi = RoleApi( |
|
749 | current_user=admin, |
|
750 | session=dbsession, |
|
751 | config=self.app_config, |
|
752 | ) |
|
753 | rapi.create_one(user, workspace, UserRoleInWorkspace.READER, False) # nopep8 |
|
754 | transaction.commit() |
|
755 | workspace_id = int(workspace.workspace_id) |
|
756 | self.testapp.authorization = ( |
|
757 | 'Basic', |
|
758 | ( |
|
759 | '[email protected]', |
|
760 | '[email protected]' |
|
761 | ) |
|
762 | ) |
|
763 | # delete |
|
764 | res = self.testapp.put( |
|
765 | '/api/v2/workspaces/{}/undelete'.format(workspace_id), |
|
766 | status=403 |
|
767 | ) |
|
768 | res = self.testapp.get( |
|
769 | '/api/v2/workspaces/{}'.format(workspace_id), |
|
770 | status=200 |
|
771 | ) |
|
772 | workspace = res.json_body |
|
773 | assert workspace['is_deleted'] is True |
|
774 | ||
775 | def test_api__undelete_workspace__err_400__manager(self) -> None: |
|
776 | """ |
|
@@ 651-711 (lines=61) @@ | ||
648 | workspace = res.json_body |
|
649 | assert workspace['is_deleted'] is False |
|
650 | ||
651 | def test_api__undelete_workspace__err_403__user_workspace_manager(self) -> None: |
|
652 | """ |
|
653 | Test undelete workspace as simple user and workspace manager |
|
654 | """ |
|
655 | self.testapp.authorization = ( |
|
656 | 'Basic', |
|
657 | ( |
|
658 | '[email protected]', |
|
659 | '[email protected]' |
|
660 | ) |
|
661 | ) |
|
662 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
663 | admin = dbsession.query(models.User) \ |
|
664 | .filter(models.User.email == '[email protected]') \ |
|
665 | .one() |
|
666 | uapi = UserApi( |
|
667 | current_user=admin, |
|
668 | session=dbsession, |
|
669 | config=self.app_config, |
|
670 | ) |
|
671 | gapi = GroupApi( |
|
672 | current_user=admin, |
|
673 | session=dbsession, |
|
674 | config=self.app_config, |
|
675 | ) |
|
676 | groups = [gapi.get_one_with_name('users')] |
|
677 | user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups) # nopep8 |
|
678 | workspace_api = WorkspaceApi( |
|
679 | current_user=admin, |
|
680 | session=dbsession, |
|
681 | config=self.app_config, |
|
682 | show_deleted=True, |
|
683 | ) |
|
684 | workspace = workspace_api.create_workspace('test', save_now=True) # nopep8 |
|
685 | workspace_api.delete(workspace, flush=True) |
|
686 | rapi = RoleApi( |
|
687 | current_user=admin, |
|
688 | session=dbsession, |
|
689 | config=self.app_config, |
|
690 | ) |
|
691 | rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 |
|
692 | transaction.commit() |
|
693 | workspace_id = int(workspace.workspace_id) |
|
694 | self.testapp.authorization = ( |
|
695 | 'Basic', |
|
696 | ( |
|
697 | '[email protected]', |
|
698 | '[email protected]' |
|
699 | ) |
|
700 | ) |
|
701 | # delete |
|
702 | res = self.testapp.put( |
|
703 | '/api/v2/workspaces/{}/undelete'.format(workspace_id), |
|
704 | status=403 |
|
705 | ) |
|
706 | res = self.testapp.get( |
|
707 | '/api/v2/workspaces/{}'.format(workspace_id), |
|
708 | status=200 |
|
709 | ) |
|
710 | workspace = res.json_body |
|
711 | assert workspace['is_deleted'] is True |
|
712 | ||
713 | def test_api__undelete_workspace__err_403__manager_reader(self) -> None: |
|
714 | """ |
|
@@ 589-649 (lines=61) @@ | ||
586 | workspace = res.json_body |
|
587 | assert workspace['is_deleted'] is False |
|
588 | ||
589 | def test_api__undelete_workspace__ok_200__manager_workspace_manager(self) -> None: |
|
590 | """ |
|
591 | Test undelete workspace as global manager and workspace manager |
|
592 | """ |
|
593 | self.testapp.authorization = ( |
|
594 | 'Basic', |
|
595 | ( |
|
596 | '[email protected]', |
|
597 | '[email protected]' |
|
598 | ) |
|
599 | ) |
|
600 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
601 | admin = dbsession.query(models.User) \ |
|
602 | .filter(models.User.email == '[email protected]') \ |
|
603 | .one() |
|
604 | uapi = UserApi( |
|
605 | current_user=admin, |
|
606 | session=dbsession, |
|
607 | config=self.app_config, |
|
608 | ) |
|
609 | gapi = GroupApi( |
|
610 | current_user=admin, |
|
611 | session=dbsession, |
|
612 | config=self.app_config, |
|
613 | ) |
|
614 | groups = [gapi.get_one_with_name('managers')] |
|
615 | user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups) # nopep8 |
|
616 | workspace_api = WorkspaceApi( |
|
617 | current_user=admin, |
|
618 | session=dbsession, |
|
619 | config=self.app_config, |
|
620 | show_deleted=True, |
|
621 | ) |
|
622 | workspace = workspace_api.create_workspace('test', save_now=True) # nopep8 |
|
623 | workspace_api.delete(workspace, flush=True) |
|
624 | rapi = RoleApi( |
|
625 | current_user=admin, |
|
626 | session=dbsession, |
|
627 | config=self.app_config, |
|
628 | ) |
|
629 | rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 |
|
630 | transaction.commit() |
|
631 | workspace_id = int(workspace.workspace_id) |
|
632 | self.testapp.authorization = ( |
|
633 | 'Basic', |
|
634 | ( |
|
635 | '[email protected]', |
|
636 | '[email protected]' |
|
637 | ) |
|
638 | ) |
|
639 | # delete |
|
640 | res = self.testapp.put( |
|
641 | '/api/v2/workspaces/{}/undelete'.format(workspace_id), |
|
642 | status=204 |
|
643 | ) |
|
644 | res = self.testapp.get( |
|
645 | '/api/v2/workspaces/{}'.format(workspace_id), |
|
646 | status=200 |
|
647 | ) |
|
648 | workspace = res.json_body |
|
649 | assert workspace['is_deleted'] is False |
|
650 | ||
651 | def test_api__undelete_workspace__err_403__user_workspace_manager(self) -> None: |
|
652 | """ |
|
@@ 410-469 (lines=60) @@ | ||
407 | workspace = res.json_body |
|
408 | assert workspace['is_deleted'] is False |
|
409 | ||
410 | def test_api__delete_workspace__err_403__manager_reader(self) -> None: |
|
411 | """ |
|
412 | Test delete workspace as manager and reader of the workspace |
|
413 | """ |
|
414 | self.testapp.authorization = ( |
|
415 | 'Basic', |
|
416 | ( |
|
417 | '[email protected]', |
|
418 | '[email protected]' |
|
419 | ) |
|
420 | ) |
|
421 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
422 | admin = dbsession.query(models.User) \ |
|
423 | .filter(models.User.email == '[email protected]') \ |
|
424 | .one() |
|
425 | uapi = UserApi( |
|
426 | current_user=admin, |
|
427 | session=dbsession, |
|
428 | config=self.app_config, |
|
429 | ) |
|
430 | gapi = GroupApi( |
|
431 | current_user=admin, |
|
432 | session=dbsession, |
|
433 | config=self.app_config, |
|
434 | ) |
|
435 | groups = [gapi.get_one_with_name('managers')] |
|
436 | user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False) # nopep8 |
|
437 | workspace_api = WorkspaceApi( |
|
438 | current_user=admin, |
|
439 | session=dbsession, |
|
440 | config=self.app_config, |
|
441 | show_deleted=True, |
|
442 | ) |
|
443 | workspace = workspace_api.create_workspace('test', save_now=True) # nopep8 |
|
444 | rapi = RoleApi( |
|
445 | current_user=admin, |
|
446 | session=dbsession, |
|
447 | config=self.app_config, |
|
448 | ) |
|
449 | rapi.create_one(user, workspace, UserRoleInWorkspace.READER, False) # nopep8 |
|
450 | transaction.commit() |
|
451 | workspace_id = int(workspace.workspace_id) |
|
452 | self.testapp.authorization = ( |
|
453 | 'Basic', |
|
454 | ( |
|
455 | '[email protected]', |
|
456 | '[email protected]' |
|
457 | ) |
|
458 | ) |
|
459 | # delete |
|
460 | res = self.testapp.put( |
|
461 | '/api/v2/workspaces/{}/delete'.format(workspace_id), |
|
462 | status=403 |
|
463 | ) |
|
464 | res = self.testapp.get( |
|
465 | '/api/v2/workspaces/{}'.format(workspace_id), |
|
466 | status=200 |
|
467 | ) |
|
468 | workspace = res.json_body |
|
469 | assert workspace['is_deleted'] is False |
|
470 | ||
471 | def test_api__delete_workspace__err_400__manager(self) -> None: |
|
472 | """ |
|
@@ 349-408 (lines=60) @@ | ||
346 | workspace = res.json_body |
|
347 | assert workspace['is_deleted'] is True |
|
348 | ||
349 | def test_api__delete_workspace__err_403__user_workspace_manager(self) -> None: |
|
350 | """ |
|
351 | Test delete workspace as simple user and workspace manager |
|
352 | """ |
|
353 | self.testapp.authorization = ( |
|
354 | 'Basic', |
|
355 | ( |
|
356 | '[email protected]', |
|
357 | '[email protected]' |
|
358 | ) |
|
359 | ) |
|
360 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
361 | admin = dbsession.query(models.User) \ |
|
362 | .filter(models.User.email == '[email protected]') \ |
|
363 | .one() |
|
364 | uapi = UserApi( |
|
365 | current_user=admin, |
|
366 | session=dbsession, |
|
367 | config=self.app_config, |
|
368 | ) |
|
369 | gapi = GroupApi( |
|
370 | current_user=admin, |
|
371 | session=dbsession, |
|
372 | config=self.app_config, |
|
373 | ) |
|
374 | groups = [gapi.get_one_with_name('users')] |
|
375 | user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups) # nopep8 |
|
376 | workspace_api = WorkspaceApi( |
|
377 | current_user=admin, |
|
378 | session=dbsession, |
|
379 | config=self.app_config, |
|
380 | show_deleted=True, |
|
381 | ) |
|
382 | workspace = workspace_api.create_workspace('test', save_now=True) # nopep8 |
|
383 | rapi = RoleApi( |
|
384 | current_user=admin, |
|
385 | session=dbsession, |
|
386 | config=self.app_config, |
|
387 | ) |
|
388 | rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 |
|
389 | transaction.commit() |
|
390 | workspace_id = int(workspace.workspace_id) |
|
391 | self.testapp.authorization = ( |
|
392 | 'Basic', |
|
393 | ( |
|
394 | '[email protected]', |
|
395 | '[email protected]' |
|
396 | ) |
|
397 | ) |
|
398 | # delete |
|
399 | res = self.testapp.put( |
|
400 | '/api/v2/workspaces/{}/delete'.format(workspace_id), |
|
401 | status=403 |
|
402 | ) |
|
403 | res = self.testapp.get( |
|
404 | '/api/v2/workspaces/{}'.format(workspace_id), |
|
405 | status=200 |
|
406 | ) |
|
407 | workspace = res.json_body |
|
408 | assert workspace['is_deleted'] is False |
|
409 | ||
410 | def test_api__delete_workspace__err_403__manager_reader(self) -> None: |
|
411 | """ |
|
@@ 288-347 (lines=60) @@ | ||
285 | workspace = res.json_body |
|
286 | assert workspace['is_deleted'] is True |
|
287 | ||
288 | def test_api__delete_workspace__ok_200__manager_workspace_manager(self) -> None: |
|
289 | """ |
|
290 | Test delete workspace as global manager and workspace manager |
|
291 | """ |
|
292 | self.testapp.authorization = ( |
|
293 | 'Basic', |
|
294 | ( |
|
295 | '[email protected]', |
|
296 | '[email protected]' |
|
297 | ) |
|
298 | ) |
|
299 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
300 | admin = dbsession.query(models.User) \ |
|
301 | .filter(models.User.email == '[email protected]') \ |
|
302 | .one() |
|
303 | uapi = UserApi( |
|
304 | current_user=admin, |
|
305 | session=dbsession, |
|
306 | config=self.app_config, |
|
307 | ) |
|
308 | gapi = GroupApi( |
|
309 | current_user=admin, |
|
310 | session=dbsession, |
|
311 | config=self.app_config, |
|
312 | ) |
|
313 | groups = [gapi.get_one_with_name('managers')] |
|
314 | user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups) # nopep8 |
|
315 | workspace_api = WorkspaceApi( |
|
316 | current_user=admin, |
|
317 | session=dbsession, |
|
318 | config=self.app_config, |
|
319 | show_deleted=True, |
|
320 | ) |
|
321 | workspace = workspace_api.create_workspace('test', save_now=True) # nopep8 |
|
322 | rapi = RoleApi( |
|
323 | current_user=admin, |
|
324 | session=dbsession, |
|
325 | config=self.app_config, |
|
326 | ) |
|
327 | rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 |
|
328 | transaction.commit() |
|
329 | workspace_id = int(workspace.workspace_id) |
|
330 | self.testapp.authorization = ( |
|
331 | 'Basic', |
|
332 | ( |
|
333 | '[email protected]', |
|
334 | '[email protected]' |
|
335 | ) |
|
336 | ) |
|
337 | # delete |
|
338 | res = self.testapp.put( |
|
339 | '/api/v2/workspaces/{}/delete'.format(workspace_id), |
|
340 | status=204 |
|
341 | ) |
|
342 | res = self.testapp.get( |
|
343 | '/api/v2/workspaces/{}'.format(workspace_id), |
|
344 | status=200 |
|
345 | ) |
|
346 | workspace = res.json_body |
|
347 | assert workspace['is_deleted'] is True |
|
348 | ||
349 | def test_api__delete_workspace__err_403__user_workspace_manager(self) -> None: |
|
350 | """ |