Code

*** empty log message ***
[roundup.git] / test / test_templating.py
1 import unittest
2 from cgi import FieldStorage, MiniFieldStorage
4 from roundup.cgi.templating import *
5 from test_actions import MockNull, true
7 class MockDatabase(MockNull):
8     def getclass(self, name):
9         return self.classes[name]
11 class TemplatingTestCase(unittest.TestCase):
12     def setUp(self):
13         self.form = FieldStorage()
14         self.client = MockNull()
15         self.client.db = MockDatabase()
16         self.client.form = self.form
18 class HTMLDatabaseTestCase(TemplatingTestCase):
19     def test_HTMLDatabase___getitem__(self):
20         db = HTMLDatabase(self.client)
21         self.assert_(isinstance(db['issue'], HTMLClass))
22         self.assert_(isinstance(db['user'], HTMLUserClass))
23         self.assert_(isinstance(db['issue1'], HTMLItem))
24         self.assert_(isinstance(db['user1'], HTMLUser))
26     def test_HTMLDatabase___getattr__(self):
27         db = HTMLDatabase(self.client)
28         self.assert_(isinstance(db.issue, HTMLClass))
29         self.assert_(isinstance(db.user, HTMLUserClass))
30         self.assert_(isinstance(db.issue1, HTMLItem))
31         self.assert_(isinstance(db.user1, HTMLUser))
33     def test_HTMLDatabase_classes(self):
34         db = HTMLDatabase(self.client)
35         db._db.classes = {'issue':MockNull(), 'user': MockNull()}
36         db.classes()
38 class FunctionsTestCase(TemplatingTestCase):
39     def test_lookupIds(self):
40         db = HTMLDatabase(self.client)
41         def lookup(key):
42             if key == 'ok':
43                 return '1'
44             if key == 'fail':
45                 raise KeyError, 'fail'
46         db._db.classes = {'issue': MockNull(lookup=lookup)}
47         prop = MockNull(classname='issue')
48         self.assertEqual(lookupIds(db._db, prop, ['1','2']), ['1','2'])
49         self.assertEqual(lookupIds(db._db, prop, ['ok','2']), ['1','2'])
50         self.assertEqual(lookupIds(db._db, prop, ['ok', 'fail'], 1),
51             ['1', 'fail'])
52         self.assertEqual(lookupIds(db._db, prop, ['ok', 'fail']), ['1'])
54     def test_lookupKeys(self):
55         db = HTMLDatabase(self.client)
56         def get(entry, key):
57             return {'1': 'green', '2': 'eggs'}.get(entry, entry)
58         shrubbery = MockNull(get=get)
59         db._db.classes = {'shrubbery': shrubbery}
60         self.assertEqual(lookupKeys(shrubbery, 'spam', ['1','2']),
61             ['green', 'eggs'])
62         self.assertEqual(lookupKeys(shrubbery, 'spam', ['ok','2']), ['ok',
63             'eggs'])
65 '''
66 class HTMLPermissions:
67     def is_edit_ok(self):
68     def is_view_ok(self):
69     def is_only_view_ok(self):
70     def view_check(self):
71     def edit_check(self):
73 def input_html4(**attrs):
74 def input_xhtml(**attrs):
76 class HTMLInputMixin:
77     def __init__(self):
79 class HTMLClass(HTMLInputMixin, HTMLPermissions):
80     def __init__(self, client, classname, anonymous=0):
81     def __repr__(self):
82     def __getitem__(self, item):
83     def __getattr__(self, attr):
84     def designator(self):
85     def getItem(self, itemid, num_re=re.compile('-?\d+')):
86     def properties(self, sort=1):
87     def list(self, sort_on=None):
88     def csv(self):
89     def propnames(self):
90     def filter(self, request=None, filterspec={}, sort=(None,None),
91     def classhelp(self, properties=None, label='(list)', width='500',
92     def submit(self, label="Submit New Entry"):
93     def history(self):
94     def renderWith(self, name, **kwargs):
96 class HTMLItem(HTMLInputMixin, HTMLPermissions):
97     def __init__(self, client, classname, nodeid, anonymous=0):
98     def __repr__(self):
99     def __getitem__(self, item):
100     def __getattr__(self, attr):
101     def designator(self):
102     def is_retired(self):
103     def submit(self, label="Submit Changes"):
104     def journal(self, direction='descending'):
105     def history(self, direction='descending', dre=re.compile('\d+')):
106     def renderQueryForm(self):
108 class HTMLUserPermission:
109     def is_edit_ok(self):
110     def is_view_ok(self):
111     def _user_perm_check(self, type):
113 class HTMLUserClass(HTMLUserPermission, HTMLClass):
115 class HTMLUser(HTMLUserPermission, HTMLItem):
116     def __init__(self, client, classname, nodeid, anonymous=0):
117     def hasPermission(self, permission, classname=_marker):
119 class HTMLProperty(HTMLInputMixin, HTMLPermissions):
120     def __init__(self, client, classname, nodeid, prop, name, value,
121     def __repr__(self):
122     def __str__(self):
123     def __cmp__(self, other):
124     def is_edit_ok(self):
125     def is_view_ok(self):
127 class StringHTMLProperty(HTMLProperty):
128     def _hyper_repl(self, match):
129     def hyperlinked(self):
130     def plain(self, escape=0, hyperlink=0):
131     def stext(self, escape=0):
132     def field(self, size = 30):
133     def multiline(self, escape=0, rows=5, cols=40):
134     def email(self, escape=1):
136 class PasswordHTMLProperty(HTMLProperty):
137     def plain(self):
138     def field(self, size = 30):
139     def confirm(self, size = 30):
141 class NumberHTMLProperty(HTMLProperty):
142     def plain(self):
143     def field(self, size = 30):
144     def __int__(self):
145     def __float__(self):
147 class BooleanHTMLProperty(HTMLProperty):
148     def plain(self):
149     def field(self):
151 class DateHTMLProperty(HTMLProperty):
152     def plain(self):
153     def now(self):
154     def field(self, size = 30):
155     def reldate(self, pretty=1):
156     def pretty(self, format=_marker):
157     def local(self, offset):
159 class IntervalHTMLProperty(HTMLProperty):
160     def plain(self):
161     def pretty(self):
162     def field(self, size = 30):
164 class LinkHTMLProperty(HTMLProperty):
165     def __init__(self, *args, **kw):
166     def __getattr__(self, attr):
167     def plain(self, escape=0):
168     def field(self, showid=0, size=None):
169     def menu(self, size=None, height=None, showid=0, additional=[],
171 class MultilinkHTMLProperty(HTMLProperty):
172     def __init__(self, *args, **kwargs):
173     def __len__(self):
174     def __getattr__(self, attr):
175     def __getitem__(self, num):
176     def __contains__(self, value):
177     def reverse(self):
178     def plain(self, escape=0):
179     def field(self, size=30, showid=0):
180     def menu(self, size=None, height=None, showid=0, additional=[],
182 def make_sort_function(db, classname, sort_on=None):
183     def sortfunc(a, b):
185 def find_sort_key(linkcl):
187 def handleListCGIValue(value):
189 class ShowDict:
190     def __init__(self, columns):
191     def __getitem__(self, name):
193 class HTMLRequest(HTMLInputMixin):
194     def __init__(self, client):
195     def _post_init(self):
196     def updateFromURL(self, url):
197     def update(self, kwargs):
198     def description(self):
199     def __str__(self):
200     def indexargs_form(self, columns=1, sort=1, group=1, filter=1,
201     def indexargs_url(self, url, args):
202     def base_javascript(self):
203     def batch(self):
205 class Batch(ZTUtils.Batch):
206     def __init__(self, client, sequence, size, start, end=0, orphan=0,
207     def __getitem__(self, index):
208     def propchanged(self, property):
209     def previous(self):
210     def next(self):
212 class TemplatingUtils:
213     def __init__(self, client):
214     def Batch(self, sequence, size, start, end=0, orphan=0, overlap=0):
216 class NoTemplate(Exception):
217 class Unauthorised(Exception):
218     def __init__(self, action, klass):
219     def __str__(self):
220 def find_template(dir, name, extension):
222 class Templates:
223     def __init__(self, dir):
224     def precompileTemplates(self):
225     def get(self, name, extension=None):
226     def __getitem__(self, name):
228 class RoundupPageTemplate(PageTemplate.PageTemplate):
229     def getContext(self, client, classname, request):
230     def render(self, client, classname, request, **options):
231     def __repr__(self):
232 '''
235 def test_suite():
236     suite = unittest.TestSuite()
237     suite.addTest(unittest.makeSuite(HTMLDatabaseTestCase))
238     suite.addTest(unittest.makeSuite(FunctionsTestCase))
239     return suite
241 if __name__ == '__main__':
242     runner = unittest.TextTestRunner()
243     unittest.main(testRunner=runner)