Code Duplication    Length = 13-26 lines in 9 locations

elodie/tests/filesystem_test.py 9 locations

@@ 459-484 (lines=26) @@
456
457
    assert path == '2015-12-Dec Test Album', path
458
459
@mock.patch('elodie.config.config_file', '%s/config.ini-combined-date-album-location-fallback' % gettempdir())
460
def test_get_folder_path_with_album_and_location_fallback():
461
    # gh-279
462
    with open('%s/config.ini-combined-date-album-location-fallback' % gettempdir(), 'w') as f:
463
        f.write("""
464
[Directory]
465
date=%Y-%m-%b
466
custom=%album
467
full_path=%custom|%city
468
        """)
469
    if hasattr(load_config, 'config'):
470
        del load_config.config
471
    filesystem = FileSystem()
472
473
    # Test with no location
474
    media = Photo(helper.get_file('plain.jpg'))
475
    path_plain = filesystem.get_folder_path(media.get_metadata())
476
477
    # Test with City
478
    media = Photo(helper.get_file('with-location.jpg'))
479
    path_city = filesystem.get_folder_path(media.get_metadata())
480
    if hasattr(load_config, 'config'):
481
        del load_config.config
482
483
    assert path_plain == 'Unknown Location', path_plain
484
    assert path_city == 'Sunnyvale', path_city
485
486
487
def test_get_folder_path_with_int_in_source_path():
@@ 556-579 (lines=24) @@
553
554
    assert path == os.path.join('2015','12','No Album Fool','12'), path
555
556
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
557
def test_get_folder_path_with_with_more_than_two_levels():
558
    with open('%s/config.ini-location-date' % gettempdir(), 'w') as f:
559
        f.write("""
560
[MapQuest]
561
key=czjNKTtFjLydLteUBwdgKAIC8OAbGLUx
562
563
[Directory]
564
year=%Y
565
month=%m
566
location=%city, %state
567
full_path=%year/%month/%location
568
        """)
569
570
    if hasattr(load_config, 'config'):
571
        del load_config.config
572
573
    filesystem = FileSystem()
574
    media = Photo(helper.get_file('with-location.jpg'))
575
    path = filesystem.get_folder_path(media.get_metadata())
576
    if hasattr(load_config, 'config'):
577
        del load_config.config
578
579
    assert path == os.path.join('2015','12','Sunnyvale, California'), path
580
581
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
582
def test_get_folder_path_with_with_only_one_level():
@@ 514-534 (lines=21) @@
511
512
    assert path == os.path.join('2015-12-Dec','Unknown Location'), path
513
514
@mock.patch('elodie.config.config_file', '%s/config.ini-custom-path' % gettempdir())
515
def test_get_folder_path_with_custom_path():
516
    with open('%s/config.ini-custom-path' % gettempdir(), 'w') as f:
517
        f.write("""
518
[MapQuest]
519
key=czjNKTtFjLydLteUBwdgKAIC8OAbGLUx
520
521
[Directory]
522
date=%Y-%m-%d
523
location=%country-%state-%city
524
full_path=%date/%location
525
        """)
526
    if hasattr(load_config, 'config'):
527
        del load_config.config
528
    filesystem = FileSystem()
529
    media = Photo(helper.get_file('with-location.jpg'))
530
    path = filesystem.get_folder_path(media.get_metadata())
531
    if hasattr(load_config, 'config'):
532
        del load_config.config
533
534
    assert path == os.path.join('2015-12-05','United States of America-California-Sunnyvale'), path
535
536
@mock.patch('elodie.config.config_file', '%s/config.ini-fallback' % gettempdir())
537
def test_get_folder_path_with_fallback_folder():
@@ 581-599 (lines=19) @@
578
579
    assert path == os.path.join('2015','12','Sunnyvale, California'), path
580
581
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
582
def test_get_folder_path_with_with_only_one_level():
583
    with open('%s/config.ini-location-date' % gettempdir(), 'w') as f:
584
        f.write("""
585
[Directory]
586
year=%Y
587
full_path=%year
588
        """)
589
590
    if hasattr(load_config, 'config'):
591
        del load_config.config
592
593
    filesystem = FileSystem()
594
    media = Photo(helper.get_file('plain.jpg'))
595
    path = filesystem.get_folder_path(media.get_metadata())
596
    if hasattr(load_config, 'config'):
597
        del load_config.config
598
599
    assert path == os.path.join('2015'), path
600
601
def test_get_folder_path_with_location_and_title():
602
    filesystem = FileSystem()
@@ 536-554 (lines=19) @@
533
534
    assert path == os.path.join('2015-12-05','United States of America-California-Sunnyvale'), path
535
536
@mock.patch('elodie.config.config_file', '%s/config.ini-fallback' % gettempdir())
537
def test_get_folder_path_with_fallback_folder():
538
    with open('%s/config.ini-fallback' % gettempdir(), 'w') as f:
539
        f.write("""
540
[Directory]
541
year=%Y
542
month=%m
543
full_path=%year/%month/%album|%"No Album Fool"/%month
544
        """)
545
#full_path=%year/%album|"No Album"
546
    if hasattr(load_config, 'config'):
547
        del load_config.config
548
    filesystem = FileSystem()
549
    media = Photo(helper.get_file('plain.jpg'))
550
    path = filesystem.get_folder_path(media.get_metadata())
551
    if hasattr(load_config, 'config'):
552
        del load_config.config
553
554
    assert path == os.path.join('2015','12','No Album Fool','12'), path
555
556
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
557
def test_get_folder_path_with_with_more_than_two_levels():
@@ 420-437 (lines=18) @@
417
418
    assert path == os.path.join('nomake', 'nomodel'), path
419
420
@mock.patch('elodie.config.config_file', '%s/config.ini-int-in-component-path' % gettempdir())
421
def test_get_folder_path_with_int_in_config_component():
422
    # gh-239
423
    with open('%s/config.ini-int-in-component-path' % gettempdir(), 'w') as f:
424
        f.write("""
425
[Directory]
426
date=%Y
427
full_path=%date
428
        """)
429
    if hasattr(load_config, 'config'):
430
        del load_config.config
431
    filesystem = FileSystem()
432
    media = Photo(helper.get_file('plain.jpg'))
433
    path = filesystem.get_folder_path(media.get_metadata())
434
    if hasattr(load_config, 'config'):
435
        del load_config.config
436
437
    assert path == os.path.join('2015'), path
438
439
@mock.patch('elodie.config.config_file', '%s/config.ini-combined-date-and-album' % gettempdir())
440
def test_get_folder_path_with_combined_date_and_album():
@@ 403-418 (lines=16) @@
400
401
    assert path == os.path.join('Canon', 'Canon EOS REBEL T2i'), path
402
403
@mock.patch('elodie.config.config_file', '%s/config.ini-original-with-camera-make-and-model-fallback' % gettempdir())
404
def test_get_folder_path_with_camera_make_and_model_fallback():
405
    with open('%s/config.ini-original-with-camera-make-and-model-fallback' % gettempdir(), 'w') as f:
406
        f.write("""
407
[Directory]
408
full_path=%camera_make|"nomake"/%camera_model|"nomodel"
409
        """)
410
    if hasattr(load_config, 'config'):
411
        del load_config.config
412
    filesystem = FileSystem()
413
    media = Photo(helper.get_file('no-exif.jpg'))
414
    path = filesystem.get_folder_path(media.get_metadata())
415
    if hasattr(load_config, 'config'):
416
        del load_config.config
417
418
    assert path == os.path.join('nomake', 'nomodel'), path
419
420
@mock.patch('elodie.config.config_file', '%s/config.ini-int-in-component-path' % gettempdir())
421
def test_get_folder_path_with_int_in_config_component():
@@ 386-401 (lines=16) @@
383
384
    assert path == os.path.join('2015-12-Dec','Sunnyvale'), path
385
386
@mock.patch('elodie.config.config_file', '%s/config.ini-original-with-camera-make-and-model' % gettempdir())
387
def test_get_folder_path_with_camera_make_and_model():
388
    with open('%s/config.ini-original-with-camera-make-and-model' % gettempdir(), 'w') as f:
389
        f.write("""
390
[Directory]
391
full_path=%camera_make/%camera_model
392
        """)
393
    if hasattr(load_config, 'config'):
394
        del load_config.config
395
    filesystem = FileSystem()
396
    media = Photo(helper.get_file('plain.jpg'))
397
    path = filesystem.get_folder_path(media.get_metadata())
398
    if hasattr(load_config, 'config'):
399
        del load_config.config
400
401
    assert path == os.path.join('Canon', 'Canon EOS REBEL T2i'), path
402
403
@mock.patch('elodie.config.config_file', '%s/config.ini-original-with-camera-make-and-model-fallback' % gettempdir())
404
def test_get_folder_path_with_camera_make_and_model_fallback():
@@ 500-512 (lines=13) @@
497
498
    assert path == os.path.join('2015-12-Dec','Unknown Location'), path
499
500
@mock.patch('elodie.config.config_file', '%s/config.ini-original-default-unknown-location' % gettempdir())
501
def test_get_folder_path_with_original_default_unknown_location():
502
    with open('%s/config.ini-original-default-with-unknown-location' % gettempdir(), 'w') as f:
503
        f.write('')
504
    if hasattr(load_config, 'config'):
505
        del load_config.config
506
    filesystem = FileSystem()
507
    media = Photo(helper.get_file('plain.jpg'))
508
    path = filesystem.get_folder_path(media.get_metadata())
509
    if hasattr(load_config, 'config'):
510
        del load_config.config
511
512
    assert path == os.path.join('2015-12-Dec','Unknown Location'), path
513
514
@mock.patch('elodie.config.config_file', '%s/config.ini-custom-path' % gettempdir())
515
def test_get_folder_path_with_custom_path():