server/test/unittest_repository.py
branchstable
changeset 6385 9f91d09ee5fa
parent 6364 ad9ed9803eb6
child 6401 d7f5d873e1b8
equal deleted inserted replaced
6383:19ebe0b994d6 6385:9f91d09ee5fa
    30 from logilab.common.testlib import TestCase, unittest_main
    30 from logilab.common.testlib import TestCase, unittest_main
    31 
    31 
    32 from yams.constraints import UniqueConstraint
    32 from yams.constraints import UniqueConstraint
    33 
    33 
    34 from cubicweb import (BadConnectionId, RepositoryError, ValidationError,
    34 from cubicweb import (BadConnectionId, RepositoryError, ValidationError,
    35                       UnknownEid, AuthenticationError, Unauthorized)
    35                       UnknownEid, AuthenticationError, Unauthorized, QueryError)
    36 from cubicweb.selectors import is_instance
    36 from cubicweb.selectors import is_instance
    37 from cubicweb.schema import CubicWebSchema, RQLConstraint
    37 from cubicweb.schema import CubicWebSchema, RQLConstraint
    38 from cubicweb.dbapi import connect, multiple_connections_unfix
    38 from cubicweb.dbapi import connect, multiple_connections_unfix
    39 from cubicweb.devtools.testlib import CubicWebTC
    39 from cubicweb.devtools.testlib import CubicWebTC
    40 from cubicweb.devtools.repotest import tuplify
    40 from cubicweb.devtools.repotest import tuplify
   152             def __call__(self):
   152             def __call__(self):
   153                 raise ValidationError(self.entity.eid, {})
   153                 raise ValidationError(self.entity.eid, {})
   154         with self.temporary_appobjects(ValidationErrorAfterHook):
   154         with self.temporary_appobjects(ValidationErrorAfterHook):
   155             self.assertRaises(ValidationError,
   155             self.assertRaises(ValidationError,
   156                               self.execute, 'SET X name "toto" WHERE X is CWGroup, X name "guests"')
   156                               self.execute, 'SET X name "toto" WHERE X is CWGroup, X name "guests"')
       
   157             self.failUnless(self.execute('Any X WHERE X is CWGroup, X name "toto"'))
       
   158             ex = self.assertRaises(QueryError, self.commit)
       
   159             self.assertEqual(str(ex), 'transaction must be rollbacked')
       
   160             self.rollback()
   157             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"'))
   158 
   162 
   159     def test_rollback_on_execute_unauthorized(self):
   163     def test_rollback_on_execute_unauthorized(self):
   160         class UnauthorizedAfterHook(Hook):
   164         class UnauthorizedAfterHook(Hook):
   161             __regid__ = 'unauthorized-after-hook'
   165             __regid__ = 'unauthorized-after-hook'
   164             def __call__(self):
   168             def __call__(self):
   165                 raise Unauthorized()
   169                 raise Unauthorized()
   166         with self.temporary_appobjects(UnauthorizedAfterHook):
   170         with self.temporary_appobjects(UnauthorizedAfterHook):
   167             self.assertRaises(Unauthorized,
   171             self.assertRaises(Unauthorized,
   168                               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"')
       
   173             self.failUnless(self.execute('Any X WHERE X is CWGroup, X name "toto"'))
       
   174             ex = self.assertRaises(QueryError, self.commit)
       
   175             self.assertEqual(str(ex), 'transaction must be rollbacked')
       
   176             self.rollback()
   169             self.failIf(self.execute('Any X WHERE X is CWGroup, X name "toto"'))
   177             self.failIf(self.execute('Any X WHERE X is CWGroup, X name "toto"'))
   170 
   178 
   171 
   179 
   172     def test_close(self):
   180     def test_close(self):
   173         repo = self.repo
   181         repo = self.repo