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