1
# Lazygal, a lazy satic web gallery generator.
2
# Copyright (C) 2011 Alexandre Rossi <alexandre.rossi@gmail.com>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License along
15
# with this program; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
from __init__ import LazygalTestGen
24
from lazygal.generators import WebalbumDir
25
from lazygal.sourcetree import Directory
26
from lazygal import pyexiv2api as pyexiv2
29
class TestGenerators(LazygalTestGen):
31
def test_genfile_filelayout(self):
32
source_subgal = self.setup_subgal('subgal', ['subgal_img.jpg'])
34
dest_path = self.get_working_path()
36
self.album.generate(dest_path)
38
# Check root dir contents
39
self.assertTrue(os.path.isdir(dest_path))
40
for fn in ('index.html', 'index_medium.html'):
41
self.assertTrue(os.path.isfile(os.path.join(dest_path, fn)))
43
# Check subgal dir contents
44
dest_subgal_path = os.path.join(dest_path, 'subgal')
45
self.assertTrue(os.path.isdir(dest_subgal_path))
46
for fn in ('index.html', 'index_medium.html',
47
'subgal_img.html', 'subgal_img_medium.html',
48
'subgal_img_thumb.jpg', 'subgal_img_small.jpg',
49
'subgal_img_medium.jpg'):
50
self.assertTrue(os.path.isfile(os.path.join(dest_subgal_path, fn)))
52
def test_filecleanup(self):
54
Files that are not part of what was generated or updated shall be
57
pics = [ 'img%d.jpg' % i for i in range(0, 8)]
58
source_subgal = self.setup_subgal('subgal', pics)
60
dest_path = self.get_working_path()
62
self.album.generate(dest_path)
64
# add a thumbs that should not be there
65
self.add_img(dest_path, 'extra_thumb.jpg')
66
self.add_img(os.path.join(dest_path, 'subgal'), 'extra_thumb2.jpg')
68
# remove a pic in source_dir
69
os.unlink(os.path.join(self.source_dir, 'subgal', 'img6.jpg'))
71
# new objects to probe filesystem
72
pics.remove('img6.jpg')
73
source_subgal = Directory(os.path.join(self.source_dir, 'subgal'),
75
dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)
76
expected = map(lambda fn:\
77
unicode(os.path.join(dest_path, 'subgal', fn)),
80
'img6_small.jpg', 'img6_medium.jpg',
81
'img6.html', 'img6_medium.html',
84
self.assertEqual(sorted(dest_subgal.list_foreign_files()),
87
source_gal = Directory(self.source_dir, [source_subgal], [], self.album)
88
dest_gal = WebalbumDir(source_gal, [dest_subgal], self.album, dest_path)
89
self.assertEqual(sorted(dest_gal.list_foreign_files()),
90
[os.path.join(dest_path, 'extra_thumb.jpg')])
92
def test_originals_symlinks(self):
93
img_path = self.add_img(self.source_dir, 'symlink_target.jpg')
95
dest_dir = self.get_working_path()
96
self.album.set_original(original=True, orig_symlink=True)
97
self.album.generate(dest_dir)
99
symlink = os.path.join(dest_dir, os.path.basename(img_path))
100
# Test if the original in the webgal is a symlink
101
self.assertEqual(os.path.islink(symlink), True)
102
# Test if that symlink point to the image in the source_dir
103
self.assertEqual(os.path.realpath(symlink), img_path)
105
def test_metadata_osize_copy(self):
106
img_path = self.add_img(self.source_dir, 'md_filled.jpg')
109
gps_data = pyexiv2.ImageMetadata(self.get_sample_path('sample-with-gps.jpg'))
111
source_image = pyexiv2.ImageMetadata(img_path)
113
gps_data.copy(source_image)
114
dummy_comment = 'nice photo'
115
source_image['Exif.Photo.UserComment'] = dummy_comment
116
dummy_date = datetime.datetime(2011, 2, 3, 12, 51, 43)
117
source_image['Exif.Photo.DateTimeDigitized'] = dummy_date
118
assert 'Exif.GPSInfo.GPSLongitude' in source_image.exif_keys
119
assert 'Exif.GPSInfo.GPSLatitude' in source_image.exif_keys
123
dest_dir = self.get_working_path()
124
self.album.generate(dest_dir)
126
dest_img_path = os.path.join(dest_dir, 'md_filled_small.jpg')
127
dest_image = pyexiv2.ImageMetadata(dest_img_path)
130
# Check that metadata is still here for reduced pictures.
131
self.assertEqual(dest_image['Exif.Photo.UserComment'].value,
133
self.assertEqual(dest_image['Exif.Photo.DateTimeDigitized'].value,
136
# Check that blacklised tags are not present anymore in the reduced
138
def lat(): return dest_image['Exif.GPSInfo.GPSLongitude'].value
139
self.assertRaises(KeyError, lat)
141
def long(): return dest_image['Exif.GPSInfo.GPSLatitude'].value
142
self.assertRaises(KeyError, long)
145
img_path = self.add_img(self.source_dir, 'img01.jpg')
146
dest_dir = self.get_working_path()
147
self.album.generate(dest_dir, 'http://example.com/album/')
149
self.assertEqual(os.path.isfile(os.path.join(dest_dir, 'index.xml')),
153
class TestSpecialGens(LazygalTestGen):
156
super(TestSpecialGens, self).setUp(False)
157
self.dest_path = os.path.join(self.tmpdir, 'dst')
159
def test_paginate(self):
161
It shall be possible to split big galleries on mutiple index pages.
163
self.setup_album({'thumbs_per_page': 4})
165
pics = [ 'img%d.jpg' % i for i in range(0, 9)]
166
source_subgal = self.setup_subgal('subgal', pics)
168
self.album.generate(self.dest_path)
169
# FIXME: Check dest dir contents, test only catches uncaught exceptions
172
def test_flatten(self):
173
self.setup_album({'dir_flattening_depth': 1})
175
source_subgal = self.setup_subgal('subgal', ['subgal_img.jpg'])
176
self.album.generate(self.dest_path)
177
# FIXME: Check dest dir contents, test only catches uncaught exceptions
180
def test_flattenpaginate(self):
181
self.setup_album({'thumbs_per_page': 4, 'dir_flattening_depth': 1,})
183
pics = [ 'img%d.jpg' % i for i in range(0, 9)]
184
source_subgal = self.setup_subgal('subgal', pics)
186
self.album.generate(self.dest_path)
187
# FIXME: Check dest dir contents, test only catches uncaught exceptions
191
if __name__ == '__main__':
195
# vim: ts=4 sw=4 expandtab