示例#1
0
class TemplateInheritanceTestCase(unittest.TestCase):
    """
    Test template override realized with StringTemplate group template
    inheritance.
    """
    def setUp(self):
        """
        Prepare configuration data and initialize Danlann processor
        for a test case.
        """
        self.conf = ConfigParser()
        conf = ConfigParser()
        conf.readfp(StringIO(CONF))
        assert not conf.has_option('danlann', 'validate')

        # initialize processor
        self.processor = Danlann()
        self.processor.initialize(conf, False)
        self.generator = self.processor.generator
        self.filemanager = self.processor.fm


    def testOverride(self):
        """template override"""
        t = Template('basic', self.generator.gallery)
        self.assertTrue(t.st_group.superGroup is None)

        t = Template('basic', self.generator.gallery, 'a')
        self.assertTrue(t.st_group.superGroup is not None)
        self.assertEqual(t.st_group.superGroup.name, 'basic')
示例#2
0
class Base(unittest.TestCase):
    """
    Abstract class for test cases testing configuration.

    Configuration data is set using @C{config} decorator.

    @ivar conf     : test case configuration object
    @ivar processor: Danlann processor
    @ivar generator: Danlann gallery generator

    @see config
    """
    def setUp(self):
        """
        Prepare configuration data and initialize Danlann processor
        for a test case.
        """
        self.conf = ConfigParser()

        # get test case configuration data and read configuration
        try:
            test_name = getattr(self, '_TestCase__testMethodName') # python 2.4
        except AttributeError:
            test_name = getattr(self, '_testMethodName')           # python 2.5
        self.conf.readfp(StringIO(CONFIG_DATA[test_name]))

        # initialize processor
        self.processor = Danlann()
        self.processor.initialize(self.conf)
        self.generator = self.processor.generator
        self.filemanager = self.processor.fm
示例#3
0
    def testValidationConfigOverrideTrue(self):
        """override validation configuration to true"""
        conf = ConfigParser()
        conf.readfp(StringIO(CONF_MIN + '\nvalidate = False'))
        assert not conf.getboolean('danlann', 'validate')

        processor = Danlann()
        processor.initialize(conf, True)
        self.assert_(processor.validate)
示例#4
0
    def testDefaultValidationConfig(self):
        """default validation configuration"""
        conf = ConfigParser()
        conf.readfp(StringIO(CONF_MIN))
        assert not conf.has_option('danlann', 'validate')

        processor = Danlann()
        processor.initialize(conf, False)
        self.assert_(not processor.validate)
示例#5
0
    def setUp(self):
        """
        Prepare configuration data and initialize Danlann processor
        for a test case.
        """
        self.conf = ConfigParser()
        conf = ConfigParser()
        conf.readfp(StringIO(CONF))
        assert not conf.has_option('danlann', 'validate')

        # initialize processor
        self.processor = Danlann()
        self.processor.initialize(conf, False)
        self.generator = self.processor.generator
        self.filemanager = self.processor.fm
示例#6
0
    def setUp(self):
        """
        Prepare configuration data and initialize Danlann processor
        for a test case.
        """
        self.conf = ConfigParser()

        # get test case configuration data and read configuration
        try:
            test_name = getattr(self, '_TestCase__testMethodName') # python 2.4
        except AttributeError:
            test_name = getattr(self, '_testMethodName')           # python 2.5
        self.conf.readfp(StringIO(CONFIG_DATA[test_name]))

        # initialize processor
        self.processor = Danlann()
        self.processor.initialize(self.conf)
        self.generator = self.processor.generator
        self.filemanager = self.processor.fm
示例#7
0
class ConfigTestCase(unittest.TestCase):
    """
    Test file manager directory tree generator.

    Configuration data is set using @C{config} decorator.

    @ivar conf     : test case configuration object
    @ivar processor: Danlann processor
    @ivar generator: Danlann gallery generator

    @see config
    """
    def setUp(self):
        """
        Prepare configuration data and initialize Danlann processor
        for a test case.
        """
        self.conf = ConfigParser()

        # get test case configuration data and read configuration
        try:
            test_name = getattr(self, '_TestCase__testMethodName') # python 2.4
        except AttributeError:
            test_name = getattr(self, '_testMethodName')           # python 2.5
        self.conf.readfp(StringIO(CONFIG_DATA[test_name]))

        # initialize processor
        self.processor = Danlann()
        self.processor.initialize(self.conf)
        self.generator = self.processor.generator
        self.filemanager = self.processor.fm


    @config(CONF_MIN)
    def testMinimalConfig(self):
        """minimal and default configuration"""

        self.assertEqual(self.processor.libpath, [danlann.config.libpath])
        self.assertEqual(self.processor.albums, ['a.txt', 'b.txt'])
        self.assertEqual(self.processor.gallery.title, 'danlann title test')
        self.assertEqual(self.generator.indir, ['input_dir'])
        self.assertEqual(self.generator.outdir, 'output_dir')

        # see Danlann Manual for specification of default values
        args = self.generator.convert_args['thumb']
        self.assertEqual(args,
            ['-resize', '128x128>', '-quality', '90', '-unsharp', '3x3+0.5+0'])

        args = self.generator.convert_args['preview']
        self.assertEqual(args,
            ['-resize', '800x600>', '-quality', '90', '-unsharp', '3x3+0.5+0'])

        args = self.generator.convert_args['view']
        self.assertEqual(args,
            ['-resize', '1024x768>', '-quality', '90', '-unsharp', '3x3+0.5+0'])


    @config(CONF_MIN + CONF_PHOTO)
    def testConversionArguments(self):
        """photo conversion arguments"""
        assert self.conf.has_option('photo:view', 'size')

        args = self.generator.convert_args['thumb']
        self.assertEqual(args,
            ['-resize', '13', '-quality', '93', '-unsharp', '3'])

        args = self.generator.convert_args['preview']
        self.assertEqual(args,
            ['-resize', '12', '-quality', '92', '-unsharp', '2'])

        args = self.generator.convert_args['view']
        self.assertEqual(args,
            ['-resize', '11', '-quality', '91', '-unsharp', '1'])


    @config(CONF_MIN + CONF_PHOTO_CLEAR_ARG)
    def testConversionArgumentsClear(self):
        """clearing photo conversion arguments"""
        assert self.conf.has_option('photo:view', 'unsharp')
        assert self.conf.get('photo:view', 'unsharp') == ''

        args = self.generator.convert_args['view']
        self.assertEqual(len(args), 4)
        self.assert_('-unsharp' not in args)
        self.assert_('' not in args)


    @config(CONF_MIN + CONF_PHOTO_PARAMS)
    def testAdditionalParameters(self):
        """additional parameters"""
        assert self.conf.has_option('photo:view', 'params')
        assert self.conf.has_option('photo:preview', 'params')
        assert self.conf.has_option('photo:thumb', 'params')

        args = self.generator.convert_args['thumb']
        self.assertEqual(args,
            ['-resize', '128x128>', '-quality', '90',
                '-blur', '15', '-dither', '-unsharp', '3x3+0.5+0'])

        args = self.generator.convert_args['preview']
        self.assertEqual(args,
            ['-resize', '800x600>', '-quality', '90',
                '-dither', '-blur', '10', '-unsharp', '3x3+0.5+0'])

        args = self.generator.convert_args['view']
        self.assertEqual(args,
            ['-resize', '1024x768>', '-quality', '90',
                '-level', '2%', '-dither', '-unsharp', '3x3+0.5+0'])


    @config(CONF_PATHS)
    def testPaths(self):
        """paths"""
        assert self.conf.has_option('danlann', 'libpath')
        assert self.conf.has_option('danlann', 'indir')
        self.assertEqual(self.processor.libpath, ['libpath1', 'libpath2'])
        self.assertEqual(self.generator.indir, ['input_dir1', 'input_dir2'])


    @config(CONF_LIBPATH_OVERRIDE)
    def testLibPath(self):
        """libpath override"""
        assert self.conf.has_option('danlann', 'libpath')
        self.assertEqual(self.processor.libpath,
                ['libpath1', danlann.config.libpath, 'libpath2'])


    @config(CONF_FILES_OVERRIDE)
    def testFiles(self):
        """files override"""
        assert self.conf.has_option('danlann', 'files')
        self.assertEqual(self.processor.files,
                ['xx', 'css', 'js', 'ee'])


    @config(CONF_MIN)
    def testUseGraphicsMagick(self):
        """using GraphicsMagick"""
        assert not self.conf.has_option('danlann', 'graphicsmagick')
        self.assertEqual(self.filemanager.convert_cmd, ['gm', 'gm', 'convert'])


    @config(CONF_MIN + CONF_FILEMANAGER)
    def testUseImageMagick(self):
        """using ImageMagick"""
        assert self.conf.has_option('danlann', 'graphicsmagick')
        self.assertEqual(self.filemanager.convert_cmd, ['convert', 'convert'])
示例#8
0
class TemplateVariablesTestCase(unittest.TestCase):
    """
    Test if template variables are provided by templating functionality.
    """
    def setUp(self):
        """
        Prepare configuration data and initialize Danlann processor
        for a test case.
        """
        self.conf = ConfigParser()
        conf = ConfigParser()
        conf.readfp(StringIO(CONF))
        assert not conf.has_option('danlann', 'validate')

        # initialize processor
        self.processor = Danlann()
        self.processor.initialize(conf, False)
        self.generator = self.processor.generator
        self.filemanager = self.processor.fm

        tmpl = self.tmpl = self.generator.tmpl
        tmpl.tmpl_page = 'page'
        tmpl.tmpl_album = 'album'


    def _setTemplate(self, tmpl):
        self.tmpl.st_group = stringtemplate.StringTemplateGroup(StringIO(tmpl))


    def testGalleryPageVariables(self):
        """gallery page template variables"""
        self._setTemplate('group basic;\n' \
                'page(gallery, css, js, class, tmpl, rootdir, copyright) ::=' \
                ' "\'$gallery.title$\'' \
                ' $css$' \
                ' $js$' \
                ' $class$' \
                ' $tmpl$' \
                ' $rootdir$' \
                ' $copyright$"')

        f = StringIO()
        self.tmpl.galleryPage(f)

        expected = '\'danlann title test\'' \
                ' css/danlann.css' \
                ' js/jquery.jsjs/danlann.js' \
                ' gallery' \
                ' basic/gallery' \
                ' .' \
                ' (cc)\n'
        self.assertEquals(expected, f.getvalue())


    def testAlbumPageVairables(self):
        """album page template variables"""
        self._setTemplate('group basic;\n' \
                'page(gallery, css, js, class, tmpl, rootdir, copyright,' \
                '           album, parent, prev, next) ::=' \
                ' "\'$gallery.title$\'' \
                ' $css$' \
                ' $js$' \
                ' $class$' \
                ' $tmpl$' \
                ' $rootdir$' \
                ' $copyright$' \
                ' p:$prev.title$' \
                ' n:$next.title$' \
                ' $parent.title$"')

        f = StringIO()
        a1 = Album()
        a1.title = 'a 1 title'
        a1.dir = 'a/b/c'
        a2 = Album()
        a2.title = 'a 2 title'
        a2.dir = 'a/b/d'
        parent = self.tmpl.gallery
        parent.subalbums.extend([a1, a2])

        self.tmpl.albumPage(f, a1, parent)

        expected = '\'danlann title test\'' \
                ' css/danlann.css' \
                ' js/jquery.jsjs/danlann.js' \
                ' album' \
                ' album' \
                ' ../../..' \
                ' (cc)' \
                ' p:' \
                ' n:a 2 title' \
                ' danlann title test\n'
        self.assertEquals(expected, f.getvalue())


    def testPhotoPageVariables(self):
        """photo page template variables"""
        self._setTemplate('group basic;\n' \
                'page(gallery, css, js, class, tmpl, rootdir, copyright,' \
                '           album, photo, prev, next) ::=' \
                ' "\'$gallery.title$\'' \
                ' $css$' \
                ' $js$' \
                ' $class$' \
                ' $tmpl$' \
                ' $rootdir$' \
                ' $copyright$' \
                ' p:$prev.title$' \
                ' n:$next.title$' \
                ' $album.title$"')

        f = StringIO()
        album = Album()
        album.title = 'a title'
        album.dir = 'a/b/c'
        parent = self.tmpl.gallery
        parent.subalbums.append(album)

        p1 = Photo()
        p1.title = 'p1'
        p1.name = 'n1'
        p1.album = album

        p2 = Photo()
        p2.title = 'p2'
        p2.name = 'n2'
        p2.album = album

        album.photos.extend([p1, p2])

        self.tmpl.photoPage(f, p1)

        expected = '\'danlann title test\'' \
                ' css/danlann.css' \
                ' js/jquery.jsjs/danlann.js' \
                ' photo' \
                ' basic/photo' \
                ' ../../..' \
                ' (cc)' \
                ' p:' \
                ' n:p2' \
                ' a title\n'
        self.assertEquals(expected, f.getvalue())


    def testExifPageVariables(self):
        """exif page template variables"""
        self._setTemplate("group basic;\n" \
                'page(gallery, css, js, class, tmpl, rootdir, copyright,' \
                '           album, photo, prev, next) ::=' \
                ' "\'$gallery.title$\'' \
                ' $css$' \
                ' $js$' \
                ' $class$' \
                ' $tmpl$' \
                ' $rootdir$' \
                ' $copyright$' \
                ' p:$prev.title$' \
                ' n:$next.title$' \
                ' $album.title$' \
                ' $photo.exif: {e | n:$e.name$v:$e.value$}$"')

        f = StringIO()
        album = Album()
        album.title = 'a title'
        album.dir = 'a/b/c'
        parent = self.tmpl.gallery
        parent.subalbums.append(album)

        p1 = Photo()
        p1.title = 'p1'
        p1.name = 'n1'
        p1.album = album

        p1.exif.append(Exif('ea', 'ev'))
        p1.exif.append(Exif('ez', 'eq'))

        p2 = Photo()
        p2.title = 'p2'
        p2.name = 'n2'
        p2.album = album

        album.photos.extend([p1, p2])

        self.tmpl.photoPage(f, p1)

        expected = '\'danlann title test\'' \
                ' css/danlann.css' \
                ' js/jquery.jsjs/danlann.js' \
                ' photo' \
                ' basic/photo' \
                ' ../../..' \
                ' (cc)' \
                ' p:' \
                ' n:p2' \
                ' a title' \
                ' n:eav:evn:ezv:eq\n'
        self.assertEquals(expected, f.getvalue())