def test_save_img_to_dir(self): test_image_path = os.path.join(os.path.dirname(__file__), '../data/image1.JPG') image = Image.open(test_image_path) res = save_img_to_dir(image, self.tempdir, SUB_DIR) self.assertIsNotNone(res) filename = res['path'] self.assertTrue(filename.endswith('.png'))
def test_save_img_to_dir_dry(self): test_image_path = os.path.join(os.path.dirname(__file__), '../data/image1.JPG') image = Image.open(test_image_path) res = save_img_to_dir(image, self.tempdir, SUB_DIR, dry=True) self.assertIsNone(res) md5 = hashlib.md5(image.tobytes()).hexdigest() filepath = os.path.join(self.tempdir, '', md5[:2], md5 + '.png') self.assertFalse(os.path.exists(filepath))
def test_save_img_to_dir_already_exists(self, mock_exists): test_image_path = os.path.join(os.path.dirname(__file__), '../data/image1.JPG') image = Image.open(test_image_path) image.save = Mock() mock_exists.return_value = True res = save_img_to_dir(image, self.tempdir, SUB_DIR) self.assertIsNotNone(res) self.assertEqual(image.save.call_count, 0)