Mercurial > p > roundup > code
comparison test/test_cgi.py @ 5160:f8a32b7331f1
add basic crappy test framework for the client.py::Client::renderFrontPage() ::determine_context() and ::renderContext() methods.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 22 Jul 2016 20:59:44 -0400 |
| parents | 7fb697267fdb |
| children | 12190efa30d4 |
comparison
equal
deleted
inserted
replaced
| 5159:7fb697267fdb | 5160:f8a32b7331f1 |
|---|---|
| 1083 # used to be self.assertRaises(exceptions.Unauthorised, | 1083 # used to be self.assertRaises(exceptions.Unauthorised, |
| 1084 # but not acting like the column name is not found | 1084 # but not acting like the column name is not found |
| 1085 self.assertRaises(exceptions.SeriousError, | 1085 self.assertRaises(exceptions.SeriousError, |
| 1086 actions.ExportCSVAction(cl).handle) | 1086 actions.ExportCSVAction(cl).handle) |
| 1087 | 1087 |
| 1088 class TemplateTestCase(unittest.TestCase): | 1088 class TemplateHtmlRendering(unittest.TestCase): |
| 1089 ''' Test the template resolving code, i.e. what can be given to @template | 1089 ''' try to test the rendering code for tal ''' |
| 1090 ''' | |
| 1091 def setUp(self): | 1090 def setUp(self): |
| 1092 self.dirname = '_test_template' | 1091 self.dirname = '_test_template' |
| 1093 # set up and open a tracker | 1092 # set up and open a tracker |
| 1094 self.instance = db_test_base.setupTracker(self.dirname) | 1093 self.instance = db_test_base.setupTracker(self.dirname) |
| 1095 | 1094 |
| 1100 realname='Bork, Chef', roles='User') | 1099 realname='Bork, Chef', roles='User') |
| 1101 self.db.user.create(username='mary', address='mary@test.test', | 1100 self.db.user.create(username='mary', address='mary@test.test', |
| 1102 roles='User', realname='Contrary, Mary') | 1101 roles='User', realname='Contrary, Mary') |
| 1103 self.db.post_init() | 1102 self.db.post_init() |
| 1104 | 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 | |
| 1176 class TemplateTestCase(unittest.TestCase): | |
| 1177 ''' Test the template resolving code, i.e. what can be given to @template | |
| 1178 ''' | |
| 1179 def setUp(self): | |
| 1180 self.dirname = '_test_template' | |
| 1181 # set up and open a tracker | |
| 1182 self.instance = db_test_base.setupTracker(self.dirname) | |
| 1183 | |
| 1184 # open the database | |
| 1185 self.db = self.instance.open('admin') | |
| 1186 self.db.tx_Source = "web" | |
| 1187 self.db.user.create(username='Chef', address='chef@bork.bork.bork', | |
| 1188 realname='Bork, Chef', roles='User') | |
| 1189 self.db.user.create(username='mary', address='mary@test.test', | |
| 1190 roles='User', realname='Contrary, Mary') | |
| 1191 self.db.post_init() | |
| 1192 | |
| 1105 def tearDown(self): | 1193 def tearDown(self): |
| 1106 self.db.close() | 1194 self.db.close() |
| 1107 try: | 1195 try: |
| 1108 shutil.rmtree(self.dirname) | 1196 shutil.rmtree(self.dirname) |
| 1109 except OSError, error: | 1197 except OSError, error: |
