web/test/unittest_propertysheet.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 31 Jan 2011 17:28:51 +0100
branchstable
changeset 6924 b88221afe491
parent 6340 470d8e828fda
child 7791 31bb51ea5485
permissions -rw-r--r--
[js utils] backport some generic code from comments cube to handle inline ajax form as you get to add comment to entities. Following stuff has been generalized and backported to ease such things: * lazy_view_holder() method on EntityCtxComponent class, to build place holder where the form will be inserted * ajax_composite_form() function in cw.web.views.ajaxedit, to build the form itself * reload() and reloadCtxComponentsSection() javascript function in cubicweb.ajax.js for the javascript processing side

import os
from os.path import join, dirname
from shutil import rmtree

from logilab.common.testlib import TestCase, unittest_main

from cubicweb.web.propertysheet import *

DATADIR = join(dirname(__file__), 'data')
CACHEDIR = join(DATADIR, 'uicache')

class PropertySheetTC(TestCase):

    def tearDown(self):
        rmtree(CACHEDIR)

    def test(self):
        ps = PropertySheet(CACHEDIR, datadir_url='http://cwtest.com')
        ps.load(join(DATADIR, 'sheet1.py'))
        ps.load(join(DATADIR, 'sheet2.py'))
        # defined by sheet1
        self.assertEqual(ps['logo'], 'http://cwtest.com/logo.png')
        # defined by sheet1, overriden by sheet2
        self.assertEqual(ps['bgcolor'], '#FFFFFF')
        # defined by sheet2
        self.assertEqual(ps['fontcolor'], 'black')
        # defined by sheet1, extended by sheet2
        self.assertEqual(ps['stylesheets'], ['http://cwtest.com/cubicweb.css',
                                              'http://cwtest.com/mycube.css'])
        # lazy string defined by sheet1
        self.assertIsInstance(ps['lazy'], lazystr)
        self.assertEqual(str(ps['lazy']), '#FFFFFF')
        # test compilation
        self.assertEqual(ps.compile('a {bgcolor: %(bgcolor)s; size: 1%;}'),
                          'a {bgcolor: #FFFFFF; size: 1%;}')
        self.assertEqual(ps.process_resource(DATADIR, 'pouet.css'),
                          CACHEDIR)
        self.failUnless('pouet.css' in ps._cache)
        self.failIf(ps.need_reload())
        os.utime(join(DATADIR, 'sheet1.py'), None)
        self.failUnless('pouet.css' in ps._cache)
        self.failUnless(ps.need_reload())
        self.failUnless('pouet.css' in ps._cache)
        ps.reload()
        self.failIf('pouet.css' in ps._cache)
        self.failIf(ps.need_reload())
        ps.process_resource(DATADIR, 'pouet.css') # put in cache
        os.utime(join(DATADIR, 'pouet.css'), None)
        self.failIf(ps.need_reload())
        self.failIf('pouet.css' in ps._cache)

if __name__ == '__main__':
    unittest_main()