1
|
import os
|
2
|
import shutil
|
3
|
import time
|
4
|
|
5
|
import pytest
|
6
|
|
7
|
from quixote import cleanup, get_publisher
|
8
|
from wcs.qommon import errors, sessions
|
9
|
from wcs.qommon.ident.password_accounts import PasswordAccount
|
10
|
from wcs.qommon.http_request import HTTPRequest
|
11
|
from wcs.qommon.template import get_current_theme
|
12
|
from wcs.categories import Category
|
13
|
from wcs.workflows import Workflow
|
14
|
from wcs.formdef import FormDef
|
15
|
from wcs import fields
|
16
|
|
17
|
from utilities import get_app, login, create_temporary_pub, clean_temporary_pub
|
18
|
|
19
|
|
20
|
def setup_module(module):
|
21
|
cleanup()
|
22
|
|
23
|
global pub
|
24
|
|
25
|
pub = create_temporary_pub()
|
26
|
|
27
|
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
|
28
|
pub.set_app_dir(req)
|
29
|
pub.cfg['identification'] = {'methods': ['password']}
|
30
|
pub.write_cfg()
|
31
|
|
32
|
|
33
|
def teardown_module(module):
|
34
|
clean_temporary_pub()
|
35
|
|
36
|
|
37
|
def create_agent():
|
38
|
if pub.user_class.get_users_with_name_identifier('agent'):
|
39
|
return pub.user_class.get_users_with_name_identifier('agent')[0]
|
40
|
user1 = pub.user_class(name='agent')
|
41
|
user1.name_identifiers = ['agent']
|
42
|
user1.is_admin = False
|
43
|
user1.store()
|
44
|
|
45
|
account1 = PasswordAccount(id='agent')
|
46
|
account1.set_password('agent')
|
47
|
account1.user_id = user1.id
|
48
|
account1.store()
|
49
|
|
50
|
pub.cfg['identification'] = {'methods': ['password']}
|
51
|
pub.write_cfg()
|
52
|
|
53
|
return user1
|
54
|
|
55
|
|
56
|
def create_role():
|
57
|
pub.role_class.wipe()
|
58
|
role = pub.role_class(name='foobar')
|
59
|
role.allows_backoffice_access = True
|
60
|
role.store()
|
61
|
return role
|
62
|
|
63
|
|
64
|
def teardown_module(module):
|
65
|
shutil.rmtree(pub.APP_DIR)
|
66
|
|
67
|
|
68
|
def test_with_agent():
|
69
|
user = create_agent()
|
70
|
app = login(get_app(pub), username='agent', password='agent')
|
71
|
resp = app.get('/backoffice/', status=403)
|
72
|
role = create_role()
|
73
|
user.roles = [role.id]
|
74
|
user.store()
|
75
|
|
76
|
app = login(get_app(pub), username='agent', password='agent')
|
77
|
resp = app.get('/backoffice/')
|
78
|
# check user is automatically redirected to management/
|
79
|
assert resp.location == 'http://example.net/backoffice/management/'
|
80
|
|
81
|
|
82
|
def test_with_agent_submitter():
|
83
|
user = create_agent()
|
84
|
role = create_role()
|
85
|
user.roles = [role.id]
|
86
|
user.store()
|
87
|
FormDef.wipe()
|
88
|
formdef = FormDef()
|
89
|
formdef.name = 'form test'
|
90
|
formdef.fields = []
|
91
|
formdef.store()
|
92
|
|
93
|
app = login(get_app(pub), username='agent', password='agent')
|
94
|
resp = app.get('/backoffice/')
|
95
|
# check user is automatically redirected to management/
|
96
|
assert resp.location == 'http://example.net/backoffice/management/'
|
97
|
resp = resp.maybe_follow()
|
98
|
assert resp.pyquery('#sidepage-menu .icon-management')
|
99
|
assert not resp.pyquery('#sidepage-menu .icon-submission')
|
100
|
|
101
|
formdef.backoffice_submission_roles = [role.id]
|
102
|
formdef.store()
|
103
|
resp = app.get('/backoffice/') # still redirecting to management
|
104
|
assert resp.location == 'http://example.net/backoffice/management/'
|
105
|
resp = resp.maybe_follow()
|
106
|
|
107
|
# check the management and submission links are present in side menu
|
108
|
assert resp.pyquery('#sidepage-menu .icon-management')
|
109
|
assert resp.pyquery('#sidepage-menu .icon-submission')
|