author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 08 Apr 2015 09:27:26 +0200 | |
changeset 10519 | 0019b7888dd7 |
parent 9844 | e7d7b7793769 |
child 10318 | 09273cb083e7 |
permissions | -rw-r--r-- |
5466
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
1 |
import os |
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
2 |
from os.path import join, dirname |
5466
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
3 |
from shutil import rmtree |
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
4 |
|
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
5 |
from logilab.common.testlib import TestCase, unittest_main |
5466
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
6 |
|
9844
e7d7b7793769
[webtests/propertysheet] kill an "import *"
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9675
diff
changeset
|
7 |
from cubicweb.web.propertysheet import PropertySheet, lazystr |
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
8 |
|
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
9 |
DATADIR = join(dirname(__file__), 'data') |
5466
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
10 |
CACHEDIR = join(DATADIR, 'uicache') |
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
11 |
|
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
12 |
class PropertySheetTC(TestCase): |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
13 |
|
5466
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
14 |
def tearDown(self): |
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
15 |
rmtree(CACHEDIR) |
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
16 |
|
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
17 |
def test(self): |
5466
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
18 |
ps = PropertySheet(CACHEDIR, datadir_url='http://cwtest.com') |
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
19 |
ps.load(join(DATADIR, 'sheet1.py')) |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
20 |
ps.load(join(DATADIR, 'sheet2.py')) |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
21 |
# defined by sheet1 |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5938
diff
changeset
|
22 |
self.assertEqual(ps['logo'], 'http://cwtest.com/logo.png') |
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
23 |
# defined by sheet1, overriden by sheet2 |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5938
diff
changeset
|
24 |
self.assertEqual(ps['bgcolor'], '#FFFFFF') |
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
25 |
# defined by sheet2 |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5938
diff
changeset
|
26 |
self.assertEqual(ps['fontcolor'], 'black') |
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
27 |
# defined by sheet1, extended by sheet2 |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5938
diff
changeset
|
28 |
self.assertEqual(ps['stylesheets'], ['http://cwtest.com/cubicweb.css', |
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
29 |
'http://cwtest.com/mycube.css']) |
5938
9cb13d1b2ce4
[uiprops] introduce lazystr to get a chance to change style without having to change all properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5466
diff
changeset
|
30 |
# lazy string defined by sheet1 |
9cb13d1b2ce4
[uiprops] introduce lazystr to get a chance to change style without having to change all properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5466
diff
changeset
|
31 |
self.assertIsInstance(ps['lazy'], lazystr) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5938
diff
changeset
|
32 |
self.assertEqual(str(ps['lazy']), '#FFFFFF') |
5938
9cb13d1b2ce4
[uiprops] introduce lazystr to get a chance to change style without having to change all properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5466
diff
changeset
|
33 |
# test compilation |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5938
diff
changeset
|
34 |
self.assertEqual(ps.compile('a {bgcolor: %(bgcolor)s; size: 1%;}'), |
5445
4467ed43d97d
[web] use uiprops value to compile css transparently, handlig cache and reloading in debug mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
35 |
'a {bgcolor: #FFFFFF; size: 1%;}') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5938
diff
changeset
|
36 |
self.assertEqual(ps.process_resource(DATADIR, 'pouet.css'), |
5466
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
37 |
CACHEDIR) |
9674
96549de9dd70
[test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents:
7791
diff
changeset
|
38 |
self.assertIn('pouet.css', ps._cache) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
39 |
self.assertFalse(ps.need_reload()) |
5466
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
40 |
os.utime(join(DATADIR, 'sheet1.py'), None) |
9674
96549de9dd70
[test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents:
7791
diff
changeset
|
41 |
self.assertIn('pouet.css', ps._cache) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
42 |
self.assertTrue(ps.need_reload()) |
9674
96549de9dd70
[test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents:
7791
diff
changeset
|
43 |
self.assertIn('pouet.css', ps._cache) |
5466
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
44 |
ps.reload() |
9675
8aabfefc8a81
[test] use assertNotIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents:
9674
diff
changeset
|
45 |
self.assertNotIn('pouet.css', ps._cache) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
46 |
self.assertFalse(ps.need_reload()) |
5466
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
47 |
ps.process_resource(DATADIR, 'pouet.css') # put in cache |
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5445
diff
changeset
|
48 |
os.utime(join(DATADIR, 'pouet.css'), None) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
49 |
self.assertFalse(ps.need_reload()) |
9675
8aabfefc8a81
[test] use assertNotIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents:
9674
diff
changeset
|
50 |
self.assertNotIn('pouet.css', ps._cache) |
5444
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
51 |
|
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
52 |
if __name__ == '__main__': |
f7fdb5dd82f6
[webconfig] introduce property sheets. Use them to replace external_resources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
53 |
unittest_main() |