39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
import unittest
|
|
import shutil
|
|
import os
|
|
|
|
from unittest.mock import Mock
|
|
|
|
from src.file_handler import sort_pictures
|
|
from src.scan_folder import recursive_scan_folder
|
|
from src.meta_data_handler import get_meta_data
|
|
|
|
TEST_IMAGES = "tests/test_files"
|
|
TEST_FOLDER = ".test_folder"
|
|
|
|
|
|
def delete_test_folder():
|
|
shutil.rmtree(TEST_FOLDER, ignore_errors=True)
|
|
|
|
|
|
def copy_test_images():
|
|
delete_test_folder()
|
|
os.makedirs(os.path.join(TEST_FOLDER, 'Temp'))
|
|
os.makedirs(os.path.join(TEST_FOLDER, 'Images'))
|
|
shutil.copy(src=os.path.join(TEST_IMAGES, 'test_image_001.JPG'), dst=os.path.join(TEST_FOLDER, 'Temp'))
|
|
shutil.copy(src=os.path.join(TEST_IMAGES, 'test_image_002.JPG'), dst=os.path.join(TEST_FOLDER, 'Temp'))
|
|
|
|
|
|
class TestFileHandler(unittest.TestCase):
|
|
def test_file_handler(self):
|
|
copy_test_images()
|
|
files = recursive_scan_folder(TEST_FOLDER)
|
|
exif_data = get_meta_data(files)
|
|
sort_pictures(images=exif_data, logger=Mock(), dst=os.path.join(TEST_FOLDER, 'Images'))
|
|
sorted_pictures = recursive_scan_folder(TEST_FOLDER)
|
|
delete_test_folder()
|
|
|
|
assert len(sorted_pictures) == 2
|
|
assert sorted_pictures == ['.test_folder/Images/SONY/2023/10/25/test_image_002.JPG',
|
|
'.test_folder/Images/SONY/2023/10/28/test_image_001.JPG']
|