152 raise ValidationError(self.entity.eid, {}) |
152 raise ValidationError(self.entity.eid, {}) |
153 with self.temporary_appobjects(ValidationErrorAfterHook): |
153 with self.temporary_appobjects(ValidationErrorAfterHook): |
154 self.assertRaises(ValidationError, |
154 self.assertRaises(ValidationError, |
155 self.execute, 'SET X name "toto" WHERE X is CWGroup, X name "guests"') |
155 self.execute, 'SET X name "toto" WHERE X is CWGroup, X name "guests"') |
156 self.failUnless(self.execute('Any X WHERE X is CWGroup, X name "toto"')) |
156 self.failUnless(self.execute('Any X WHERE X is CWGroup, X name "toto"')) |
157 ex = self.assertRaises(QueryError, self.commit) |
157 with self.assertRaises(QueryError) as cm: |
158 self.assertEqual(str(ex), 'transaction must be rollbacked') |
158 self.commit() |
|
159 self.assertEqual(str(cm.exception), 'transaction must be rollbacked') |
159 self.rollback() |
160 self.rollback() |
160 self.failIf(self.execute('Any X WHERE X is CWGroup, X name "toto"')) |
161 self.failIf(self.execute('Any X WHERE X is CWGroup, X name "toto"')) |
161 |
162 |
162 def test_rollback_on_execute_unauthorized(self): |
163 def test_rollback_on_execute_unauthorized(self): |
163 class UnauthorizedAfterHook(Hook): |
164 class UnauthorizedAfterHook(Hook): |
168 raise Unauthorized() |
169 raise Unauthorized() |
169 with self.temporary_appobjects(UnauthorizedAfterHook): |
170 with self.temporary_appobjects(UnauthorizedAfterHook): |
170 self.assertRaises(Unauthorized, |
171 self.assertRaises(Unauthorized, |
171 self.execute, 'SET X name "toto" WHERE X is CWGroup, X name "guests"') |
172 self.execute, 'SET X name "toto" WHERE X is CWGroup, X name "guests"') |
172 self.failUnless(self.execute('Any X WHERE X is CWGroup, X name "toto"')) |
173 self.failUnless(self.execute('Any X WHERE X is CWGroup, X name "toto"')) |
173 ex = self.assertRaises(QueryError, self.commit) |
174 with self.assertRaises(QueryError) as cm: |
174 self.assertEqual(str(ex), 'transaction must be rollbacked') |
175 self.commit() |
|
176 self.assertEqual(str(cm.exception), 'transaction must be rollbacked') |
175 self.rollback() |
177 self.rollback() |
176 self.failIf(self.execute('Any X WHERE X is CWGroup, X name "toto"')) |
178 self.failIf(self.execute('Any X WHERE X is CWGroup, X name "toto"')) |
177 |
179 |
178 |
180 |
179 def test_close(self): |
181 def test_close(self): |
274 t.start() |
276 t.start() |
275 def run_transaction(): |
277 def run_transaction(): |
276 repo.execute(cnxid, 'DELETE CWUser X WHERE X login "toto"') |
278 repo.execute(cnxid, 'DELETE CWUser X WHERE X login "toto"') |
277 repo.commit(cnxid) |
279 repo.commit(cnxid) |
278 try: |
280 try: |
279 ex = self.assertRaises(Exception, run_transaction) |
281 with self.assertRaises(Exception) as cm: |
280 self.assertEqual(str(ex), 'try to access pool on a closed session') |
282 run_transaction() |
|
283 self.assertEqual(str(cm.exception), 'try to access pool on a closed session') |
281 finally: |
284 finally: |
282 t.join() |
285 t.join() |
283 |
286 |
284 def test_initial_schema(self): |
287 def test_initial_schema(self): |
285 schema = self.repo.schema |
288 schema = self.repo.schema |
666 req = self.request() |
669 req = self.request() |
667 req.create_entity('Note', type=u'todo', inline1=a01) |
670 req.create_entity('Note', type=u'todo', inline1=a01) |
668 req.cnx.commit() |
671 req.cnx.commit() |
669 req = self.request() |
672 req = self.request() |
670 req.create_entity('Note', type=u'todo', inline1=a01) |
673 req.create_entity('Note', type=u'todo', inline1=a01) |
671 ex = self.assertRaises(ValidationError, req.cnx.commit) |
674 with self.assertRaises(ValidationError) as cm: |
672 self.assertEqual(ex.errors, {'inline1-subject': u'RQLUniqueConstraint S type T, S inline1 A1, A1 todo_by C, Y type T, Y inline1 A2, A2 todo_by C failed'}) |
675 req.cnx.commit() |
|
676 self.assertEqual(cm.exception.errors, {'inline1-subject': u'RQLUniqueConstraint S type T, S inline1 A1, A1 todo_by C, Y type T, Y inline1 A2, A2 todo_by C failed'}) |
673 |
677 |
674 if __name__ == '__main__': |
678 if __name__ == '__main__': |
675 unittest_main() |
679 unittest_main() |