Mercurial > p > roundup > code
comparison test/test_actions.py @ 3852:0dd05c9e5fff
New test for linking of non-existing and existing properties via a form.
The idea of the test is to track all create and set operations and
afterwards compare that they occurred as expected. Sorry for the
peculiar syntax for the expected updates to the database -- this should
be one line for each update...
An a bug-fix: I've reverted a change from April in
roundup/cgi/actions.py that broke linking of messages to issues. The
tests above now catch that. I couldn't figure out what the change was
meant for, sorry if I broke something here.
| author | Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net> |
|---|---|
| date | Tue, 08 May 2007 20:54:56 +0000 |
| parents | 53987aa153d2 |
| children | de4c2e538e06 |
comparison
equal
deleted
inserted
replaced
| 3851:5fe1f30f7f30 | 3852:0dd05c9e5fff |
|---|---|
| 223 self.assertEqual(username, 'foo') | 223 self.assertEqual(username, 'foo') |
| 224 self.client.opendb = opendb | 224 self.client.opendb = opendb |
| 225 | 225 |
| 226 self.assertLoginLeavesMessages([], 'foo', 'right') | 226 self.assertLoginLeavesMessages([], 'foo', 'right') |
| 227 | 227 |
| 228 class EditItemActionTestCase(ActionTestCase): | |
| 229 def setUp(self): | |
| 230 ActionTestCase.setUp(self) | |
| 231 self.result = [] | |
| 232 class AppendResult: | |
| 233 def __init__(inner_self, name): | |
| 234 inner_self.name = name | |
| 235 def __call__(inner_self, *args, **kw): | |
| 236 self.result.append((inner_self.name, args, kw)) | |
| 237 if inner_self.name == 'set': | |
| 238 return kw | |
| 239 return '17' | |
| 240 | |
| 241 self.client.db.security.hasPermission = true | |
| 242 self.client.classname = 'issue' | |
| 243 self.client.base = 'http://tracker/' | |
| 244 self.client.nodeid = '4711' | |
| 245 self.client.template = 'item' | |
| 246 self.client.db.classes.create = AppendResult('create') | |
| 247 self.client.db.classes.set = AppendResult('set') | |
| 248 self.client.db.classes.getprops = lambda: \ | |
| 249 ({'messages':hyperdb.Multilink('msg'), 'content':hyperdb.String()}) | |
| 250 self.action = EditItemAction(self.client) | |
| 251 | |
| 252 def testMessageAttach(self): | |
| 253 expect = \ | |
| 254 [ ('create',(),{'content':'t'}) | |
| 255 , ('set',('4711',), {'messages':['23','42','17']}) | |
| 256 ] | |
| 257 self.client.db.classes.get = lambda a, b:['23','42'] | |
| 258 self.client.parsePropsFromForm = lambda: \ | |
| 259 ( {('msg','-1'):{'content':'t'},('issue','4711'):{}} | |
| 260 , [('issue','4711','messages',[('msg','-1')])] | |
| 261 ) | |
| 262 try : | |
| 263 self.action.handle() | |
| 264 except Redirect, msg: | |
| 265 pass | |
| 266 self.assertEqual(expect, self.result) | |
| 267 | |
| 268 def testLinkExisting(self): | |
| 269 expect = [('set',('4711',),{'messages':['23','42','1']})] | |
| 270 self.client.db.classes.get = lambda a, b:['23','42'] | |
| 271 self.client.parsePropsFromForm = lambda: \ | |
| 272 ( {('issue','4711'):{},('msg','1'):{}} | |
| 273 , [('issue','4711','messages',[('msg','1')])] | |
| 274 ) | |
| 275 try : | |
| 276 self.action.handle() | |
| 277 except Redirect, msg: | |
| 278 pass | |
| 279 self.assertEqual(expect, self.result) | |
| 280 | |
| 228 def test_suite(): | 281 def test_suite(): |
| 229 suite = unittest.TestSuite() | 282 suite = unittest.TestSuite() |
| 230 suite.addTest(unittest.makeSuite(RetireActionTestCase)) | 283 suite.addTest(unittest.makeSuite(RetireActionTestCase)) |
| 231 suite.addTest(unittest.makeSuite(StandardSearchActionTestCase)) | 284 suite.addTest(unittest.makeSuite(StandardSearchActionTestCase)) |
| 232 suite.addTest(unittest.makeSuite(FakeFilterVarsTestCase)) | 285 suite.addTest(unittest.makeSuite(FakeFilterVarsTestCase)) |
| 233 suite.addTest(unittest.makeSuite(ShowActionTestCase)) | 286 suite.addTest(unittest.makeSuite(ShowActionTestCase)) |
| 234 suite.addTest(unittest.makeSuite(CollisionDetectionTestCase)) | 287 suite.addTest(unittest.makeSuite(CollisionDetectionTestCase)) |
| 235 suite.addTest(unittest.makeSuite(LoginTestCase)) | 288 suite.addTest(unittest.makeSuite(LoginTestCase)) |
| 289 suite.addTest(unittest.makeSuite(EditItemActionTestCase)) | |
| 236 return suite | 290 return suite |
| 237 | 291 |
| 238 if __name__ == '__main__': | 292 if __name__ == '__main__': |
| 239 runner = unittest.TextTestRunner() | 293 runner = unittest.TextTestRunner() |
| 240 unittest.main(testRunner=runner) | 294 unittest.main(testRunner=runner) |
