def test_exists(self, mock_exists): """Call os.path.exists for path of image file.""" mock_exists.return_value = True image = Image() image.filename = 'hello.jpg' assert image.exists() mock_exists.assert_called_with(image.full_path)
def test_full_path(self): """Return the absolute file path for image name.""" image = Image() image.filename = 'hello.jpg' assert image.full_path ==\ os.path.join(current_app.config.get('IMAGES_FOLDER'), 'plants', image.filename)
def test_remove_cultivar_delete_images_deletes_images(self, mock_delete, app, db): """Delete images and thumbnail if delete_images is checked.""" cultivar = foxy_cultivar() img = Image() img.filename = "foxee.jpg" thumb = Image() thumb.filename = "foxy.jpg" cultivar.images.append(img) cultivar.thumbnail = thumb db.session.add_all([cultivar, img, thumb]) db.session.commit() with app.test_client() as tc: tc.post( url_for("seeds.remove_cultivar", cv_id=cultivar.id), data=dict(verify_removal=True, delete_images=True), follow_redirects=True, ) assert Image.query.count() == 0 assert mock_delete.called
def test_delete_file(self, mock_remove): """Delete image file using os.remove.""" image = Image() image.filename = 'hello.jpg' image.delete_file() mock_remove.assert_called_with(image.full_path)