~ubuntu-branches/ubuntu/quantal/lazygal/quantal

« back to all changes in this revision

Viewing changes to lazygaltest/test_gendeps.py

  • Committer: Bazaar Package Importer
  • Author(s): Michal Čihař
  • Date: 2011-03-21 15:55:53 UTC
  • mfrom: (1.1.6 upstream) (2.1.10 sid)
  • Revision ID: james.westby@ubuntu.com-20110321155553-2qmag1i39n54hjv3
Tags: 0.6-2
* Update home page.
* Suggest gstreamer for video support.
* Require python 2.6 or newer (Closes: #619032).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Lazygal, a lazy satic web gallery generator.
 
2
# Copyright (C) 2011 Alexandre Rossi <alexandre.rossi@gmail.com>
 
3
#
 
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.
 
8
#
 
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.
 
13
#
 
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.
 
17
 
 
18
 
 
19
import os
 
20
import unittest
 
21
 
 
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
 
27
 
 
28
 
 
29
class TestDeps(LazygalTestGen):
 
30
    """
 
31
    Dependencies of built items
 
32
    """
 
33
 
 
34
    def test_second_build(self):
 
35
        """
 
36
        Once built, a webgal shall not need build.
 
37
        """
 
38
        source_subgal = self.setup_subgal('subgal', ['subgal_img.jpg'])
 
39
 
 
40
        dest_path = os.path.join(self.tmpdir, 'dst')
 
41
        dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)
 
42
 
 
43
        self.assertTrue(dest_subgal.needs_build(),
 
44
               'Webalbum subgal has not been built and does not need build.')
 
45
 
 
46
        self.album.generate(dest_path)
 
47
        dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)
 
48
 
 
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)))
 
52
 
 
53
    def test_dirmetadata_update(self):
 
54
        """
 
55
        Updated directory metadata file shall trigger the rebuild of the
 
56
        corresponding webgal directory.
 
57
        """
 
58
        subgal_path = os.path.join(self.source_dir, 'subgal')
 
59
        os.mkdir(subgal_path)
 
60
        self.add_img(subgal_path, 'subgal_img.jpg')
 
61
 
 
62
        # metadata must exist before creating the Directory() object (md files
 
63
        # are probed in the constructor.
 
64
        self.album.generate_default_metadata()
 
65
 
 
66
        source_subgal = Directory(subgal_path, [], ['subgal_img.jpg'],
 
67
                                  self.album)
 
68
 
 
69
        dest_path = os.path.join(self.tmpdir, 'dst')
 
70
 
 
71
        self.album.generate(dest_path)
 
72
        dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)
 
73
 
 
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)))
 
77
 
 
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'],
 
82
                                  self.album)
 
83
        dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)
 
84
 
 
85
        self.assertTrue(dest_subgal.needs_build(),
 
86
            'Webalbum subgal should need build because of updated dir md.')
 
87
 
 
88
    def test_subgal_update(self):
 
89
        """
 
90
        Updated subgals shall trigger the webgal rebuild and the parent
 
91
        directory index rebuild.
 
92
        """
 
93
        source_subgal = self.setup_subgal('subgal', ['subgal_img.jpg'])
 
94
 
 
95
        dest_path = os.path.join(self.tmpdir, 'dst')
 
96
 
 
97
        self.album.generate(dest_path)
 
98
        dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)
 
99
 
 
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)))
 
103
 
 
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'],
 
108
                                  self.album)
 
109
        dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)
 
110
 
 
111
        # Subgal should need build.
 
112
        self.assertTrue(dest_subgal.needs_build(),
 
113
            'Webalbum subgal should need build because of added pic in subgal.')
 
114
 
 
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.')
 
120
 
 
121
        # Parent directory should need build.
 
122
        parent_index = WebalbumIndexPage(dest_gal, 'small', 0,
 
123
                                         [dest_subgal],
 
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.')
 
127
 
 
128
 
 
129
if __name__ == '__main__':
 
130
    unittest.main()
 
131
 
 
132
 
 
133
# vim: ts=4 sw=4 expandtab