Projet

Général

Profil

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

root / tests / test_admin_pages.py @ fd36f89b

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.categories import Category
17
from wcs.roles import Role
18
from wcs.workflows import Workflow
19
from wcs.formdef import FormDef
20
from wcs import fields
21

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

    
24

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

    
28
    global pub
29

    
30
    pub = create_temporary_pub()
31

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

    
37

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

    
41

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

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

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

    
63

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

    
70

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

    
74

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

    
79

    
80
def test_with_superuser():
81
    create_superuser()
82
    app = login(get_app(pub))
83
    # this makes sure the extension loaded properly
84
    resp = app.get('/backoffice/settings/texts/aq-home-page', status=200)
(2-2/5)