Code Duplication    Length = 22-25 lines in 8 locations

elodie/tests/filesystem_test.py 8 locations

@@ 918-942 (lines=25) @@
915
    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
916
917
# gh-89 (setting album then title reverts album)
918
def test_process_video_with_album_then_title():
919
    filesystem = FileSystem()
920
    temporary_folder, folder = helper.create_working_folder()
921
922
    origin = os.path.join(folder,'movie.mov')
923
    shutil.copyfile(helper.get_file('video.mov'), origin)
924
925
    origin_checksum = helper.checksum(origin)
926
927
    origin_checksum_preprocess = helper.checksum(origin)
928
    media = Video(origin)
929
    media.set_album('test_album')
930
    media.set_title('test_title')
931
    destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
932
933
    destination_checksum = helper.checksum(destination)
934
935
    shutil.rmtree(folder)
936
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
937
938
    assert origin_checksum_preprocess is not None
939
    assert origin_checksum is not None
940
    assert destination_checksum is not None
941
    assert origin_checksum_preprocess == origin_checksum
942
    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
943
944
@mock.patch('elodie.config.config_file', '%s/config.ini-fallback-folder' % gettempdir())
945
def test_process_file_fallback_folder():
@@ 894-915 (lines=22) @@
891
    assert origin_checksum_preprocess == origin_checksum
892
    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
893
894
def test_process_file_with_album_and_title_and_location():
895
    filesystem = FileSystem()
896
    temporary_folder, folder = helper.create_working_folder()
897
898
    origin = os.path.join(folder,'photo.jpg')
899
    shutil.copyfile(helper.get_file('with-album-and-title-and-location.jpg'), origin)
900
901
    origin_checksum_preprocess = helper.checksum(origin)
902
    media = Photo(origin)
903
    destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
904
905
    origin_checksum = helper.checksum(origin)
906
    destination_checksum = helper.checksum(destination)
907
908
    shutil.rmtree(folder)
909
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
910
911
    assert origin_checksum_preprocess is not None
912
    assert origin_checksum is not None
913
    assert destination_checksum is not None
914
    assert origin_checksum_preprocess == origin_checksum
915
    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
916
917
# gh-89 (setting album then title reverts album)
918
def test_process_video_with_album_then_title():
@@ 871-892 (lines=22) @@
868
    assert origin_checksum_preprocess == origin_checksum
869
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Test Album','2015-12-05_00-59-26-photo.jpg')) in destination, destination
870
871
def test_process_file_with_album_and_title():
872
    filesystem = FileSystem()
873
    temporary_folder, folder = helper.create_working_folder()
874
875
    origin = os.path.join(folder,'photo.jpg')
876
    shutil.copyfile(helper.get_file('with-album-and-title.jpg'), origin)
877
878
    origin_checksum_preprocess = helper.checksum(origin)
879
    media = Photo(origin)
880
    destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
881
882
    origin_checksum = helper.checksum(origin)
883
    destination_checksum = helper.checksum(destination)
884
885
    shutil.rmtree(folder)
886
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
887
888
    assert origin_checksum_preprocess is not None
889
    assert origin_checksum is not None
890
    assert destination_checksum is not None
891
    assert origin_checksum_preprocess == origin_checksum
892
    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
893
894
def test_process_file_with_album_and_title_and_location():
895
    filesystem = FileSystem()
@@ 848-869 (lines=22) @@
845
    assert origin_checksum_preprocess == origin_checksum
846
    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
847
848
def test_process_file_with_album():
849
    filesystem = FileSystem()
850
    temporary_folder, folder = helper.create_working_folder()
851
852
    origin = os.path.join(folder,'photo.jpg')
853
    shutil.copyfile(helper.get_file('with-album.jpg'), origin)
854
855
    origin_checksum_preprocess = helper.checksum(origin)
856
    media = Photo(origin)
857
    destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
858
859
    origin_checksum = helper.checksum(origin)
860
    destination_checksum = helper.checksum(destination)
861
862
    shutil.rmtree(folder)
863
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
864
865
    assert origin_checksum_preprocess is not None
866
    assert origin_checksum is not None
867
    assert destination_checksum is not None
868
    assert origin_checksum_preprocess == origin_checksum
869
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Test Album','2015-12-05_00-59-26-photo.jpg')) in destination, destination
870
871
def test_process_file_with_album_and_title():
872
    filesystem = FileSystem()
@@ 825-846 (lines=22) @@
822
    assert '/2012-03-Mar/' in destination, destination
823
    assert '/2012-03-02_18-28-20' in destination, destination
824
825
def test_process_file_with_location_and_title():
826
    filesystem = FileSystem()
827
    temporary_folder, folder = helper.create_working_folder()
828
829
    origin = os.path.join(folder,'photo.jpg')
830
    shutil.copyfile(helper.get_file('with-location-and-title.jpg'), origin)
831
832
    origin_checksum_preprocess = helper.checksum(origin)
833
    media = Photo(origin)
834
    destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
835
836
    origin_checksum = helper.checksum(origin)
837
    destination_checksum = helper.checksum(destination)
838
839
    shutil.rmtree(folder)
840
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
841
842
    assert origin_checksum_preprocess is not None
843
    assert origin_checksum is not None
844
    assert destination_checksum is not None
845
    assert origin_checksum_preprocess == origin_checksum
846
    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
847
848
def test_process_file_with_album():
849
    filesystem = FileSystem()
@@ 756-777 (lines=22) @@
753
    assert origin_checksum_preprocess == origin_checksum
754
    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
755
756
def test_process_file_with_location():
757
    filesystem = FileSystem()
758
    temporary_folder, folder = helper.create_working_folder()
759
760
    origin = os.path.join(folder,'photo.jpg')
761
    shutil.copyfile(helper.get_file('with-location.jpg'), origin)
762
763
    origin_checksum_preprocess = helper.checksum(origin)
764
    media = Photo(origin)
765
    destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
766
767
    origin_checksum = helper.checksum(origin)
768
    destination_checksum = helper.checksum(destination)
769
770
    shutil.rmtree(folder)
771
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
772
773
    assert origin_checksum_preprocess is not None
774
    assert origin_checksum is not None
775
    assert destination_checksum is not None
776
    assert origin_checksum_preprocess == origin_checksum
777
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Sunnyvale','2015-12-05_00-59-26-photo.jpg')) in destination, destination
778
779
def test_process_file_validate_original_checksum():
780
    filesystem = FileSystem()
@@ 733-754 (lines=22) @@
730
    assert origin_checksum_preprocess == origin_checksum
731
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Unknown Location','2015-12-05_00-59-26-photo.jpg')) in destination, destination
732
733
def test_process_file_with_title():
734
    filesystem = FileSystem()
735
    temporary_folder, folder = helper.create_working_folder()
736
737
    origin = '%s/photo.jpg' % folder
738
    shutil.copyfile(helper.get_file('with-title.jpg'), origin)
739
740
    origin_checksum_preprocess = helper.checksum(origin)
741
    media = Photo(origin)
742
    destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
743
744
    origin_checksum = helper.checksum(origin)
745
    destination_checksum = helper.checksum(destination)
746
747
    shutil.rmtree(folder)
748
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
749
750
    assert origin_checksum_preprocess is not None
751
    assert origin_checksum is not None
752
    assert destination_checksum is not None
753
    assert origin_checksum_preprocess == origin_checksum
754
    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
755
756
def test_process_file_with_location():
757
    filesystem = FileSystem()
@@ 710-731 (lines=22) @@
707
708
    assert destination is None
709
710
def test_process_file_plain():
711
    filesystem = FileSystem()
712
    temporary_folder, folder = helper.create_working_folder()
713
714
    origin = os.path.join(folder,'photo.jpg')
715
    shutil.copyfile(helper.get_file('plain.jpg'), origin)
716
717
    origin_checksum_preprocess = helper.checksum(origin)
718
    media = Photo(origin)
719
    destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
720
721
    origin_checksum = helper.checksum(origin)
722
    destination_checksum = helper.checksum(destination)
723
724
    shutil.rmtree(folder)
725
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
726
727
    assert origin_checksum_preprocess is not None
728
    assert origin_checksum is not None
729
    assert destination_checksum is not None
730
    assert origin_checksum_preprocess == origin_checksum
731
    assert helper.path_tz_fix(os.path.join('2015-12-Dec','Unknown Location','2015-12-05_00-59-26-photo.jpg')) in destination, destination
732
733
def test_process_file_with_title():
734
    filesystem = FileSystem()