| @@ 511-621 (lines=111) @@ | ||
| 508 |         eq_('', c.label) | |
| 509 | eq_(ActionDescription.COMMENT, c.revision_type) | |
| 510 | ||
| 511 | def test_unit_copy_file_different_label_different_parent_ok(self): | |
| 512 | uapi = UserApi( | |
| 513 | session=self.session, | |
| 514 | config=self.app_config, | |
| 515 | current_user=None, | |
| 516 | ) | |
| 517 | group_api = GroupApi( | |
| 518 | current_user=None, | |
| 519 | session=self.session | |
| 520 | ) | |
| 521 | groups = [group_api.get_one(Group.TIM_USER), | |
| 522 | group_api.get_one(Group.TIM_MANAGER), | |
| 523 | group_api.get_one(Group.TIM_ADMIN)] | |
| 524 | ||
| 525 | user = uapi.create_user( | |
| 526 | email='user1@user', | |
| 527 | groups=groups, | |
| 528 | save_now=True | |
| 529 | ) | |
| 530 | user2 = uapi.create_user( | |
| 531 | email='user2@user', | |
| 532 | groups=groups, | |
| 533 | save_now=True | |
| 534 | ) | |
| 535 | workspace = WorkspaceApi( | |
| 536 | current_user=user, | |
| 537 | session=self.session | |
| 538 | ).create_workspace( | |
| 539 | 'test workspace', | |
| 540 | save_now=True | |
| 541 | ) | |
| 542 | RoleApi(current_user=user, session=self.session).create_one( | |
| 543 | user2, | |
| 544 | workspace, | |
| 545 | UserRoleInWorkspace.WORKSPACE_MANAGER, | |
| 546 | with_notif=False | |
| 547 | ) | |
| 548 | api = ContentApi( | |
| 549 | current_user=user, | |
| 550 | session=self.session, | |
| 551 | config=self.app_config, | |
| 552 | ) | |
| 553 | foldera = api.create( | |
| 554 | ContentType.Folder, | |
| 555 | workspace, | |
| 556 | None, | |
| 557 | 'folder a', | |
| 558 | True | |
| 559 | ) | |
| 560 | with self.session.no_autoflush: | |
| 561 | text_file = api.create( | |
| 562 | content_type=ContentType.File, | |
| 563 | workspace=workspace, | |
| 564 | parent=foldera, | |
| 565 | label='test_file', | |
| 566 | do_save=False, | |
| 567 | ) | |
| 568 | api.update_file_data( | |
| 569 | text_file, | |
| 570 | 'test_file', | |
| 571 | 'text/plain', | |
| 572 | b'test_content' | |
| 573 | ) | |
| 574 | ||
| 575 | api.save(text_file, ActionDescription.CREATION) | |
| 576 | api2 = ContentApi( | |
| 577 | current_user=user2, | |
| 578 | session=self.session, | |
| 579 | config=self.app_config, | |
| 580 | ) | |
| 581 | workspace2 = WorkspaceApi( | |
| 582 | current_user=user2, | |
| 583 | session=self.session, | |
| 584 | ).create_workspace( | |
| 585 | 'test workspace2', | |
| 586 | save_now=True | |
| 587 | ) | |
| 588 | folderb = api2.create( | |
| 589 | ContentType.Folder, | |
| 590 | workspace2, | |
| 591 | None, | |
| 592 | 'folder b', | |
| 593 | True | |
| 594 | ) | |
| 595 | ||
| 596 | api2.copy( | |
| 597 | item=text_file, | |
| 598 | new_parent=folderb, | |
| 599 | new_label='test_file_copy' | |
| 600 | ) | |
| 601 | ||
| 602 | transaction.commit() | |
| 603 | text_file_copy = api2.get_one_by_label_and_parent( | |
| 604 | 'test_file_copy', | |
| 605 | folderb, | |
| 606 | ) | |
| 607 | ||
| 608 | assert text_file != text_file_copy | |
| 609 | assert text_file_copy.content_id != text_file.content_id | |
| 610 | assert text_file_copy.workspace_id == workspace2.workspace_id | |
| 611 | assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read() # nopep8 | |
| 612 | assert text_file_copy.depot_file.path != text_file.depot_file.path | |
| 613 | assert text_file_copy.label == 'test_file_copy' | |
| 614 | assert text_file_copy.type == text_file.type | |
| 615 | assert text_file_copy.parent.content_id == folderb.content_id | |
| 616 | assert text_file_copy.owner.user_id == user.user_id | |
| 617 | assert text_file_copy.description == text_file.description | |
| 618 | assert text_file_copy.file_extension == text_file.file_extension | |
| 619 | assert text_file_copy.file_mimetype == text_file.file_mimetype | |
| 620 | assert text_file_copy.revision_type == ActionDescription.COPY | |
| 621 | assert len(text_file_copy.revisions) == len(text_file.revisions) + 1 | |
| 622 | ||
| 623 | def test_unit_copy_file__same_label_different_parent_ok(self): | |
| 624 | uapi = UserApi( | |
| @@ 623-731 (lines=109) @@ | ||
| 620 | assert text_file_copy.revision_type == ActionDescription.COPY | |
| 621 | assert len(text_file_copy.revisions) == len(text_file.revisions) + 1 | |
| 622 | ||
| 623 | def test_unit_copy_file__same_label_different_parent_ok(self): | |
| 624 | uapi = UserApi( | |
| 625 | session=self.session, | |
| 626 | config=self.app_config, | |
| 627 | current_user=None, | |
| 628 | ) | |
| 629 | group_api = GroupApi( | |
| 630 | current_user=None, | |
| 631 | session=self.session | |
| 632 | ) | |
| 633 | groups = [group_api.get_one(Group.TIM_USER), | |
| 634 | group_api.get_one(Group.TIM_MANAGER), | |
| 635 | group_api.get_one(Group.TIM_ADMIN)] | |
| 636 | ||
| 637 | user = uapi.create_user( | |
| 638 | email='user1@user', | |
| 639 | groups=groups, | |
| 640 | save_now=True | |
| 641 | ) | |
| 642 | user2 = uapi.create_user( | |
| 643 | email='user2@user', | |
| 644 | groups=groups, | |
| 645 | save_now=True | |
| 646 | ) | |
| 647 | workspace = WorkspaceApi( | |
| 648 | current_user=user, | |
| 649 | session=self.session | |
| 650 | ).create_workspace( | |
| 651 | 'test workspace', | |
| 652 | save_now=True | |
| 653 | ) | |
| 654 | RoleApi(current_user=user, session=self.session).create_one( | |
| 655 | user2, | |
| 656 | workspace, | |
| 657 | UserRoleInWorkspace.WORKSPACE_MANAGER, | |
| 658 | with_notif=False | |
| 659 | ) | |
| 660 | api = ContentApi( | |
| 661 | current_user=user, | |
| 662 | session=self.session, | |
| 663 | config=self.app_config, | |
| 664 | ) | |
| 665 | foldera = api.create( | |
| 666 | ContentType.Folder, | |
| 667 | workspace, | |
| 668 | None, | |
| 669 | 'folder a', | |
| 670 | True | |
| 671 | ) | |
| 672 | with self.session.no_autoflush: | |
| 673 | text_file = api.create( | |
| 674 | content_type=ContentType.File, | |
| 675 | workspace=workspace, | |
| 676 | parent=foldera, | |
| 677 | label='test_file', | |
| 678 | do_save=False, | |
| 679 | ) | |
| 680 | api.update_file_data( | |
| 681 | text_file, | |
| 682 | 'test_file', | |
| 683 | 'text/plain', | |
| 684 | b'test_content' | |
| 685 | ) | |
| 686 | ||
| 687 | api.save(text_file, ActionDescription.CREATION) | |
| 688 | api2 = ContentApi( | |
| 689 | current_user=user2, | |
| 690 | session=self.session, | |
| 691 | config=self.app_config, | |
| 692 | ) | |
| 693 | workspace2 = WorkspaceApi( | |
| 694 | current_user=user2, | |
| 695 | session=self.session | |
| 696 | ).create_workspace( | |
| 697 | 'test workspace2', | |
| 698 | save_now=True | |
| 699 | ) | |
| 700 | folderb = api2.create( | |
| 701 | ContentType.Folder, | |
| 702 | workspace2, | |
| 703 | None, | |
| 704 | 'folder b', | |
| 705 | True | |
| 706 | ) | |
| 707 | api2.copy( | |
| 708 | item=text_file, | |
| 709 | new_parent=folderb, | |
| 710 | ) | |
| 711 | ||
| 712 | transaction.commit() | |
| 713 | text_file_copy = api2.get_one_by_label_and_parent( | |
| 714 | 'test_file', | |
| 715 | folderb, | |
| 716 | ) | |
| 717 | ||
| 718 | assert text_file != text_file_copy | |
| 719 | assert text_file_copy.content_id != text_file.content_id | |
| 720 | assert text_file_copy.workspace_id == workspace2.workspace_id | |
| 721 | assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read() # nopep8 | |
| 722 | assert text_file_copy.depot_file.path != text_file.depot_file.path | |
| 723 | assert text_file_copy.label == text_file.label | |
| 724 | assert text_file_copy.type == text_file.type | |
| 725 | assert text_file_copy.parent.content_id == folderb.content_id | |
| 726 | assert text_file_copy.owner.user_id == user.user_id | |
| 727 | assert text_file_copy.description == text_file.description | |
| 728 | assert text_file_copy.file_extension == text_file.file_extension | |
| 729 | assert text_file_copy.file_mimetype == text_file.file_mimetype | |
| 730 | assert text_file_copy.revision_type == ActionDescription.COPY | |
| 731 | assert len(text_file_copy.revisions) == len(text_file.revisions) + 1 | |
| 732 | ||
| 733 | def test_unit_copy_file_different_label_same_parent_ok(self): | |
| 734 | uapi = UserApi( | |