1 |
25697df1
|
Frédéric Péters
|
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 |
3e037e2e
|
Frédéric Péters
|
from wcs.qommon.ident.password_accounts import PasswordAccount
|
15 |
25697df1
|
Frédéric Péters
|
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 |
a485f930
|
Frédéric Péters
|
from utilities import get_app, login, create_temporary_pub, clean_temporary_pub
|
23 |
25697df1
|
Frédéric Péters
|
|
24 |
2663e08e
|
Frédéric Péters
|
|
25 |
25697df1
|
Frédéric Péters
|
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 |
2663e08e
|
Frédéric Péters
|
|
38 |
a485f930
|
Frédéric Péters
|
def teardown_module(module):
|
39 |
|
|
clean_temporary_pub()
|
40 |
|
|
|
41 |
|
|
|
42 |
25697df1
|
Frédéric Péters
|
def create_superuser():
|
43 |
|
|
global user1
|
44 |
a485f930
|
Frédéric Péters
|
if pub.user_class.get_users_with_name_identifier('admin'):
|
45 |
|
|
user1 = pub.user_class.get_users_with_name_identifier('admin')[0]
|
46 |
c8b78b6f
|
Frédéric Péters
|
user1.is_admin = True
|
47 |
|
|
user1.roles = []
|
48 |
25697df1
|
Frédéric Péters
|
return
|
49 |
|
|
user1 = pub.user_class(name='admin')
|
50 |
|
|
user1.is_admin = True
|
51 |
a485f930
|
Frédéric Péters
|
user1.name_identifiers = ['admin']
|
52 |
c8b78b6f
|
Frédéric Péters
|
user1.roles = []
|
53 |
25697df1
|
Frédéric Péters
|
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 |
2663e08e
|
Frédéric Péters
|
|
64 |
25697df1
|
Frédéric Péters
|
def create_role():
|
65 |
|
|
Role.wipe()
|
66 |
|
|
role = Role(name='foobar')
|
67 |
|
|
role.store()
|
68 |
|
|
return role
|
69 |
|
|
|
70 |
2663e08e
|
Frédéric Péters
|
|
71 |
25697df1
|
Frédéric Péters
|
def teardown_module(module):
|
72 |
|
|
shutil.rmtree(pub.APP_DIR)
|
73 |
|
|
|
74 |
2663e08e
|
Frédéric Péters
|
|
75 |
80784d04
|
Frédéric Péters
|
@pytest.fixture
|
76 |
|
|
def empty_siteoptions():
|
77 |
|
|
open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w').close()
|
78 |
|
|
|
79 |
2663e08e
|
Frédéric Péters
|
|
80 |
25697df1
|
Frédéric Péters
|
def test_with_superuser():
|
81 |
|
|
create_superuser()
|
82 |
|
|
app = login(get_app(pub))
|
83 |
3c9126b5
|
Frédéric Péters
|
# this makes sure the extension loaded properly
|
84 |
fd36f89b
|
Frédéric Péters
|
resp = app.get('/backoffice/settings/texts/aq-home-page', status=200)
|