Commit 0f5beb65 authored by Marc Duez's avatar Marc Duez

server test : group.py test file

parent c76182f3
#!/usr/bin/python
import unittest
from gluon.globals import Request, Session, Storage, Response
from gluon.tools import Auth
from gluon.contrib.test_helpers import form_postvars
from gluon import current
class GroupController(unittest.TestCase):
def __init__(self, p):
global auth, session, request
unittest.TestCase.__init__(self, p)
def setUp(self):
# Load the to-be-tested file
execfile("applications/vidjil/controllers/group.py", globals())
# set up default session/request/auth/...
global response, session, request, auth
session = Session()
request = Request({})
auth = Auth(globals(), db)
auth.login_bare("test@vidjil.org", "1234")
# rewrite info / error functions
# for some reasons we lost them between the testRunner and the testCase but we need them to avoid error so ...
def f(a):
pass
log.info = f
log.error = f
log.debug = f
# for defs
current.db = db
current.auth = auth
def testIndex(self):
resp = index()
self.assertTrue(resp.has_key('message'), "index() has returned an incomplete response")
def testAdd(self):
resp = add()
self.assertTrue(resp.has_key('message'), "add() has returned an incomplete response")
def test1AddForm(self):
request.vars["group_name"] = "test_group_1"
request.vars["info"] = "test_group_1"
resp = add_form()
self.assertTrue(auth.has_membership("test_group_1"), "group creation failed")
def testConfirm(self):
resp = confirm()
self.assertTrue(resp.has_key('message'), "confirm() has returned an incomplete response")
def test9Delete(self):
group_id = db( db.auth_group.role == "test_group_1").select()[0].id
request.vars["id"] = group_id
resp = delete()
self.assertNotEqual(resp.find('"message":"group deleted"'), -1, "group have been deleted")
self.assertTrue(db.auth_group[group_id] == None , "group have been deleted")
def testInfo(self):
resp = info()
self.assertTrue(resp.has_key('message'), "info() has returned an incomplete response")
def testPermission(self):
resp = permission()
self.assertTrue(resp.has_key('message'), "permission() has returned an incomplete response")
def test2RemovePermission(self):
group_id = db( db.auth_group.role == "test_group_1").select()[0].id
request.vars["user_id"] = user_id
request.vars["group_id"] = group_id
resp = remove_permission()
auth.has_permission('admin', 'auth_group', group_id)
def test3ChangePermission(self):
group_id = db( db.auth_group.role == "test_group_1").select()[0].id
request.vars["user_id"] = user_id
request.vars["group_id"] = group_id
resp = change_permission()
auth.has_permission('admin', 'auth_group', group_id)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment