more test stuff
This commit is contained in:
@@ -1,38 +1,25 @@
|
||||
import unittest
|
||||
import shutil
|
||||
import os
|
||||
|
||||
from unittest.mock import Mock
|
||||
|
||||
from helpers.folder_helper import TEST_FOLDER
|
||||
from helpers.folder_helper import TEST_IMAGE_FOLDER
|
||||
from helpers.folder_helper import delete_folder
|
||||
from helpers.folder_helper import copy_test_images
|
||||
|
||||
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'))
|
||||
sort_pictures(images=exif_data, logger=Mock(), dst=TEST_IMAGE_FOLDER)
|
||||
sorted_pictures = recursive_scan_folder(TEST_FOLDER)
|
||||
delete_test_folder()
|
||||
delete_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']
|
||||
assert "".join(picture for picture in sorted_pictures if '2023/10/25/test_image_002.JPG' in picture) != ""
|
||||
assert "".join(picture for picture in sorted_pictures if '2023/10/28/test_image_001.JPG' in picture) != ""
|
||||
|
||||
Reference in New Issue
Block a user