Code Duplication    Length = 22-25 lines in 8 locations

elodie/tests/filesystem_test.py 8 locations

@@ 820-844 (lines=25) @@
817
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Test Album','2015-12-05_00-59-26-photo-some-title.jpg')) in destination, destination
818
819
# gh-89 (setting album then title reverts album)
820
def test_process_video_with_album_then_title():
821
    filesystem = FileSystem()
822
    temporary_folder, folder = helper.create_working_folder()
823
824
    origin = os.path.join(folder,'movie.mov')
825
    shutil.copyfile(helper.get_file('video.mov'), origin)
826
827
    origin_checksum = helper.checksum(origin)
828
829
    origin_checksum_preprocess = helper.checksum(origin)
830
    media = Video(origin)
831
    media.set_album('test_album')
832
    media.set_title('test_title')
833
    destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
834
835
    destination_checksum = helper.checksum(destination)
836
837
    shutil.rmtree(folder)
838
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
839
840
    assert origin_checksum_preprocess is not None
841
    assert origin_checksum is not None
842
    assert destination_checksum is not None
843
    assert origin_checksum_preprocess == origin_checksum
844
    assert helper.path_tz_fix(os.path.join('2015-01-Jan','test_album','2015-01-19_12-45-11-movie-test_title.mov')) in destination, destination
845
846
@mock.patch('elodie.config.config_file', '%s/config.ini-fallback-folder' % gettempdir())
847
def test_process_file_fallback_folder():
@@ 796-817 (lines=22) @@
793
    assert origin_checksum_preprocess == origin_checksum
794
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Test Album','2015-12-05_00-59-26-photo-some-title.jpg')) in destination, destination
795
796
def test_process_file_with_album_and_title_and_location():
797
    filesystem = FileSystem()
798
    temporary_folder, folder = helper.create_working_folder()
799
800
    origin = os.path.join(folder,'photo.jpg')
801
    shutil.copyfile(helper.get_file('with-album-and-title-and-location.jpg'), origin)
802
803
    origin_checksum_preprocess = helper.checksum(origin)
804
    media = Photo(origin)
805
    destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
806
807
    origin_checksum = helper.checksum(origin)
808
    destination_checksum = helper.checksum(destination)
809
810
    shutil.rmtree(folder)
811
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
812
813
    assert origin_checksum_preprocess is not None
814
    assert origin_checksum is not None
815
    assert destination_checksum is not None
816
    assert origin_checksum_preprocess == origin_checksum
817
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Test Album','2015-12-05_00-59-26-photo-some-title.jpg')) in destination, destination
818
819
# gh-89 (setting album then title reverts album)
820
def test_process_video_with_album_then_title():
@@ 773-794 (lines=22) @@
770
    assert origin_checksum_preprocess == origin_checksum
771
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Test Album','2015-12-05_00-59-26-photo.jpg')) in destination, destination
772
773
def test_process_file_with_album_and_title():
774
    filesystem = FileSystem()
775
    temporary_folder, folder = helper.create_working_folder()
776
777
    origin = os.path.join(folder,'photo.jpg')
778
    shutil.copyfile(helper.get_file('with-album-and-title.jpg'), origin)
779
780
    origin_checksum_preprocess = helper.checksum(origin)
781
    media = Photo(origin)
782
    destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
783
784
    origin_checksum = helper.checksum(origin)
785
    destination_checksum = helper.checksum(destination)
786
787
    shutil.rmtree(folder)
788
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
789
790
    assert origin_checksum_preprocess is not None
791
    assert origin_checksum is not None
792
    assert destination_checksum is not None
793
    assert origin_checksum_preprocess == origin_checksum
794
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Test Album','2015-12-05_00-59-26-photo-some-title.jpg')) in destination, destination
795
796
def test_process_file_with_album_and_title_and_location():
797
    filesystem = FileSystem()
@@ 750-771 (lines=22) @@
747
    assert origin_checksum_preprocess == origin_checksum
748
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Sunnyvale','2015-12-05_00-59-26-photo-some-title.jpg')) in destination, destination
749
750
def test_process_file_with_album():
751
    filesystem = FileSystem()
752
    temporary_folder, folder = helper.create_working_folder()
753
754
    origin = os.path.join(folder,'photo.jpg')
755
    shutil.copyfile(helper.get_file('with-album.jpg'), origin)
756
757
    origin_checksum_preprocess = helper.checksum(origin)
758
    media = Photo(origin)
759
    destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
760
761
    origin_checksum = helper.checksum(origin)
762
    destination_checksum = helper.checksum(destination)
763
764
    shutil.rmtree(folder)
765
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
766
767
    assert origin_checksum_preprocess is not None
768
    assert origin_checksum is not None
769
    assert destination_checksum is not None
770
    assert origin_checksum_preprocess == origin_checksum
771
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Test Album','2015-12-05_00-59-26-photo.jpg')) in destination, destination
772
773
def test_process_file_with_album_and_title():
774
    filesystem = FileSystem()
@@ 727-748 (lines=22) @@
724
    assert origin_checksum_preprocess == origin_checksum, (origin_checksum_preprocess, origin_checksum)
725
726
727
def test_process_file_with_location_and_title():
728
    filesystem = FileSystem()
729
    temporary_folder, folder = helper.create_working_folder()
730
731
    origin = os.path.join(folder,'photo.jpg')
732
    shutil.copyfile(helper.get_file('with-location-and-title.jpg'), origin)
733
734
    origin_checksum_preprocess = helper.checksum(origin)
735
    media = Photo(origin)
736
    destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
737
738
    origin_checksum = helper.checksum(origin)
739
    destination_checksum = helper.checksum(destination)
740
741
    shutil.rmtree(folder)
742
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
743
744
    assert origin_checksum_preprocess is not None
745
    assert origin_checksum is not None
746
    assert destination_checksum is not None
747
    assert origin_checksum_preprocess == origin_checksum
748
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Sunnyvale','2015-12-05_00-59-26-photo-some-title.jpg')) in destination, destination
749
750
def test_process_file_with_album():
751
    filesystem = FileSystem()
@@ 681-702 (lines=22) @@
678
    assert origin_checksum_preprocess == origin_checksum
679
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Unknown Location','2015-12-05_00-59-26-photo-some-title.jpg')) in destination, destination
680
681
def test_process_file_with_location():
682
    filesystem = FileSystem()
683
    temporary_folder, folder = helper.create_working_folder()
684
685
    origin = os.path.join(folder,'photo.jpg')
686
    shutil.copyfile(helper.get_file('with-location.jpg'), origin)
687
688
    origin_checksum_preprocess = helper.checksum(origin)
689
    media = Photo(origin)
690
    destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
691
692
    origin_checksum = helper.checksum(origin)
693
    destination_checksum = helper.checksum(destination)
694
695
    shutil.rmtree(folder)
696
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
697
698
    assert origin_checksum_preprocess is not None
699
    assert origin_checksum is not None
700
    assert destination_checksum is not None
701
    assert origin_checksum_preprocess == origin_checksum
702
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Sunnyvale','2015-12-05_00-59-26-photo.jpg')) in destination, destination
703
704
def test_process_file_validate_original_checksum():
705
    filesystem = FileSystem()
@@ 658-679 (lines=22) @@
655
    assert origin_checksum_preprocess == origin_checksum
656
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Unknown Location','2015-12-05_00-59-26-photo.jpg')) in destination, destination
657
658
def test_process_file_with_title():
659
    filesystem = FileSystem()
660
    temporary_folder, folder = helper.create_working_folder()
661
662
    origin = '%s/photo.jpg' % folder
663
    shutil.copyfile(helper.get_file('with-title.jpg'), origin)
664
665
    origin_checksum_preprocess = helper.checksum(origin)
666
    media = Photo(origin)
667
    destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
668
669
    origin_checksum = helper.checksum(origin)
670
    destination_checksum = helper.checksum(destination)
671
672
    shutil.rmtree(folder)
673
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
674
675
    assert origin_checksum_preprocess is not None
676
    assert origin_checksum is not None
677
    assert destination_checksum is not None
678
    assert origin_checksum_preprocess == origin_checksum
679
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Unknown Location','2015-12-05_00-59-26-photo-some-title.jpg')) in destination, destination
680
681
def test_process_file_with_location():
682
    filesystem = FileSystem()
@@ 635-656 (lines=22) @@
632
633
    assert destination is None
634
635
def test_process_file_plain():
636
    filesystem = FileSystem()
637
    temporary_folder, folder = helper.create_working_folder()
638
639
    origin = os.path.join(folder,'photo.jpg')
640
    shutil.copyfile(helper.get_file('plain.jpg'), origin)
641
642
    origin_checksum_preprocess = helper.checksum(origin)
643
    media = Photo(origin)
644
    destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
645
646
    origin_checksum = helper.checksum(origin)
647
    destination_checksum = helper.checksum(destination)
648
649
    shutil.rmtree(folder)
650
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
651
652
    assert origin_checksum_preprocess is not None
653
    assert origin_checksum is not None
654
    assert destination_checksum is not None
655
    assert origin_checksum_preprocess == origin_checksum
656
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Unknown Location','2015-12-05_00-59-26-photo.jpg')) in destination, destination
657
658
def test_process_file_with_title():
659
    filesystem = FileSystem()