Skip to content

Commit 122d991

Browse files
committed
add basic crappy test framework for the client.py::Client::renderFrontPage() ::determine_context() and ::renderContext() methods.
1 parent ecf62e6 commit 122d991

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

test/test_cgi.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,94 @@ def testCSVExportFailPermission(self):
10851085
self.assertRaises(exceptions.SeriousError,
10861086
actions.ExportCSVAction(cl).handle)
10871087

1088+
class TemplateHtmlRendering(unittest.TestCase):
1089+
''' try to test the rendering code for tal '''
1090+
def setUp(self):
1091+
self.dirname = '_test_template'
1092+
# set up and open a tracker
1093+
self.instance = db_test_base.setupTracker(self.dirname)
1094+
1095+
# open the database
1096+
self.db = self.instance.open('admin')
1097+
self.db.tx_Source = "web"
1098+
self.db.user.create(username='Chef', address='[email protected]',
1099+
realname='Bork, Chef', roles='User')
1100+
self.db.user.create(username='mary', address='[email protected]',
1101+
roles='User', realname='Contrary, Mary')
1102+
self.db.post_init()
1103+
1104+
# create a client instance and hijack write_html
1105+
self.client = client.Client(self.instance, "user",
1106+
{'PATH_INFO':'/user', 'REQUEST_METHOD':'POST'},
1107+
form=makeForm({"@template": "item"}))
1108+
1109+
self.client._error_message = []
1110+
self.client._ok_message = []
1111+
self.client.db = self.db
1112+
self.client.userid = '1'
1113+
self.client.language = ('en',)
1114+
1115+
self.output = []
1116+
# ugly hack to get html_write to return data here.
1117+
def html_write(s):
1118+
self.output.append(s)
1119+
1120+
# hijack html_write
1121+
self.client.write_html = html_write
1122+
1123+
self.db.issue.create(title='foo')
1124+
1125+
def tearDown(self):
1126+
self.db.close()
1127+
try:
1128+
shutil.rmtree(self.dirname)
1129+
except OSError, error:
1130+
if error.errno not in (errno.ENOENT, errno.ESRCH): raise
1131+
1132+
def testrenderFrontPage(self):
1133+
self.client.renderFrontPage("hello world RaNdOmJunk")
1134+
# make sure we can find the "hello world RaNdOmJunk"
1135+
# message in the output.
1136+
self.assertNotEqual(-1,
1137+
self.output[0].index('<p class="error-message">hello world RaNdOmJunk <br/ > </p>'))
1138+
# make sure we can find issue 1 title foo in the output
1139+
self.assertNotEqual(-1,
1140+
self.output[0].index('<a href="issue1">foo</a>'))
1141+
1142+
# make sure we can find the last SHA1 sum line at the end of the
1143+
# page
1144+
self.assertNotEqual(-1,
1145+
self.output[0].index('<!-- SHA: c87a4e18d59a527331f1d367c0c6cc67ee123e63 -->'))
1146+
1147+
def testrenderContext(self):
1148+
# set up the client;
1149+
# run determine_context to set the required client attributes
1150+
# run renderContext(); check result for proper page
1151+
1152+
# this will generate the default home page like
1153+
# testrenderFrontPage
1154+
self.client.form=makeForm({})
1155+
self.client.path = ''
1156+
self.client.determine_context()
1157+
self.assertEqual((self.client.classname, self.client.template, self.client.nodeid), (None, '', None))
1158+
self.assertEqual(self.client._ok_message, [])
1159+
1160+
result = self.client.renderContext()
1161+
self.assertNotEqual(-1,
1162+
result.index('<!-- SHA: c87a4e18d59a527331f1d367c0c6cc67ee123e63 -->'))
1163+
1164+
# now look at the user index page
1165+
self.client.form=makeForm({ "@ok_message": "ok message", "@template": "index"})
1166+
self.client.path = 'user'
1167+
self.client.determine_context()
1168+
self.assertEqual((self.client.classname, self.client.template, self.client.nodeid), ('user', 'index', None))
1169+
self.assertEqual(self.client._ok_message, ['ok message'])
1170+
1171+
result = self.client.renderContext()
1172+
self.assertNotEqual(-1, result.index('<title>User listing - Roundup issue tracker</title>'))
1173+
self.assertNotEqual(-1, result.index('ok message'))
1174+
# print result
1175+
10881176
class TemplateTestCase(unittest.TestCase):
10891177
''' Test the template resolving code, i.e. what can be given to @template
10901178
'''

0 commit comments

Comments
 (0)