[Cubicweb] CubicWebTC / assertRaises / Unauthorized

Sylvain Thénault sylvain.thenault at logilab.fr
Mon Aug 16 21:29:47 CEST 2010


On 16 août 11:24, Carlos Balderas wrote:
> Hi List!

Hi Carlos,
 
> I am working on unnitest for a cube, especially testing users permissions .
> 
> I want to test an 'Unauthorized' error using this:
> 
> # rql update sentence, this query must fail
> rql = 'SET C description "description test" WHERE ....'
> 
> if I execute the rql as this:
> rset = req.execute(rql)
> 
> When I run the test this is what I get:
> Unauthorized: You are not allowed to perform update operation on ...
> 
> (so, the error shows as it should)
> 
> but exception does no raise if I use assertRaises method:
> 
> rql = 'SET C description "description test" WHERE ....'
> self.assertRaises(Unauthorized, req.execute, rql)
> 
> this is what i get:
> AssertionError: Unauthorized not raised

huum, I suspect there is something different in the two queries... There is no reason
explaining that

   req.execute(rql) # raise Unauthorized
   self.assertRaises(Unauthorized, req.execute, rql) # assertion error
   
> My first question
> 
> 1.- what am I missing to make this exception raise and let it be caught by
> assertRaises method?

As I said, I suspect something not in this mail :) Copy and paste the
whole test code if you want more eyes to check it.

> 2.- would this be a good method to test cubicweb users permissions or do you
> recommend me another one for this purpose?

Yup
 
-- 
Sylvain Thénault                               LOGILAB, Paris (France)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org




More information about the Cubicweb mailing list