auth_permission at Unittest

25 views
Skip to first unread message

Pedro Henrique Correa Ferreira

unread,
Nov 3, 2014, 7:32:47 AM11/3/14
to web...@googlegroups.com
Hello, buddies

I'd like to know how can I run a Unittest in a fuction that requires permission. 

The function is the following: 
@auth.requires_permission('accessible', URL(request.controller,'pessoa'))
def pessoa():
    print URL(request.controller,'pessoa')
    grid = SQLFORM.grid(db.pessoa, formstyle = 'bootstrap')
    form=SQLFORM(db.pessoa).process()
    return locals()

While the unittest code is: 

# coding: utf8
import unittest, types
from gluon.globals import Request
from gluon.storage import Storage
execfile("applications/novo/controllers/plugin_00030_crm.py", globals()) 
class testPessoa(unittest.TestCase):
def setUp(self):
request = Request({})
auth.user = Storage(dict(id=1))
  def testPessoa(self):
resp = pessoa()
        self.assertEquals(True, isinstance(resp, types.DictType))
        self.assertEquals(True, "grid" in resp.keys())
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(testPessoa))
unittest.TextTestRunner(verbosity=2).run(suite)




I've entered in the db table "auth_permission" and created the following record: 

group_id: "ADMINISTRADOR (1)"
name: "accessible"
Object or table name: "/novo/plugin_00030_crm/pessoa"
Record id: "0"

It was supposed to work, but still returning HTTP 303. 

How do I fix this?

Sorry if this is a duplicated post.

Cheers,

Pedro. 

Pedro Henrique Correa Ferreira

unread,
Nov 3, 2014, 11:34:45 AM11/3/14
to web...@googlegroups.com
Already tried login_bare too... still not working... 
Reply all
Reply to author
Forward
0 new messages