Mercurial > p > roundup > code
annotate test/session_common.py @ 4587:a2eb4fb3e6d8
New Chameleon templating engine, engine is now configurable.
We now have two configurable templating engines, the old Zope TAL
templates (called zopetal in the config) and the new Chameleon (called
chameleon in the config). A new config-option "template_engine" under
[main] can take these config-options, the default is zopetal.
Thanks to Cheer Xiao for the idea of making this configurable *and*
for the actual implementation!
Cheer Xiao commit log:
- The original TAL engine ported from Zope is thereafter referred to as
"zopetal", in speech and in code
- A new option "template_engine" under [main] introduced
- Zopetal-specific code stripped from cgi/templating.py to form the new
cgi/engine_zopetal.py
- Interface to Chameleon in cgi/engine_chameleon.py
- Engines are supposed to provide a Templates class that mimics the
behavior of the old cgi.templating.Templates. The Templates class is
preferably subclassed from cgi.templating.TemplatesBase.
- New function cgi.templating.get_templates to get the appropriate engine's
Templates instance according to the engine name
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Thu, 23 Feb 2012 18:10:03 +0100 |
| parents | cc33dc9aa3f2 |
| children | 63c79c0992ae |
| rev | line source |
|---|---|
|
2082
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1 import os, shutil, unittest |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2 |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3 from db_test_base import config |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
4 |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
5 class SessionTest(unittest.TestCase): |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
6 def setUp(self): |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
7 # remove previous test, ignore errors |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
8 if os.path.exists(config.DATABASE): |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
9 shutil.rmtree(config.DATABASE) |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
10 os.makedirs(config.DATABASE + '/files') |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
11 self.db = self.module.Database(config, 'admin') |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
12 self.sessions = self.sessions_module.Sessions(self.db) |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
13 self.otks = self.sessions_module.OneTimeKeys(self.db) |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
14 |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
15 def tearDown(self): |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
16 del self.otks |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
17 del self.sessions |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
18 if hasattr(self, 'db'): |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
19 self.db.close() |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
20 if os.path.exists(config.DATABASE): |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
21 shutil.rmtree(config.DATABASE) |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
22 |
|
4386
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
23 def testList(self): |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
24 self.sessions.list() |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
25 self.sessions.set('random_key', text='hello, world!') |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
26 self.sessions.list() |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
27 |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
28 def testGetAll(self): |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
29 self.sessions.set('random_key', text='hello, world!') |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
30 self.assertEqual(self.sessions.getall('random_key'), |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
31 {'text': 'hello, world!'}) |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
32 |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
33 def testDestroy(self): |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
34 self.sessions.set('random_key', text='hello, world!') |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
35 self.assertEquals(self.sessions.getall('random_key'), |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
36 {'text': 'hello, world!'}) |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
37 self.sessions.destroy('random_key') |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
38 self.assertRaises(KeyError, self.sessions.getall, 'random_key') |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
39 |
|
2082
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
40 def testSetSession(self): |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
41 self.sessions.set('random_key', text='hello, world!') |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
42 self.assertEqual(self.sessions.get('random_key', 'text'), |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
43 'hello, world!') |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
44 |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
45 def testUpdateSession(self): |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
46 self.sessions.set('random_key', text='hello, world!') |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
47 self.assertEqual(self.sessions.get('random_key', 'text'), |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
48 'hello, world!') |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
49 self.sessions.set('random_key', text='nope') |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
50 self.assertEqual(self.sessions.get('random_key', 'text'), 'nope') |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
51 |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
52 class DBMTest(SessionTest): |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
53 import roundup.backends.sessions_dbm as sessions_module |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
54 |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
55 class RDBMSTest(SessionTest): |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
56 import roundup.backends.sessions_rdbms as sessions_module |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
57 |
