web/test/unittest_propertysheet.py
changeset 5466 b5af2ac0c43c
parent 5445 4467ed43d97d
child 5938 9cb13d1b2ce4
equal deleted inserted replaced
5454:76b828dc3b9f 5466:b5af2ac0c43c
       
     1 import os
     1 from os.path import join, dirname
     2 from os.path import join, dirname
       
     3 from shutil import rmtree
       
     4 
     2 from logilab.common.testlib import TestCase, unittest_main
     5 from logilab.common.testlib import TestCase, unittest_main
       
     6 
     3 from cubicweb.web.propertysheet import *
     7 from cubicweb.web.propertysheet import *
     4 
     8 
     5 DATADIR = join(dirname(__file__), 'data')
     9 DATADIR = join(dirname(__file__), 'data')
       
    10 CACHEDIR = join(DATADIR, 'uicache')
       
    11 
     6 class PropertySheetTC(TestCase):
    12 class PropertySheetTC(TestCase):
     7 
    13 
       
    14     def tearDown(self):
       
    15         rmtree(CACHEDIR)
       
    16 
     8     def test(self):
    17     def test(self):
     9         ps = PropertySheet(None, datadir_url='http://cwtest.com')
    18         ps = PropertySheet(CACHEDIR, datadir_url='http://cwtest.com')
    10         ps.load(join(DATADIR, 'sheet1.py'))
    19         ps.load(join(DATADIR, 'sheet1.py'))
    11         ps.load(join(DATADIR, 'sheet2.py'))
    20         ps.load(join(DATADIR, 'sheet2.py'))
    12         # defined by sheet1
    21         # defined by sheet1
    13         self.assertEquals(ps['logo'], 'http://cwtest.com/logo.png')
    22         self.assertEquals(ps['logo'], 'http://cwtest.com/logo.png')
    14         # defined by sheet1, overriden by sheet2
    23         # defined by sheet1, overriden by sheet2
    18         # defined by sheet1, extended by sheet2
    27         # defined by sheet1, extended by sheet2
    19         self.assertEquals(ps['stylesheets'], ['http://cwtest.com/cubicweb.css',
    28         self.assertEquals(ps['stylesheets'], ['http://cwtest.com/cubicweb.css',
    20                                               'http://cwtest.com/mycube.css'])
    29                                               'http://cwtest.com/mycube.css'])
    21         self.assertEquals(ps.compile('a {bgcolor: %(bgcolor)s; size: 1%;}'),
    30         self.assertEquals(ps.compile('a {bgcolor: %(bgcolor)s; size: 1%;}'),
    22                           'a {bgcolor: #FFFFFF; size: 1%;}')
    31                           'a {bgcolor: #FFFFFF; size: 1%;}')
       
    32         self.assertEquals(ps.process_resource(DATADIR, 'pouet.css'),
       
    33                           CACHEDIR)
       
    34         self.failUnless('pouet.css' in ps._cache)
       
    35         self.failIf(ps.need_reload())
       
    36         os.utime(join(DATADIR, 'sheet1.py'), None)
       
    37         self.failUnless('pouet.css' in ps._cache)
       
    38         self.failUnless(ps.need_reload())
       
    39         self.failUnless('pouet.css' in ps._cache)
       
    40         ps.reload()
       
    41         self.failIf('pouet.css' in ps._cache)
       
    42         self.failIf(ps.need_reload())
       
    43         ps.process_resource(DATADIR, 'pouet.css') # put in cache
       
    44         os.utime(join(DATADIR, 'pouet.css'), None)
       
    45         self.failIf(ps.need_reload())
       
    46         self.failIf('pouet.css' in ps._cache)
    23 
    47 
    24 if __name__ == '__main__':
    48 if __name__ == '__main__':
    25     unittest_main()
    49     unittest_main()