|
@@ -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,250 @@ 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
|
+ text_file_copy = api2.get_one_by_label_and_parent(
|
|
423
|
+ 'test_file_copy',
|
|
424
|
+ folderb
|
|
425
|
+ )
|
|
426
|
+ assert text_file != text_file_copy
|
|
427
|
+ assert text_file_copy.content_id != text_file.content_id
|
|
428
|
+ assert text_file_copy.workspace == workspace2
|
|
429
|
+ assert text_file_copy.depot_file != text_file.depot_file
|
|
430
|
+ assert text_file_copy.label == 'test_file_copy'
|
|
431
|
+ assert text_file_copy.type == text_file.type
|
|
432
|
+ assert text_file_copy.parent == folderb
|
|
433
|
+ assert text_file_copy.owner == user2
|
|
434
|
+ assert text_file_copy.description == text_file.description
|
|
435
|
+ assert text_file_copy.file_extension == text_file.file_extension
|
|
436
|
+ assert text_file_copy.file_mimetype == text_file.file_mimetype
|
|
437
|
+
|
|
438
|
+ def test_unit_copy_file__same_label_different_parent_ok(self):
|
|
439
|
+ uapi = UserApi(None)
|
|
440
|
+ groups = [GroupApi(None).get_one(Group.TIM_USER),
|
|
441
|
+ GroupApi(None).get_one(Group.TIM_MANAGER),
|
|
442
|
+ GroupApi(None).get_one(Group.TIM_ADMIN)]
|
|
443
|
+
|
|
444
|
+ user = uapi.create_user(
|
|
445
|
+ email='user1@user',
|
|
446
|
+ groups=groups,
|
|
447
|
+ save_now=True
|
|
448
|
+ )
|
|
449
|
+ user2 = uapi.create_user(
|
|
450
|
+ email='user2@user',
|
|
451
|
+ groups=groups,
|
|
452
|
+ save_now=True
|
|
453
|
+ )
|
|
454
|
+ workspace = WorkspaceApi(user).create_workspace(
|
|
455
|
+ 'test workspace',
|
|
456
|
+ save_now=True
|
|
457
|
+ )
|
|
458
|
+ RoleApi(user).create_one(
|
|
459
|
+ user2,
|
|
460
|
+ workspace,
|
|
461
|
+ UserRoleInWorkspace.WORKSPACE_MANAGER,
|
|
462
|
+ with_notif=False
|
|
463
|
+ )
|
|
464
|
+ api = ContentApi(user)
|
|
465
|
+ foldera = api.create(
|
|
466
|
+ ContentType.Folder,
|
|
467
|
+ workspace,
|
|
468
|
+ None,
|
|
469
|
+ 'folder a',
|
|
470
|
+ True
|
|
471
|
+ )
|
|
472
|
+ with DBSession.no_autoflush:
|
|
473
|
+ text_file = api.create(
|
|
474
|
+ content_type=ContentType.File,
|
|
475
|
+ workspace=workspace,
|
|
476
|
+ parent=foldera,
|
|
477
|
+ label='test_file',
|
|
478
|
+ do_save=False,
|
|
479
|
+ )
|
|
480
|
+ api.update_file_data(
|
|
481
|
+ text_file,
|
|
482
|
+ 'test_file',
|
|
483
|
+ 'text/plain',
|
|
484
|
+ b'test_content'
|
|
485
|
+ )
|
|
486
|
+
|
|
487
|
+ api.save(text_file, ActionDescription.CREATION)
|
|
488
|
+ api2 = ContentApi(user2)
|
|
489
|
+ workspace2 = WorkspaceApi(user2).create_workspace(
|
|
490
|
+ 'test workspace2',
|
|
491
|
+ save_now=True
|
|
492
|
+ )
|
|
493
|
+ folderb = api2.create(
|
|
494
|
+ ContentType.Folder,
|
|
495
|
+ workspace2,
|
|
496
|
+ None,
|
|
497
|
+ 'folder b',
|
|
498
|
+ True
|
|
499
|
+ )
|
|
500
|
+
|
|
501
|
+ api2.copy(
|
|
502
|
+ item=text_file,
|
|
503
|
+ new_parent=folderb,
|
|
504
|
+ )
|
|
505
|
+
|
|
506
|
+ text_file_copy = api2.get_one_by_label_and_parent('test_file', folderb)
|
|
507
|
+ assert text_file != text_file_copy
|
|
508
|
+ assert text_file_copy.content_id != text_file.content_id
|
|
509
|
+ assert text_file_copy.workspace == workspace2
|
|
510
|
+ assert text_file_copy.depot_file != text_file.depot_file
|
|
511
|
+ assert text_file_copy.label == text_file.label
|
|
512
|
+ assert text_file_copy.type == text_file.type
|
|
513
|
+ assert text_file_copy.parent == folderb
|
|
514
|
+ assert text_file_copy.owner == user2
|
|
515
|
+ assert text_file_copy.description == text_file.description
|
|
516
|
+ assert text_file_copy.file_extension == text_file.file_extension
|
|
517
|
+ assert text_file_copy.file_mimetype == text_file.file_mimetype
|
|
518
|
+
|
|
519
|
+ def test_unit_copy_file_different_label_same_parent_ok(self):
|
|
520
|
+ uapi = UserApi(None)
|
|
521
|
+ groups = [
|
|
522
|
+ GroupApi(None).get_one(Group.TIM_USER),
|
|
523
|
+ GroupApi(None).get_one(Group.TIM_MANAGER),
|
|
524
|
+ GroupApi(None).get_one(Group.TIM_ADMIN),
|
|
525
|
+ ]
|
|
526
|
+
|
|
527
|
+ user = uapi.create_user(
|
|
528
|
+ email='user1@user',
|
|
529
|
+ groups=groups,
|
|
530
|
+ save_now=True,
|
|
531
|
+ )
|
|
532
|
+ user2 = uapi.create_user(
|
|
533
|
+ email='user2@user',
|
|
534
|
+ groups=groups,
|
|
535
|
+ save_now=True
|
|
536
|
+ )
|
|
537
|
+ workspace = WorkspaceApi(user).create_workspace(
|
|
538
|
+ 'test workspace',
|
|
539
|
+ save_now=True
|
|
540
|
+ )
|
|
541
|
+ RoleApi(user).create_one(
|
|
542
|
+ user2, workspace,
|
|
543
|
+ UserRoleInWorkspace.WORKSPACE_MANAGER,
|
|
544
|
+ with_notif=False
|
|
545
|
+ )
|
|
546
|
+ api = ContentApi(user)
|
|
547
|
+ foldera = api.create(
|
|
548
|
+ ContentType.Folder,
|
|
549
|
+ workspace,
|
|
550
|
+ None,
|
|
551
|
+ 'folder a',
|
|
552
|
+ True
|
|
553
|
+ )
|
|
554
|
+ with DBSession.no_autoflush:
|
|
555
|
+ text_file = api.create(
|
|
556
|
+ content_type=ContentType.File,
|
|
557
|
+ workspace=workspace,
|
|
558
|
+ parent=foldera,
|
|
559
|
+ label='test_file',
|
|
560
|
+ do_save=False,
|
|
561
|
+ )
|
|
562
|
+ api.update_file_data(
|
|
563
|
+ text_file,
|
|
564
|
+ 'test_file',
|
|
565
|
+ 'text/plain',
|
|
566
|
+ b'test_content'
|
|
567
|
+ )
|
|
568
|
+
|
|
569
|
+ api.save(
|
|
570
|
+ text_file,
|
|
571
|
+ ActionDescription.CREATION
|
|
572
|
+ )
|
|
573
|
+ api2 = ContentApi(user2)
|
|
574
|
+
|
|
575
|
+ api2.copy(
|
|
576
|
+ item=text_file,
|
|
577
|
+ new_label='test_file_copy'
|
|
578
|
+ )
|
|
579
|
+
|
|
580
|
+ text_file_copy = api2.get_one_by_label_and_parent(
|
|
581
|
+ 'test_file_copy',
|
|
582
|
+ foldera
|
|
583
|
+ )
|
|
584
|
+ assert text_file != text_file_copy
|
|
585
|
+ assert text_file_copy.content_id != text_file.content_id
|
|
586
|
+ assert text_file_copy.workspace == workspace
|
|
587
|
+ assert text_file_copy.depot_file != text_file.depot_file
|
|
588
|
+ assert text_file_copy.label == 'test_file_copy'
|
|
589
|
+ assert text_file_copy.type == text_file.type
|
|
590
|
+ assert text_file_copy.parent == foldera
|
|
591
|
+ assert text_file_copy.owner == user2
|
|
592
|
+ assert text_file_copy.description == text_file.description
|
|
593
|
+ assert text_file_copy.file_extension == text_file.file_extension
|
|
594
|
+ assert text_file_copy.file_mimetype == text_file.file_mimetype
|
350
|
595
|
|
351
|
596
|
def test_mark_read__workspace(self):
|
352
|
597
|
uapi = UserApi(None)
|