Skip to content

Commit 5abcf9e

Browse files
author
Richard Jones
committed
start at templating tests
1 parent 44fd451 commit 5abcf9e

File tree

2 files changed

+248
-2
lines changed

2 files changed

+248
-2
lines changed

test/test_actions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class MockNull:
1212
def __init__(self, **kwargs):
1313
for key, value in kwargs.items():
14-
setattr(self, key, value)
14+
self.__dict__[key] = value
1515

1616
def __call__(self, *args, **kwargs): return MockNull()
1717
def __getattr__(self, name):
@@ -21,12 +21,13 @@ def __getattr__(self, name):
2121
# For example (with just 'client' defined):
2222
#
2323
# client.db.config.TRACKER_WEB = 'BASE/'
24-
setattr(self, name, MockNull())
24+
self.__dict__[name] = MockNull()
2525
return getattr(self, name)
2626

2727
def __getitem__(self, key): return self
2828
def __nonzero__(self): return 0
2929
def __str__(self): return ''
30+
def __repr__(self): return '<MockNull 0x%x>'%id(self)
3031

3132
def true(*args, **kwargs):
3233
return 1
@@ -196,3 +197,4 @@ def test_suite():
196197
if __name__ == '__main__':
197198
runner = unittest.TextTestRunner()
198199
unittest.main(testRunner=runner)
200+

test/test_templating.py

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
import unittest
2+
from cgi import FieldStorage, MiniFieldStorage
3+
4+
from roundup.cgi.templating import *
5+
from test_actions import MockNull, true
6+
7+
class MockDatabase(MockNull):
8+
def getclass(self, name):
9+
return self.classes[name]
10+
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
17+
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))
25+
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))
32+
33+
def test_HTMLDatabase_classes(self):
34+
db = HTMLDatabase(self.client)
35+
db._db.classes = {'issue':MockNull(), 'user': MockNull()}
36+
db.classes()
37+
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'])
53+
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'])
64+
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):
72+
73+
def input_html4(**attrs):
74+
def input_xhtml(**attrs):
75+
76+
class HTMLInputMixin:
77+
def __init__(self):
78+
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):
95+
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):
107+
108+
class HTMLUserPermission:
109+
def is_edit_ok(self):
110+
def is_view_ok(self):
111+
def _user_perm_check(self, type):
112+
113+
class HTMLUserClass(HTMLUserPermission, HTMLClass):
114+
115+
class HTMLUser(HTMLUserPermission, HTMLItem):
116+
def __init__(self, client, classname, nodeid, anonymous=0):
117+
def hasPermission(self, permission, classname=_marker):
118+
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):
126+
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):
135+
136+
class PasswordHTMLProperty(HTMLProperty):
137+
def plain(self):
138+
def field(self, size = 30):
139+
def confirm(self, size = 30):
140+
141+
class NumberHTMLProperty(HTMLProperty):
142+
def plain(self):
143+
def field(self, size = 30):
144+
def __int__(self):
145+
def __float__(self):
146+
147+
class BooleanHTMLProperty(HTMLProperty):
148+
def plain(self):
149+
def field(self):
150+
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):
158+
159+
class IntervalHTMLProperty(HTMLProperty):
160+
def plain(self):
161+
def pretty(self):
162+
def field(self, size = 30):
163+
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=[],
170+
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=[],
181+
182+
def make_sort_function(db, classname, sort_on=None):
183+
def sortfunc(a, b):
184+
185+
def find_sort_key(linkcl):
186+
187+
def handleListCGIValue(value):
188+
189+
class ShowDict:
190+
def __init__(self, columns):
191+
def __getitem__(self, name):
192+
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):
204+
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):
211+
212+
class TemplatingUtils:
213+
def __init__(self, client):
214+
def Batch(self, sequence, size, start, end=0, orphan=0, overlap=0):
215+
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):
221+
222+
class Templates:
223+
def __init__(self, dir):
224+
def precompileTemplates(self):
225+
def get(self, name, extension=None):
226+
def __getitem__(self, name):
227+
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+
'''
233+
234+
235+
def test_suite():
236+
suite = unittest.TestSuite()
237+
suite.addTest(unittest.makeSuite(HTMLDatabaseTestCase))
238+
suite.addTest(unittest.makeSuite(FunctionsTestCase))
239+
return suite
240+
241+
if __name__ == '__main__':
242+
runner = unittest.TextTestRunner()
243+
unittest.main(testRunner=runner)
244+

0 commit comments

Comments
 (0)