def test_index_html(self, input): with TempDirectory() as tempdir: create_mock_image(os.path.join(tempdir.path, "photo.jpg"), 1000, 500) sys.argv = ["gallery_init", "-p", tempdir.path] gallery_init.main() sys.argv = ["gallery_build", "-p", tempdir.path] gallery_build.main() tempdir.compare(["css", "images", "js", "index.html"], path="public", recursive=False) with open(os.path.join(tempdir.path, "public", "index.html"), "r") as html_in: html = html_in.read() self.assertIn("<title>My Gallery</title>", html) self.assertIn("<h1>My Gallery</h1>", html) self.assertIn( '<div class="header-info-details">Default description of my gallery</div>', html, ) self.assertIn("<h2>My Gallery</h2>", html) self.assertIn('<a href="images/photos/photo.jpg"', html) self.assertIn( 'background: #333366 url("images/photos/photo.jpg")', html)
def test_index_html(self, input): with TempDirectory() as tempdir: create_mock_image(os.path.join(tempdir.path, 'photo.jpg'), 1000, 500) sys.argv = ['gallery_init', '-p', tempdir.path] gallery_init.main() sys.argv = ['gallery_build', '-p', tempdir.path] gallery_build.main() tempdir.compare(['css', 'images', 'js', 'index.html'], path='public', recursive=False) with open(os.path.join(tempdir.path, 'public', 'index.html'), 'r') as html_in: html = html_in.read() self.assertIn('<title>My Gallery</title>', html) self.assertIn('<h1>My Gallery</h1>', html) self.assertIn( '<div class="header-info-details">Default description of my gallery</div>', html) self.assertIn('<h2>My Gallery</h2>', html) self.assertIn('<a href="images/photos/photo.jpg"', html) self.assertIn( 'background: #333366 url("images/photos/photo.jpg")', html)
def test_default_gallery_config(self, input): with TempDirectory() as tempdir: sys.argv = ['gallery_init', '-p', tempdir.path] gallery_init.main() self.check_gallery_config( os.path.join(tempdir.path, 'gallery.json'), tempdir.path, 'My Gallery', 'Default description of my gallery', 160, '')
def test_new_invalid_remote_gallery(self, input): with TempDirectory() as tempdir: sys.argv = [ 'gallery_init', 'https://test.com/test', '-p', tempdir.path ] with self.assertRaises(SystemExit) as cm: gallery_init.main() self.assertEqual(cm.exception.code, 1)
def test_nonexisting_gallery_path(self): with TempDirectory() as tempdir: with self.assertRaises(SystemExit) as cm: sys.argv = [ 'gallery_init', '-p', os.path.join(tempdir.path, 'non_existing_path') ] gallery_init.main() self.assertEqual(cm.exception.code, 1)
def test_existing_gallery_no_force(self): with TempDirectory() as tempdir: tempdir.write('gallery.json', b'') with self.assertRaises(SystemExit) as cm: sys.argv = ['gallery_init', '-p', tempdir.path] gallery_init.main() self.assertEqual(cm.exception.code, 0) tempdir.compare(['gallery.json'])
def test_existing_gallery_no_force(self): with TempDirectory() as tempdir: tempdir.write("gallery.json", b"") with self.assertRaises(SystemExit) as cm: sys.argv = ["gallery_init", "-p", tempdir.path] gallery_init.main() self.assertEqual(cm.exception.code, 0) tempdir.compare(["gallery.json"])
def setup_gallery(tempdir): # Create a mock image create_mock_image(os.path.join(tempdir.path, 'photo.jpg'), 1000, 500) # Init and build the gallery public_path = os.path.join(tempdir.path, 'public') sys.argv = ['gallery_init', '-p', tempdir.path] gallery_init.main() sys.argv = ['gallery_build', '-p', tempdir.path] gallery_build.main() return public_path
def setup_gallery(tempdir): # Create a mock image create_mock_image(os.path.join(tempdir.path, "photo.jpg"), 1000, 500) # Init and build the gallery public_path = os.path.join(tempdir.path, "public") sys.argv = ["gallery_init", "-p", tempdir.path] gallery_init.main() sys.argv = ["gallery_build", "-p", tempdir.path] gallery_build.main() return public_path
def test_gallery_not_built(self, input): with TempDirectory() as tempdir: sys.argv = ['gallery_init', '-p', tempdir.path] gallery_init.main() with self.assertRaises(SystemExit) as cm: sys.argv = [ 'gallery_upload', 'aws', 'testbucket/path', '-p', tempdir.path ] gallery_upload.main() self.assertEqual(cm.exception.code, 1)
def test_default_gallery_config(self, input): with TempDirectory() as tempdir: sys.argv = ["gallery_init", "-p", tempdir.path] gallery_init.main() self.check_gallery_config( os.path.join(tempdir.path, "gallery.json"), tempdir.path, "My Gallery", "Default description of my gallery", 160, "", )
def test_new_google_gallery_created(self, input): with TempDirectory() as tempdir: sys.argv = [ 'gallery_init', 'https://photos.app.goo.gl/test', '-p', tempdir.path ] gallery_init.main() check_gallery_files(tempdir, [], []) self.check_gallery_config( os.path.join(tempdir.path, 'gallery.json'), tempdir.path, 'Test Gallery', 'Test Description', 160, 'photo.jpg', 'example.com', 'google', 'https://photos.app.goo.gl/test')
def test_images_data_generation(self, input): with TempDirectory() as tempdir: create_mock_image(os.path.join(tempdir.path, 'photo.jpg'), 1000, 500) sys.argv = ['gallery_init', '-p', tempdir.path] gallery_init.main() sys.argv = ['gallery_build', '-p', tempdir.path] gallery_build.main() tempdir.compare( ['templates', 'public', 'gallery.json', 'images_data.json'], recursive=False)
def test_images_data_generation(self, input): with TempDirectory() as tempdir: create_mock_image(os.path.join(tempdir.path, "photo.jpg"), 1000, 500) sys.argv = ["gallery_init", "-p", tempdir.path] gallery_init.main() sys.argv = ["gallery_build", "-p", tempdir.path] gallery_build.main() tempdir.compare( ["templates", "public", "gallery.json", "images_data.json"], recursive=False, )
def init_gallery_and_read_gallery_config(path, remote_link=""): """ Initializes a new gallery and reads the data from the gallery.json file :param path: path to the folder where the gallery will be created :param remote_link: optional remote link to initialize a remote gallery :return: gallery config dict """ sys.argv = ["gallery_init", remote_link, "-p", path] gallery_init.main() with open(os.path.join(path, "gallery.json"), "r") as json_in: gallery_config = json.load(json_in) return gallery_config
def test_new_gallery_created(self, input): files_photos = ['photo.jpg', 'photo.jpeg', 'photo.gif', 'video.mp4'] files_other = ['something.txt'] with TempDirectory() as tempdir: for file in files_photos + files_other: tempdir.write(file, b'') sys.argv = ['gallery_init', '-p', tempdir.path] gallery_init.main() check_gallery_files(tempdir, files_photos, files_other) self.check_gallery_config( os.path.join(tempdir.path, 'gallery.json'), tempdir.path, 'Test Gallery', 'Test Description', 160, 'photo.jpg', 'example.com')
def test_gallery_not_built(self, input): with TempDirectory() as tempdir: sys.argv = ["gallery_init", "-p", tempdir.path] gallery_init.main() with self.assertRaises(SystemExit) as cm: sys.argv = [ "gallery_upload", "aws", "testbucket/path", "-p", tempdir.path, ] gallery_upload.main() self.assertEqual(cm.exception.code, 1)
def test_new_gallery_created(self, input): files_photos = ["photo.jpg", "photo.jpeg", "photo.gif", "video.mp4"] files_other = ["something.txt"] with TempDirectory() as tempdir: for file in files_photos + files_other: tempdir.write(file, b"") sys.argv = ["gallery_init", "-p", tempdir.path] gallery_init.main() check_gallery_files(tempdir, files_photos, files_other) self.check_gallery_config( os.path.join(tempdir.path, "gallery.json"), tempdir.path, "Test Gallery", "Test Description", 160, "photo.jpg", "example.com", )
def test_new_google_gallery_created(self, input): with TempDirectory() as tempdir: sys.argv = [ "gallery_init", "https://photos.app.goo.gl/test", "-p", tempdir.path, ] gallery_init.main() check_gallery_files(tempdir, [], []) self.check_gallery_config( os.path.join(tempdir.path, "gallery.json"), tempdir.path, "Test Gallery", "Test Description", 160, "photo.jpg", "example.com", "google", "https://photos.app.goo.gl/test", )
def test_thumbnails_generation(self, input): with TempDirectory() as tempdir: create_mock_image(os.path.join(tempdir.path, "photo.jpg"), 1000, 500) thumbnail_path = os.path.join(tempdir.path, "public", "images", "thumbnails", "photo.jpg") sys.argv = ["gallery_init", "-p", tempdir.path] gallery_init.main() # Check no thumbnails exist tempdir.compare([".empty"], path="public/images/thumbnails") # Check thumbnail created sys.argv = ["gallery_build", "-p", tempdir.path] gallery_build.main() tempdir.compare([".empty", "photo.jpg"], path="public/images/thumbnails") self.assertEqual((640, 320), spg_media.get_image_size(thumbnail_path)) # Check thumbnail not regenerated without force create_mock_image( os.path.join(tempdir.path, "public", "images", "photos", "photo.jpg"), 500, 500, ) sys.argv = ["gallery_build", "-p", tempdir.path] gallery_build.main() self.assertEqual((640, 320), spg_media.get_image_size(thumbnail_path)) # Check thumbnail regenerated with force sys.argv = ["gallery_build", "-p", tempdir.path, "-ft"] gallery_build.main() self.assertEqual((320, 320), spg_media.get_image_size(thumbnail_path))
def test_thumbnails_generation(self, input): with TempDirectory() as tempdir: create_mock_image(os.path.join(tempdir.path, 'photo.jpg'), 1000, 500) thumbnail_path = os.path.join(tempdir.path, 'public', 'images', 'thumbnails', 'photo.jpg') sys.argv = ['gallery_init', '-p', tempdir.path] gallery_init.main() # Check no thumbnails exist tempdir.compare(['.empty'], path='public/images/thumbnails') # Check thumbnail created sys.argv = ['gallery_build', '-p', tempdir.path] gallery_build.main() tempdir.compare(['.empty', 'photo.jpg'], path='public/images/thumbnails') self.assertEqual((640, 320), spg_media.get_image_size(thumbnail_path)) # Check thumbnail not regenerated without force create_mock_image( os.path.join(tempdir.path, 'public', 'images', 'photos', 'photo.jpg'), 500, 500) sys.argv = ['gallery_build', '-p', tempdir.path] gallery_build.main() self.assertEqual((640, 320), spg_media.get_image_size(thumbnail_path)) # Check thumbnail regenerated with force sys.argv = ['gallery_build', '-p', tempdir.path, '-ft'] gallery_build.main() self.assertEqual((320, 320), spg_media.get_image_size(thumbnail_path))