|
@@ -4,6 +4,7 @@ import datetime
|
4
|
4
|
from nose.tools import eq_, ok_
|
5
|
5
|
from nose.tools import raises
|
6
|
6
|
|
|
7
|
+from depot.io.utils import FileIntent
|
7
|
8
|
import transaction
|
8
|
9
|
|
9
|
10
|
from tracim.lib.content import compare_content_for_sorting_by_type_and_name
|
|
@@ -347,6 +348,267 @@ class TestContentApi(BaseTest, TestStandard):
|
347
|
348
|
eq_('', c.label)
|
348
|
349
|
eq_(ActionDescription.COMMENT, c.revision_type)
|
349
|
350
|
|
|
351
|
+ def test_unit_copy_file_different_label_different_parent_ok(self):
|
|
352
|
+ uapi = UserApi(None)
|
|
353
|
+ groups = [
|
|
354
|
+ GroupApi(None).get_one(Group.TIM_USER),
|
|
355
|
+ GroupApi(None).get_one(Group.TIM_MANAGER),
|
|
356
|
+ GroupApi(None).get_one(Group.TIM_ADMIN)
|
|
357
|
+ ]
|
|
358
|
+
|
|
359
|
+ user = uapi.create_user(
|
|
360
|
+ email='user1@user',
|
|
361
|
+ groups=groups,
|
|
362
|
+ save_now=True
|
|
363
|
+ )
|
|
364
|
+ user2 = uapi.create_user(
|
|
365
|
+ email='user2@user',
|
|
366
|
+ groups=groups,
|
|
367
|
+ save_now=True
|
|
368
|
+ )
|
|
369
|
+ workspace = WorkspaceApi(user).create_workspace(
|
|
370
|
+ 'test workspace',
|
|
371
|
+ save_now=True
|
|
372
|
+ )
|
|
373
|
+ RoleApi(user).create_one(
|
|
374
|
+ user2,
|
|
375
|
+ workspace,
|
|
376
|
+ UserRoleInWorkspace.WORKSPACE_MANAGER,
|
|
377
|
+ with_notif=False
|
|
378
|
+ )
|
|
379
|
+ api = ContentApi(user)
|
|
380
|
+ foldera = api.create(
|
|
381
|
+ ContentType.Folder,
|
|
382
|
+ workspace,
|
|
383
|
+ None,
|
|
384
|
+ 'folder a',
|
|
385
|
+ True
|
|
386
|
+ )
|
|
387
|
+ with DBSession.no_autoflush:
|
|
388
|
+ text_file = api.create(
|
|
389
|
+ content_type=ContentType.File,
|
|
390
|
+ workspace=workspace,
|
|
391
|
+ parent=foldera,
|
|
392
|
+ label='test_file',
|
|
393
|
+ do_save=False,
|
|
394
|
+ )
|
|
395
|
+ api.update_file_data(
|
|
396
|
+ text_file,
|
|
397
|
+ 'test_file',
|
|
398
|
+ 'text/plain',
|
|
399
|
+ b'test_content'
|
|
400
|
+ )
|
|
401
|
+
|
|
402
|
+ api.save(text_file, ActionDescription.CREATION)
|
|
403
|
+ api2 = ContentApi(user2)
|
|
404
|
+ workspace2 = WorkspaceApi(user2).create_workspace(
|
|
405
|
+ 'test workspace2',
|
|
406
|
+ save_now=True
|
|
407
|
+ )
|
|
408
|
+ folderb = api2.create(
|
|
409
|
+ ContentType.Folder,
|
|
410
|
+ workspace2,
|
|
411
|
+ None,
|
|
412
|
+ 'folder b',
|
|
413
|
+ True
|
|
414
|
+ )
|
|
415
|
+
|
|
416
|
+ api2.copy(
|
|
417
|
+ item=text_file,
|
|
418
|
+ new_parent=folderb,
|
|
419
|
+ new_label='test_file_copy'
|
|
420
|
+ )
|
|
421
|
+
|
|
422
|
+ transaction.commit()
|
|
423
|
+ text_file_copy = api2.get_one_by_label_and_parent(
|
|
424
|
+ 'test_file_copy',
|
|
425
|
+ folderb,
|
|
426
|
+ )
|
|
427
|
+
|
|
428
|
+ assert text_file != text_file_copy
|
|
429
|
+ assert text_file_copy.content_id != text_file.content_id
|
|
430
|
+ assert text_file_copy.workspace_id == workspace2.workspace_id
|
|
431
|
+ assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read() # nopep8
|
|
432
|
+ assert text_file_copy.depot_file.path != text_file.depot_file.path
|
|
433
|
+ assert text_file_copy.label == 'test_file_copy'
|
|
434
|
+ assert text_file_copy.type == text_file.type
|
|
435
|
+ assert text_file_copy.parent.content_id == folderb.content_id
|
|
436
|
+ assert text_file_copy.owner.user_id == user.user_id
|
|
437
|
+ assert text_file_copy.description == text_file.description
|
|
438
|
+ assert text_file_copy.file_extension == text_file.file_extension
|
|
439
|
+ assert text_file_copy.file_mimetype == text_file.file_mimetype
|
|
440
|
+ assert text_file_copy.revision_type == ActionDescription.COPY
|
|
441
|
+ assert len(text_file_copy.revisions) == len(text_file.revisions) + 1
|
|
442
|
+
|
|
443
|
+ def test_unit_copy_file__same_label_different_parent_ok(self):
|
|
444
|
+ uapi = UserApi(None)
|
|
445
|
+ groups = [GroupApi(None).get_one(Group.TIM_USER),
|
|
446
|
+ GroupApi(None).get_one(Group.TIM_MANAGER),
|
|
447
|
+ GroupApi(None).get_one(Group.TIM_ADMIN)]
|
|
448
|
+
|
|
449
|
+ user = uapi.create_user(
|
|
450
|
+ email='user1@user',
|
|
451
|
+ groups=groups,
|
|
452
|
+ save_now=True
|
|
453
|
+ )
|
|
454
|
+ user2 = uapi.create_user(
|
|
455
|
+ email='user2@user',
|
|
456
|
+ groups=groups,
|
|
457
|
+ save_now=True
|
|
458
|
+ )
|
|
459
|
+ workspace = WorkspaceApi(user).create_workspace(
|
|
460
|
+ 'test workspace',
|
|
461
|
+ save_now=True
|
|
462
|
+ )
|
|
463
|
+ RoleApi(user).create_one(
|
|
464
|
+ user2,
|
|
465
|
+ workspace,
|
|
466
|
+ UserRoleInWorkspace.WORKSPACE_MANAGER,
|
|
467
|
+ with_notif=False
|
|
468
|
+ )
|
|
469
|
+ api = ContentApi(user)
|
|
470
|
+ foldera = api.create(
|
|
471
|
+ ContentType.Folder,
|
|
472
|
+ workspace,
|
|
473
|
+ None,
|
|
474
|
+ 'folder a',
|
|
475
|
+ True
|
|
476
|
+ )
|
|
477
|
+ with DBSession.no_autoflush:
|
|
478
|
+ text_file = api.create(
|
|
479
|
+ content_type=ContentType.File,
|
|
480
|
+ workspace=workspace,
|
|
481
|
+ parent=foldera,
|
|
482
|
+ label='test_file',
|
|
483
|
+ do_save=False,
|
|
484
|
+ )
|
|
485
|
+ api.update_file_data(
|
|
486
|
+ text_file,
|
|
487
|
+ 'test_file',
|
|
488
|
+ 'text/plain',
|
|
489
|
+ b'test_content'
|
|
490
|
+ )
|
|
491
|
+
|
|
492
|
+ api.save(text_file, ActionDescription.CREATION)
|
|
493
|
+ api2 = ContentApi(user2)
|
|
494
|
+ workspace2 = WorkspaceApi(user2).create_workspace(
|
|
495
|
+ 'test workspace2',
|
|
496
|
+ save_now=True
|
|
497
|
+ )
|
|
498
|
+ folderb = api2.create(
|
|
499
|
+ ContentType.Folder,
|
|
500
|
+ workspace2,
|
|
501
|
+ None,
|
|
502
|
+ 'folder b',
|
|
503
|
+ True
|
|
504
|
+ )
|
|
505
|
+ api2.copy(
|
|
506
|
+ item=text_file,
|
|
507
|
+ new_parent=folderb,
|
|
508
|
+ )
|
|
509
|
+
|
|
510
|
+ transaction.commit()
|
|
511
|
+ text_file_copy = api2.get_one_by_label_and_parent(
|
|
512
|
+ 'test_file',
|
|
513
|
+ folderb,
|
|
514
|
+ )
|
|
515
|
+
|
|
516
|
+ assert text_file != text_file_copy
|
|
517
|
+ assert text_file_copy.content_id != text_file.content_id
|
|
518
|
+ assert text_file_copy.workspace_id == workspace2.workspace_id
|
|
519
|
+ assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read() # nopep8
|
|
520
|
+ assert text_file_copy.depot_file.path != text_file.depot_file.path
|
|
521
|
+ assert text_file_copy.label == text_file.label
|
|
522
|
+ assert text_file_copy.type == text_file.type
|
|
523
|
+ assert text_file_copy.parent.content_id == folderb.content_id
|
|
524
|
+ assert text_file_copy.owner.user_id == user.user_id
|
|
525
|
+ assert text_file_copy.description == text_file.description
|
|
526
|
+ assert text_file_copy.file_extension == text_file.file_extension
|
|
527
|
+ assert text_file_copy.file_mimetype == text_file.file_mimetype
|
|
528
|
+ assert text_file_copy.revision_type == ActionDescription.COPY
|
|
529
|
+ assert len(text_file_copy.revisions) == len(text_file.revisions) + 1
|
|
530
|
+
|
|
531
|
+ def test_unit_copy_file_different_label_same_parent_ok(self):
|
|
532
|
+ uapi = UserApi(None)
|
|
533
|
+ groups = [
|
|
534
|
+ GroupApi(None).get_one(Group.TIM_USER),
|
|
535
|
+ GroupApi(None).get_one(Group.TIM_MANAGER),
|
|
536
|
+ GroupApi(None).get_one(Group.TIM_ADMIN),
|
|
537
|
+ ]
|
|
538
|
+
|
|
539
|
+ user = uapi.create_user(
|
|
540
|
+ email='user1@user',
|
|
541
|
+ groups=groups,
|
|
542
|
+ save_now=True,
|
|
543
|
+ )
|
|
544
|
+ user2 = uapi.create_user(
|
|
545
|
+ email='user2@user',
|
|
546
|
+ groups=groups,
|
|
547
|
+ save_now=True
|
|
548
|
+ )
|
|
549
|
+ workspace = WorkspaceApi(user).create_workspace(
|
|
550
|
+ 'test workspace',
|
|
551
|
+ save_now=True
|
|
552
|
+ )
|
|
553
|
+ RoleApi(user).create_one(
|
|
554
|
+ user2, workspace,
|
|
555
|
+ UserRoleInWorkspace.WORKSPACE_MANAGER,
|
|
556
|
+ with_notif=False
|
|
557
|
+ )
|
|
558
|
+ api = ContentApi(user)
|
|
559
|
+ foldera = api.create(
|
|
560
|
+ ContentType.Folder,
|
|
561
|
+ workspace,
|
|
562
|
+ None,
|
|
563
|
+ 'folder a',
|
|
564
|
+ True
|
|
565
|
+ )
|
|
566
|
+ with DBSession.no_autoflush:
|
|
567
|
+ text_file = api.create(
|
|
568
|
+ content_type=ContentType.File,
|
|
569
|
+ workspace=workspace,
|
|
570
|
+ parent=foldera,
|
|
571
|
+ label='test_file',
|
|
572
|
+ do_save=False,
|
|
573
|
+ )
|
|
574
|
+ api.update_file_data(
|
|
575
|
+ text_file,
|
|
576
|
+ 'test_file',
|
|
577
|
+ 'text/plain',
|
|
578
|
+ b'test_content'
|
|
579
|
+ )
|
|
580
|
+
|
|
581
|
+ api.save(
|
|
582
|
+ text_file,
|
|
583
|
+ ActionDescription.CREATION
|
|
584
|
+ )
|
|
585
|
+ api2 = ContentApi(user2)
|
|
586
|
+
|
|
587
|
+ api2.copy(
|
|
588
|
+ item=text_file,
|
|
589
|
+ new_label='test_file_copy'
|
|
590
|
+ )
|
|
591
|
+
|
|
592
|
+ transaction.commit()
|
|
593
|
+ text_file_copy = api2.get_one_by_label_and_parent(
|
|
594
|
+ 'test_file_copy',
|
|
595
|
+ foldera,
|
|
596
|
+ )
|
|
597
|
+
|
|
598
|
+ assert text_file != text_file_copy
|
|
599
|
+ assert text_file_copy.content_id != text_file.content_id
|
|
600
|
+ assert text_file_copy.workspace_id == workspace.workspace_id
|
|
601
|
+ assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read() # nopep8
|
|
602
|
+ assert text_file_copy.depot_file.path != text_file.depot_file.path
|
|
603
|
+ assert text_file_copy.label == 'test_file_copy'
|
|
604
|
+ assert text_file_copy.type == text_file.type
|
|
605
|
+ assert text_file_copy.parent.content_id == foldera.content_id
|
|
606
|
+ assert text_file_copy.owner.user_id == user.user_id
|
|
607
|
+ assert text_file_copy.description == text_file.description
|
|
608
|
+ assert text_file_copy.file_extension == text_file.file_extension
|
|
609
|
+ assert text_file_copy.file_mimetype == text_file.file_mimetype
|
|
610
|
+ assert text_file_copy.revision_type == ActionDescription.COPY
|
|
611
|
+ assert len(text_file_copy.revisions) == len(text_file.revisions) + 1
|
350
|
612
|
|
351
|
613
|
def test_mark_read__workspace(self):
|
352
|
614
|
uapi = UserApi(None)
|