Code Duplication    Length = 13-26 lines in 9 locations

elodie/tests/filesystem_test.py 9 locations

@@ 396-421 (lines=26) @@
393
394
    assert path == '2015-12-Dec Test Album', path
395
396
@mock.patch('elodie.config.config_file', '%s/config.ini-combined-date-album-location-fallback' % gettempdir())
397
def test_get_folder_path_with_album_and_location_fallback():
398
    # gh-279
399
    with open('%s/config.ini-combined-date-album-location-fallback' % gettempdir(), 'w') as f:
400
        f.write("""
401
[Directory]
402
date=%Y-%m-%b
403
custom=%album
404
full_path=%custom|%city
405
        """)
406
    if hasattr(load_config, 'config'):
407
        del load_config.config
408
    filesystem = FileSystem()
409
410
    # Test with no location
411
    media = Photo(helper.get_file('plain.jpg'))
412
    path_plain = filesystem.get_folder_path(media.get_metadata())
413
414
    # Test with City
415
    media = Photo(helper.get_file('with-location.jpg'))
416
    path_city = filesystem.get_folder_path(media.get_metadata())
417
    if hasattr(load_config, 'config'):
418
        del load_config.config
419
420
    assert path_plain == 'Unknown Location', path_plain
421
    assert path_city == 'Sunnyvale', path_city
422
423
424
def test_get_folder_path_with_int_in_source_path():
@@ 493-516 (lines=24) @@
490
491
    assert path == os.path.join('2015','12','No Album Fool','12'), path
492
493
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
494
def test_get_folder_path_with_with_more_than_two_levels():
495
    with open('%s/config.ini-location-date' % gettempdir(), 'w') as f:
496
        f.write("""
497
[MapQuest]
498
key=czjNKTtFjLydLteUBwdgKAIC8OAbGLUx
499
500
[Directory]
501
year=%Y
502
month=%m
503
location=%city, %state
504
full_path=%year/%month/%location
505
        """)
506
507
    if hasattr(load_config, 'config'):
508
        del load_config.config
509
510
    filesystem = FileSystem()
511
    media = Photo(helper.get_file('with-location.jpg'))
512
    path = filesystem.get_folder_path(media.get_metadata())
513
    if hasattr(load_config, 'config'):
514
        del load_config.config
515
516
    assert path == os.path.join('2015','12','Sunnyvale, California'), path
517
518
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
519
def test_get_folder_path_with_with_only_one_level():
@@ 451-471 (lines=21) @@
448
449
    assert path == os.path.join('2015-12-Dec','Unknown Location'), path
450
451
@mock.patch('elodie.config.config_file', '%s/config.ini-custom-path' % gettempdir())
452
def test_get_folder_path_with_custom_path():
453
    with open('%s/config.ini-custom-path' % gettempdir(), 'w') as f:
454
        f.write("""
455
[MapQuest]
456
key=czjNKTtFjLydLteUBwdgKAIC8OAbGLUx
457
458
[Directory]
459
date=%Y-%m-%d
460
location=%country-%state-%city
461
full_path=%date/%location
462
        """)
463
    if hasattr(load_config, 'config'):
464
        del load_config.config
465
    filesystem = FileSystem()
466
    media = Photo(helper.get_file('with-location.jpg'))
467
    path = filesystem.get_folder_path(media.get_metadata())
468
    if hasattr(load_config, 'config'):
469
        del load_config.config
470
471
    assert path == os.path.join('2015-12-05','United States of America-California-Sunnyvale'), path
472
473
@mock.patch('elodie.config.config_file', '%s/config.ini-fallback' % gettempdir())
474
def test_get_folder_path_with_fallback_folder():
@@ 518-536 (lines=19) @@
515
516
    assert path == os.path.join('2015','12','Sunnyvale, California'), path
517
518
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
519
def test_get_folder_path_with_with_only_one_level():
520
    with open('%s/config.ini-location-date' % gettempdir(), 'w') as f:
521
        f.write("""
522
[Directory]
523
year=%Y
524
full_path=%year
525
        """)
526
527
    if hasattr(load_config, 'config'):
528
        del load_config.config
529
530
    filesystem = FileSystem()
531
    media = Photo(helper.get_file('plain.jpg'))
532
    path = filesystem.get_folder_path(media.get_metadata())
533
    if hasattr(load_config, 'config'):
534
        del load_config.config
535
536
    assert path == os.path.join('2015'), path
537
538
def test_get_folder_path_with_location_and_title():
539
    filesystem = FileSystem()
@@ 473-491 (lines=19) @@
470
471
    assert path == os.path.join('2015-12-05','United States of America-California-Sunnyvale'), path
472
473
@mock.patch('elodie.config.config_file', '%s/config.ini-fallback' % gettempdir())
474
def test_get_folder_path_with_fallback_folder():
475
    with open('%s/config.ini-fallback' % gettempdir(), 'w') as f:
476
        f.write("""
477
[Directory]
478
year=%Y
479
month=%m
480
full_path=%year/%month/%album|%"No Album Fool"/%month
481
        """)
482
#full_path=%year/%album|"No Album"
483
    if hasattr(load_config, 'config'):
484
        del load_config.config
485
    filesystem = FileSystem()
486
    media = Photo(helper.get_file('plain.jpg'))
487
    path = filesystem.get_folder_path(media.get_metadata())
488
    if hasattr(load_config, 'config'):
489
        del load_config.config
490
491
    assert path == os.path.join('2015','12','No Album Fool','12'), path
492
493
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
494
def test_get_folder_path_with_with_more_than_two_levels():
@@ 357-374 (lines=18) @@
354
355
    assert path == os.path.join('nomake', 'nomodel'), path
356
357
@mock.patch('elodie.config.config_file', '%s/config.ini-int-in-component-path' % gettempdir())
358
def test_get_folder_path_with_int_in_config_component():
359
    # gh-239
360
    with open('%s/config.ini-int-in-component-path' % gettempdir(), 'w') as f:
361
        f.write("""
362
[Directory]
363
date=%Y
364
full_path=%date
365
        """)
366
    if hasattr(load_config, 'config'):
367
        del load_config.config
368
    filesystem = FileSystem()
369
    media = Photo(helper.get_file('plain.jpg'))
370
    path = filesystem.get_folder_path(media.get_metadata())
371
    if hasattr(load_config, 'config'):
372
        del load_config.config
373
374
    assert path == os.path.join('2015'), path
375
376
@mock.patch('elodie.config.config_file', '%s/config.ini-combined-date-and-album' % gettempdir())
377
def test_get_folder_path_with_combined_date_and_album():
@@ 340-355 (lines=16) @@
337
338
    assert path == os.path.join('Canon', 'Canon EOS REBEL T2i'), path
339
340
@mock.patch('elodie.config.config_file', '%s/config.ini-original-with-camera-make-and-model-fallback' % gettempdir())
341
def test_get_folder_path_with_camera_make_and_model_fallback():
342
    with open('%s/config.ini-original-with-camera-make-and-model-fallback' % gettempdir(), 'w') as f:
343
        f.write("""
344
[Directory]
345
full_path=%camera_make|"nomake"/%camera_model|"nomodel"
346
        """)
347
    if hasattr(load_config, 'config'):
348
        del load_config.config
349
    filesystem = FileSystem()
350
    media = Photo(helper.get_file('no-exif.jpg'))
351
    path = filesystem.get_folder_path(media.get_metadata())
352
    if hasattr(load_config, 'config'):
353
        del load_config.config
354
355
    assert path == os.path.join('nomake', 'nomodel'), path
356
357
@mock.patch('elodie.config.config_file', '%s/config.ini-int-in-component-path' % gettempdir())
358
def test_get_folder_path_with_int_in_config_component():
@@ 323-338 (lines=16) @@
320
321
    assert path == os.path.join('2015-12-Dec','Sunnyvale'), path
322
323
@mock.patch('elodie.config.config_file', '%s/config.ini-original-with-camera-make-and-model' % gettempdir())
324
def test_get_folder_path_with_camera_make_and_model():
325
    with open('%s/config.ini-original-with-camera-make-and-model' % gettempdir(), 'w') as f:
326
        f.write("""
327
[Directory]
328
full_path=%camera_make/%camera_model
329
        """)
330
    if hasattr(load_config, 'config'):
331
        del load_config.config
332
    filesystem = FileSystem()
333
    media = Photo(helper.get_file('plain.jpg'))
334
    path = filesystem.get_folder_path(media.get_metadata())
335
    if hasattr(load_config, 'config'):
336
        del load_config.config
337
338
    assert path == os.path.join('Canon', 'Canon EOS REBEL T2i'), path
339
340
@mock.patch('elodie.config.config_file', '%s/config.ini-original-with-camera-make-and-model-fallback' % gettempdir())
341
def test_get_folder_path_with_camera_make_and_model_fallback():
@@ 437-449 (lines=13) @@
434
435
    assert path == os.path.join('2015-12-Dec','Unknown Location'), path
436
437
@mock.patch('elodie.config.config_file', '%s/config.ini-original-default-unknown-location' % gettempdir())
438
def test_get_folder_path_with_original_default_unknown_location():
439
    with open('%s/config.ini-original-default-with-unknown-location' % gettempdir(), 'w') as f:
440
        f.write('')
441
    if hasattr(load_config, 'config'):
442
        del load_config.config
443
    filesystem = FileSystem()
444
    media = Photo(helper.get_file('plain.jpg'))
445
    path = filesystem.get_folder_path(media.get_metadata())
446
    if hasattr(load_config, 'config'):
447
        del load_config.config
448
449
    assert path == os.path.join('2015-12-Dec','Unknown Location'), path
450
451
@mock.patch('elodie.config.config_file', '%s/config.ini-custom-path' % gettempdir())
452
def test_get_folder_path_with_custom_path():