Code Duplication    Length = 118-120 lines in 2 locations

backend/tracim_backend/tests/library/test_content_api.py 2 locations

@@ 912-1031 (lines=120) @@
909
        eq_('', c.label)
910
        eq_(ActionDescription.COMMENT, c.revision_type)
911
912
    def test_unit_copy_file_different_label_different_parent_ok(self):
913
        uapi = UserApi(
914
            session=self.session,
915
            config=self.app_config,
916
            current_user=None,
917
        )
918
        group_api = GroupApi(
919
            current_user=None,
920
            session=self.session,
921
            config=self.app_config
922
        )
923
        groups = [group_api.get_one(Group.TIM_USER),
924
                  group_api.get_one(Group.TIM_MANAGER),
925
                  group_api.get_one(Group.TIM_ADMIN)]
926
927
        user = uapi.create_minimal_user(
928
            email='user1@user',
929
            groups=groups,
930
            save_now=True
931
        )
932
        user2 = uapi.create_minimal_user(
933
            email='user2@user',
934
            groups=groups,
935
            save_now=True
936
        )
937
        workspace = WorkspaceApi(
938
            current_user=user,
939
            session=self.session,
940
            config=self.app_config,
941
        ).create_workspace(
942
            'test workspace',
943
            save_now=True
944
        )
945
        RoleApi(
946
            current_user=user,
947
            session=self.session,
948
            config=self.app_config,
949
        ).create_one(
950
            user2,
951
            workspace,
952
            UserRoleInWorkspace.WORKSPACE_MANAGER,
953
            with_notif=False
954
        )
955
        api = ContentApi(
956
            current_user=user,
957
            session=self.session,
958
            config=self.app_config,
959
        )
960
        foldera = api.create(
961
            CONTENT_TYPES.Folder.slug,
962
            workspace,
963
            None,
964
            'folder a',
965
            '',
966
            True
967
        )
968
        with self.session.no_autoflush:
969
            text_file = api.create(
970
                content_type_slug=CONTENT_TYPES.File.slug,
971
                workspace=workspace,
972
                parent=foldera,
973
                label='test_file',
974
                do_save=False,
975
            )
976
            api.update_file_data(
977
                text_file,
978
                'test_file',
979
                'text/plain',
980
                b'test_content'
981
            )
982
983
        api.save(text_file, ActionDescription.CREATION)
984
        api2 = ContentApi(
985
            current_user=user2,
986
            session=self.session,
987
            config=self.app_config,
988
        )
989
        workspace2 = WorkspaceApi(
990
            current_user=user2,
991
            session=self.session,
992
            config=self.app_config,
993
        ).create_workspace(
994
            'test workspace2',
995
            save_now=True
996
        )
997
        folderb = api2.create(
998
            CONTENT_TYPES.Folder.slug,
999
            workspace2,
1000
            None,
1001
            'folder b',
1002
            '',
1003
            True
1004
        )
1005
1006
        api2.copy(
1007
            item=text_file,
1008
            new_parent=folderb,
1009
            new_label='test_file_copy'
1010
        )
1011
1012
        transaction.commit()
1013
        text_file_copy = api2.get_one_by_label_and_parent(
1014
            'test_file_copy',
1015
            folderb,
1016
        )
1017
1018
        assert text_file != text_file_copy
1019
        assert text_file_copy.content_id != text_file.content_id
1020
        assert text_file_copy.workspace_id == workspace2.workspace_id
1021
        assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read()   # nopep8
1022
        assert text_file_copy.depot_file.path != text_file.depot_file.path
1023
        assert text_file_copy.label == 'test_file_copy'
1024
        assert text_file_copy.type == text_file.type
1025
        assert text_file_copy.parent.content_id == folderb.content_id
1026
        assert text_file_copy.owner.user_id == user.user_id
1027
        assert text_file_copy.description == text_file.description
1028
        assert text_file_copy.file_extension == text_file.file_extension
1029
        assert text_file_copy.file_mimetype == text_file.file_mimetype
1030
        assert text_file_copy.revision_type == ActionDescription.COPY
1031
        assert len(text_file_copy.revisions) == len(text_file.revisions) + 1
1032
1033
    def test_unit_copy_file__same_label_different_parent_ok(self):
1034
        uapi = UserApi(
@@ 1033-1150 (lines=118) @@
1030
        assert text_file_copy.revision_type == ActionDescription.COPY
1031
        assert len(text_file_copy.revisions) == len(text_file.revisions) + 1
1032
1033
    def test_unit_copy_file__same_label_different_parent_ok(self):
1034
        uapi = UserApi(
1035
            session=self.session,
1036
            config=self.app_config,
1037
            current_user=None,
1038
        )
1039
        group_api = GroupApi(
1040
            current_user=None,
1041
            session=self.session,
1042
            config=self.app_config,
1043
        )
1044
        groups = [group_api.get_one(Group.TIM_USER),
1045
                  group_api.get_one(Group.TIM_MANAGER),
1046
                  group_api.get_one(Group.TIM_ADMIN)]
1047
1048
        user = uapi.create_minimal_user(
1049
            email='user1@user',
1050
            groups=groups,
1051
            save_now=True
1052
        )
1053
        user2 = uapi.create_minimal_user(
1054
            email='user2@user',
1055
            groups=groups,
1056
            save_now=True
1057
        )
1058
        workspace = WorkspaceApi(
1059
            current_user=user,
1060
            session=self.session,
1061
            config=self.app_config,
1062
        ).create_workspace(
1063
            'test workspace',
1064
            save_now=True
1065
        )
1066
        RoleApi(
1067
            current_user=user,
1068
            session=self.session,
1069
            config=self.app_config,
1070
        ).create_one(
1071
            user2,
1072
            workspace,
1073
            UserRoleInWorkspace.WORKSPACE_MANAGER,
1074
            with_notif=False
1075
        )
1076
        api = ContentApi(
1077
            current_user=user,
1078
            session=self.session,
1079
            config=self.app_config,
1080
        )
1081
        foldera = api.create(
1082
            CONTENT_TYPES.Folder.slug,
1083
            workspace,
1084
            None,
1085
            'folder a',
1086
            '',
1087
            True
1088
        )
1089
        with self.session.no_autoflush:
1090
            text_file = api.create(
1091
                content_type_slug=CONTENT_TYPES.File.slug,
1092
                workspace=workspace,
1093
                parent=foldera,
1094
                label='test_file',
1095
                do_save=False,
1096
            )
1097
            api.update_file_data(
1098
                text_file,
1099
                'test_file',
1100
                'text/plain',
1101
                b'test_content'
1102
            )
1103
1104
        api.save(text_file, ActionDescription.CREATION)
1105
        api2 = ContentApi(
1106
            current_user=user2,
1107
            session=self.session,
1108
            config=self.app_config,
1109
        )
1110
        workspace2 = WorkspaceApi(
1111
            current_user=user2,
1112
            session=self.session,
1113
            config=self.app_config,
1114
        ).create_workspace(
1115
            'test workspace2',
1116
            save_now=True
1117
        )
1118
        folderb = api2.create(
1119
            CONTENT_TYPES.Folder.slug,
1120
            workspace2,
1121
            None,
1122
            'folder b',
1123
            '',
1124
            True
1125
        )
1126
        api2.copy(
1127
            item=text_file,
1128
            new_parent=folderb,
1129
        )
1130
1131
        transaction.commit()
1132
        text_file_copy = api2.get_one_by_label_and_parent(
1133
            'test_file',
1134
            folderb,
1135
        )
1136
1137
        assert text_file != text_file_copy
1138
        assert text_file_copy.content_id != text_file.content_id
1139
        assert text_file_copy.workspace_id == workspace2.workspace_id
1140
        assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read()  # nopep8
1141
        assert text_file_copy.depot_file.path != text_file.depot_file.path
1142
        assert text_file_copy.label == text_file.label
1143
        assert text_file_copy.type == text_file.type
1144
        assert text_file_copy.parent.content_id == folderb.content_id
1145
        assert text_file_copy.owner.user_id == user.user_id
1146
        assert text_file_copy.description == text_file.description
1147
        assert text_file_copy.file_extension == text_file.file_extension
1148
        assert text_file_copy.file_mimetype == text_file.file_mimetype
1149
        assert text_file_copy.revision_type == ActionDescription.COPY
1150
        assert len(text_file_copy.revisions) == len(text_file.revisions) + 1
1151
1152
    def test_unit_copy_file_different_label_same_parent_ok(self):
1153
        uapi = UserApi(