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