def test_generate_images_data(self, input): with TempDirectory() as tempdir: helpers.create_mock_image(os.path.join(tempdir.path, 'photo.jpg'), 1000, 500) # Init files gallery logic gallery_config = helpers.init_gallery_and_read_gallery_config( tempdir.path) file_gallery_logic = FilesGalleryLogic(gallery_config) # Check images_data generated correctly file_gallery_logic.create_thumbnails() images_data = file_gallery_logic.generate_images_data({}) self.assertEqual(1, len(images_data)) helpers.check_image_data(self, images_data, 'photo.jpg', '', (1000, 500), (320, 160), local_files=True) # Change a description, add a new image and check description of the first is preserved images_data['photo.jpg']['description'] = 'Test description' helpers.create_mock_image( os.path.join(tempdir.path, 'public', 'images', 'photos', 'photo2.jpg'), 1000, 500) file_gallery_logic.create_thumbnails() images_data = file_gallery_logic.generate_images_data(images_data) self.assertEqual(2, len(images_data)) helpers.check_image_data(self, images_data, 'photo.jpg', 'Test description', (1000, 500), (320, 160), local_files=True)
def test_generate_images_data(self, input): with TempDirectory() as tempdir: # Init files gallery logic gallery_config = helpers.init_gallery_and_read_gallery_config( tempdir.path, self.remote_link) file_gallery_logic = GoogleGalleryLogic(gallery_config) # Check images_data generated correctly file_gallery_logic.create_thumbnails() images_data = file_gallery_logic.generate_images_data({}) self.assertEqual(2, len(images_data)) helpers.check_image_data( self, images_data, "tGPJDmxLbrr9BTX_IHjh_MH1gJ7JhlcBnMBXPgWQslNLQSUjKGFdYd3TqTqTsGsYkpOJakSgcB05yB9aZJQ03JvRxHRLC0R0W4pYfbV2hXPlAgLHxIy1izHbhdWtrj4izcGbax6Pqw", "", (800, 600), (213, 160), ) helpers.check_image_data( self, images_data, "lOHX7xeJqCo_lqxKBobKGjwFTW8qPMPCbaAKeqS3baU-VT_SPC0HrapdAEXFzkL98dAb9nCjlRhnmCSLoz520E1fZ-xuNPXAwXvM2PapP6uolH6rZsR3QKivxr_rtVADKuWVm2lz8Q", "", (1000, 1000), (160, 160), )
def test_generate_images_data(self, input): with TempDirectory() as tempdir: # Init files gallery logic gallery_config = helpers.init_gallery_and_read_gallery_config( tempdir.path, self.remote_link) file_gallery_logic = OnedriveGalleryLogic(gallery_config) # Check images_data generated correctly file_gallery_logic.create_thumbnails() images_data = file_gallery_logic.generate_images_data({}) self.assertEqual(2, len(images_data)) helpers.check_image_data( self, images_data, "image1.jpg", "", (800, 600), (213, 160), ) helpers.check_image_data( self, images_data, "image2.jpg", "", (1000, 1000), (160, 160), )
def test_create_thumbnails(self, input): with TempDirectory() as tempdir: # Init files gallery logic gallery_config = helpers.init_gallery_and_read_gallery_config( tempdir.path, self.remote_link) file_gallery_logic = GoogleGalleryLogic(gallery_config) # Check no thumbnail created file_gallery_logic.create_thumbnails() tempdir.compare([".empty"], path="public/images/thumbnails")
def test_create_thumbnails(self, input): with TempDirectory() as tempdir: helpers.create_mock_image(os.path.join(tempdir.path, 'photo.jpg'), 1000, 500) helpers.create_mock_image(os.path.join(tempdir.path, 'photo2.gif'), 1000, 500) thumbnail_path = os.path.join(tempdir.path, 'public', 'images', 'thumbnails', 'photo.jpg') thumbnail_gif_path = os.path.join(tempdir.path, 'public', 'images', 'thumbnails', 'photo2.jpg') # Init files gallery logic gallery_config = helpers.init_gallery_and_read_gallery_config( tempdir.path) file_gallery_logic = FilesGalleryLogic(gallery_config) # Check no thumbnails exist tempdir.compare(['.empty'], path='public/images/thumbnails') # Check thumbnail created file_gallery_logic.create_thumbnails() tempdir.compare(['.empty', 'photo.jpg', 'photo2.jpg'], path='public/images/thumbnails') # The thumbnails are generated twice as big in order to improve the quality on retina displays self.assertEqual((640, 320), spg_media.get_image_size(thumbnail_path)) self.assertEqual((640, 320), spg_media.get_image_size(thumbnail_gif_path)) # Check thumbnail not regenerated without force helpers.create_mock_image( os.path.join(tempdir.path, 'public', 'images', 'photos', 'photo.jpg'), 500, 500) file_gallery_logic.create_thumbnails() self.assertEqual((640, 320), spg_media.get_image_size(thumbnail_path)) # Check thumbnail regenerated with force file_gallery_logic.create_thumbnails(force=True) self.assertEqual((320, 320), spg_media.get_image_size(thumbnail_path)) # Check thumbnail regenerated after size changed gallery_config['thumbnail_height'] = 320 file_gallery_logic = FilesGalleryLogic(gallery_config) file_gallery_logic.create_thumbnails() self.assertEqual((640, 640), spg_media.get_image_size(thumbnail_path))