Projet

Général

Profil

Télécharger (1,99 ko) Statistiques
| Branche: | Tag: | Révision:

root / tests / test_admin_pages.py @ a485f930

1
import os
2
import shutil
3
import time
4

    
5
try:
6
    import lasso
7
except ImportError:
8
    lasso = None
9

    
10
import pytest
11

    
12
from quixote import cleanup, get_publisher
13
from wcs.qommon import errors, sessions
14
from wcs.qommon.ident.password_accounts import PasswordAccount
15
from wcs.qommon.http_request import HTTPRequest
16
from wcs.qommon.template import get_current_theme
17
from wcs.categories import Category
18
from wcs.roles import Role
19
from wcs.workflows import Workflow
20
from wcs.formdef import FormDef
21
from wcs import fields
22

    
23
from utilities import get_app, login, create_temporary_pub, clean_temporary_pub
24

    
25

    
26
def setup_module(module):
27
    cleanup()
28

    
29
    global pub
30

    
31
    pub = create_temporary_pub()
32

    
33
    req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
34
    pub.set_app_dir(req)
35
    pub.cfg['identification'] = {'methods': ['password']}
36
    pub.write_cfg()
37

    
38

    
39
def teardown_module(module):
40
    clean_temporary_pub()
41

    
42

    
43
def create_superuser():
44
    global user1
45
    if pub.user_class.get_users_with_name_identifier('admin'):
46
        user1 = pub.user_class.get_users_with_name_identifier('admin')[0]
47
        user1.is_admin = True
48
        user1.roles = []
49
        return
50
    user1 = pub.user_class(name='admin')
51
    user1.is_admin = True
52
    user1.name_identifiers = ['admin']
53
    user1.roles = []
54
    user1.store()
55

    
56
    account1 = PasswordAccount(id='admin')
57
    account1.set_password('admin')
58
    account1.user_id = user1.id
59
    account1.store()
60

    
61
    pub.cfg['identification'] = {'methods': ['password']}
62
    pub.write_cfg()
63

    
64

    
65
def create_role():
66
    Role.wipe()
67
    role = Role(name='foobar')
68
    role.store()
69
    return role
70

    
71

    
72
def teardown_module(module):
73
    shutil.rmtree(pub.APP_DIR)
74

    
75

    
76
@pytest.fixture
77
def empty_siteoptions():
78
    open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w').close()
79

    
80

    
81
def test_with_superuser():
82
    create_superuser()
83
    app = login(get_app(pub))
84
    resp = app.get('/backoffice/studio/')
85
    # this makes sure the extension loaded properly
86
    assert '<span id="applabel">Publik</span>' in resp.text
(2-2/5)