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