Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / tests / functional / test_userutils.py @ d3c47597

History | View | Annotate | Download (2.74 KB)

1
# -*- coding: utf-8 -*-
2
# vim:set expandtab tabstop=4 shiftwidth=4:
3
"""
4
Test de la classe User Utils
5
"""
6
from nose.tools import assert_true
7

    
8
from vigiboard.model import DBSession, Groups, Permission, \
9
        GroupPermissions
10
from vigiboard.tests import TestController
11
from vigiboard.controllers.userutils import get_user_groups
12
from vigiboard.tests import teardown_db
13
import tg
14
import transaction
15
from nose.plugins.skip import SkipTest
16

    
17
class TestUserUtils(TestController):
18
    """Test de la classe User Utils"""
19
    
20
#    def tearDown(self):
21
#        """TearDown methode for Nose"""
22

    
23
#        DBSession.rollback()
24
#        teardown_db()
25
#        transaction.begin() 
26

    
27
    def test_get_user_groups(self):
28
        """
29
        Manager est dans le group hostmanagers et hosteditors
30
        et Editor seulement dans hosteditors
31
        """
32

    
33
        # XXX This test has some issues, skip it until it gets fixed.
34
        raise SkipTest
35
        
36
        # On commence par peupler la base
37
        
38
        DBSession.add(Groups(name = "hostmanagers"))
39
        DBSession.add(Groups(name = "hosteditors", parent="hostmanagers"))
40
        DBSession.query(Permission).filter(
41
            Permission.permission_name == u'manage')[0].idpermission
42
        idmanagers = DBSession.query(Permission).filter(
43
                Permission.permission_name == u'manage')[0].idpermission
44
        ideditors = DBSession.query(Permission
45
                ).filter(Permission.permission_name == u'edit')[0].idpermission
46
        DBSession.add(GroupPermissions(groupname = "hostmanagers",
47
                idpermission = idmanagers))
48
        DBSession.add(GroupPermissions(groupname = "hosteditors",
49
                idpermission = ideditors))
50

    
51
        # On commit car app.get fait un rollback ou équivalent
52
        
53
        transaction.commit()        
54
        
55
        # On obtient les variables de sessions comme si on était loggué
56
        # en tant que manager
57

    
58
        environ = {'REMOTE_USER': u'manager'}
59
        response = self.app.get('/', extra_environ=environ)
60
        tg.request = response.request
61
        
62
        # On récupère la liste des groups auquel on appartient
63
        
64
        grp = get_user_groups()
65

    
66
        # On vérifi que la liste est correcte (vérifi la gestion des
67
        # groupes sous forme d'arbre)
68
        
69
        assert_true( 'hostmanagers' in grp and 'hosteditors' in grp ,
70
            msg = "il est dans %s" % grp)
71
        
72
        # On recommence pour l'utilisateur editor
73
        
74
        environ = {'REMOTE_USER': u'editor'}
75
        response = self.app.get('/', extra_environ=environ)
76
        tg.request = response.request
77
        
78
        grp = get_user_groups()
79
        
80
        assert_true( not('hostmanagers' in grp) and 'hosteditors' in grp,
81
            msg = "il est dans %s" % grp)