improve tests for gallery

This commit is contained in:
Simon
2012-11-09 13:07:03 +01:00
parent b06c381833
commit 6fcaa01e90

View File

@@ -4,7 +4,7 @@
import os
import unittest
from sigal.gallery import Gallery
from sigal.gallery import Gallery, get_metadata
from sigal.settings import read_settings
CURRENT_DIR = os.path.dirname(__file__)
@@ -13,19 +13,20 @@ CURRENT_DIR = os.path.dirname(__file__)
class TestGallery(unittest.TestCase):
"Test the Gallery class."
def setUp(self):
@classmethod
def setUp(cls):
"""Read the sample config file."""
default_conf = os.path.join(CURRENT_DIR, 'sample', 'sigal.conf')
settings = read_settings(default_conf)
self.gal = Gallery(settings, os.path.join(CURRENT_DIR, 'sample'),
os.path.join(CURRENT_DIR, 'output'))
cls.gal = Gallery(settings, os.path.join(CURRENT_DIR, 'sample'),
os.path.join(CURRENT_DIR, 'output'))
cls.gal.build_paths()
def test_filelist(self):
self.gal.build_paths()
paths = self.gal.paths
self.assertItemsEqual(paths.keys(), ['.', 'dir1', 'dir2'])
self.assertItemsEqual(paths.keys(), ['.', 'dir1', 'dir2', 'dir1/test'])
self.assertListEqual(paths['.']['img'], [])
self.assertItemsEqual(paths['.']['subdir'], ['dir1', 'dir2'])
@@ -33,3 +34,20 @@ class TestGallery(unittest.TestCase):
self.assertItemsEqual(paths['dir1']['img'], ['test1.jpg', 'test2.jpg'])
self.assertEqual(paths['dir1']['representative'], u'test1.jpg')
self.assertEqual(paths['dir1']['title'], u'An example gallery')
def test_find_representative(self):
self.assertEqual(self.gal.find_representative('dir1'), u'test1.jpg')
self.assertEqual(self.gal.find_representative('dir1/test'),
u'test2.jpg')
class TestMetadata(unittest.TestCase):
"Test the Gallery class."
def test_get_metadata(self):
m = get_metadata(os.path.join(CURRENT_DIR, 'sample', 'dir1'))
self.assertEqual(m['title'], 'An example gallery')
self.assertEqual(m['representative'], 'test1.jpg')
m = get_metadata(os.path.join(CURRENT_DIR, 'sample', 'dir1', 'test'))
self.assertEqual(m['title'], 'Test')