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.
22
from __init__ import LazygalTestGen
23
from lazygal.generators import WebalbumDir
24
from lazygal.sourcetree import Directory
25
from lazygal.genpage import WebalbumIndexPage
26
from lazygal import pyexiv2api as pyexiv2
29
class TestDeps(LazygalTestGen):
31
Dependencies of built items
34
def test_second_build(self):
36
Once built, a webgal shall not need build.
38
source_subgal = self.setup_subgal('subgal', ['subgal_img.jpg'])
40
dest_path = os.path.join(self.tmpdir, 'dst')
41
dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)
43
self.assertTrue(dest_subgal.needs_build(),
44
'Webalbum subgal has not been built and does not need build.')
46
self.album.generate(dest_path)
47
dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)
49
self.assertFalse(dest_subgal.needs_build(),
50
'Webalbum subgal has been built and does need build because of %s.'\
51
% str(dest_subgal.needs_build(True)))
53
def test_dirmetadata_update(self):
55
Updated directory metadata file shall trigger the rebuild of the
56
corresponding webgal directory.
58
subgal_path = os.path.join(self.source_dir, 'subgal')
60
self.add_img(subgal_path, 'subgal_img.jpg')
62
# metadata must exist before creating the Directory() object (md files
63
# are probed in the constructor.
64
self.album.generate_default_metadata()
66
source_subgal = Directory(subgal_path, [], ['subgal_img.jpg'],
69
dest_path = os.path.join(self.tmpdir, 'dst')
71
self.album.generate(dest_path)
72
dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)
74
self.assertFalse(dest_subgal.needs_build(),
75
'Webalbum subgal has been built and does need build because of %s.'\
76
% str(dest_subgal.needs_build(True)))
78
# touch the description file
79
os.utime(os.path.join(source_subgal.path, 'album_description'), None)
80
# New objects in order to probe filesystem
81
source_subgal = Directory(subgal_path, [], ['subgal_img.jpg'],
83
dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)
85
self.assertTrue(dest_subgal.needs_build(),
86
'Webalbum subgal should need build because of updated dir md.')
88
def test_subgal_update(self):
90
Updated subgals shall trigger the webgal rebuild and the parent
91
directory index rebuild.
93
source_subgal = self.setup_subgal('subgal', ['subgal_img.jpg'])
95
dest_path = os.path.join(self.tmpdir, 'dst')
97
self.album.generate(dest_path)
98
dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)
100
self.assertFalse(dest_subgal.needs_build(),
101
'Webalbum subgal has been built and does need build because of %s.'\
102
% str(dest_subgal.needs_build(True)))
104
self.add_img(source_subgal.path, 'subgal_img2.jpg')
105
# New objects to ensure pic is taken into account
106
source_subgal = Directory(source_subgal.path, [],
107
['subgal_img.jpg', 'subgal_img2.jpg'],
109
dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)
111
# Subgal should need build.
112
self.assertTrue(dest_subgal.needs_build(),
113
'Webalbum subgal should need build because of added pic in subgal.')
115
# Parent directory should need build.
116
source_gal = Directory(self.source_dir, [source_subgal], [], self.album)
117
dest_gal = WebalbumDir(source_gal, [dest_subgal], self.album, dest_path)
118
self.assertTrue(dest_gal.needs_build(),
119
'Webalbum gal should need build because of added pic in subgal.')
121
# Parent directory should need build.
122
parent_index = WebalbumIndexPage(dest_gal, 'small', 0,
124
[(dest_subgal, dest_subgal.medias)])
125
self.assertTrue(parent_index.needs_build(),
126
'Webalbum gal index should need build because of added pic in subgal.')
129
if __name__ == '__main__':
133
# vim: ts=4 sw=4 expandtab