0001-misc-split-workflow-notification-tests.patch
tests/workflow/test_all.py | ||
---|---|---|
64 | 64 |
from wcs.wf.form import FormWorkflowStatusItem, WorkflowFormFieldsFormDef |
65 | 65 |
from wcs.wf.geolocate import GeolocateWorkflowStatusItem |
66 | 66 |
from wcs.wf.jump import JumpWorkflowStatusItem, _apply_timeouts |
67 |
from wcs.wf.notification import SendNotificationWorkflowStatusItem |
|
68 | 67 |
from wcs.wf.profile import UpdateUserProfileStatusItem |
69 | 68 |
from wcs.wf.redirect_to_url import RedirectToUrlWorkflowStatusItem |
70 | 69 |
from wcs.wf.register_comment import JournalEvolutionPart, RegisterCommenterWorkflowStatusItem |
... | ... | |
5948 | 5947 |
assert logged_error.expression_type == 'python' |
5949 | 5948 | |
5950 | 5949 | |
5951 |
def test_notifications(pub, http_requests): |
|
5952 |
formdef = FormDef() |
|
5953 |
formdef.name = 'baz' |
|
5954 |
formdef.fields = [] |
|
5955 |
formdef.store() |
|
5956 | ||
5957 |
formdata = formdef.data_class()() |
|
5958 |
formdata.just_created() |
|
5959 |
formdata.store() |
|
5960 | ||
5961 |
assert not SendNotificationWorkflowStatusItem.is_available() |
|
5962 | ||
5963 |
if not pub.site_options.has_section('variables'): |
|
5964 |
pub.site_options.add_section('variables') |
|
5965 |
pub.site_options.set('variables', 'portal_url', 'https://portal/') |
|
5966 |
assert SendNotificationWorkflowStatusItem.is_available() |
|
5967 | ||
5968 |
item = SendNotificationWorkflowStatusItem() |
|
5969 |
assert item.to == ['_submitter'] |
|
5970 |
item.title = 'xxx' |
|
5971 |
item.body = 'XXX' |
|
5972 | ||
5973 |
# no user |
|
5974 |
http_requests.empty() |
|
5975 |
item.perform(formdata) |
|
5976 |
assert http_requests.count() == 0 |
|
5977 | ||
5978 |
# user |
|
5979 |
http_requests.empty() |
|
5980 |
user = pub.user_class() |
|
5981 |
user.name_identifiers = ['xxx'] |
|
5982 |
user.store() |
|
5983 |
formdata.user_id = user.id |
|
5984 |
formdata.store() |
|
5985 | ||
5986 |
item.perform(formdata) |
|
5987 |
assert http_requests.count() == 1 |
|
5988 |
assert http_requests.get_last('url') == 'https://portal/api/notification/add/?NameID=xxx' |
|
5989 |
assert json.loads(http_requests.get_last('body')) == { |
|
5990 |
'body': 'XXX', |
|
5991 |
'url': formdata.get_url(), |
|
5992 |
'id': 'formdata:%s' % formdata.get_display_id(), |
|
5993 |
'origin': '', |
|
5994 |
'summary': 'xxx', |
|
5995 |
} |
|
5996 | ||
5997 |
# deleted user |
|
5998 |
http_requests.empty() |
|
5999 |
user.deleted_timestamp = datetime.datetime.now() |
|
6000 |
user.store() |
|
6001 |
item.perform(formdata) |
|
6002 |
assert http_requests.count() == 0 |
|
6003 | ||
6004 |
# roles (not exposed in current UI) |
|
6005 |
http_requests.empty() |
|
6006 |
user.deleted_timestamp = datetime.datetime.now() |
|
6007 |
user.store() |
|
6008 | ||
6009 |
role = pub.role_class(name='blah') |
|
6010 |
role.store() |
|
6011 | ||
6012 |
user1 = pub.user_class() |
|
6013 |
user1.roles = [role.id] |
|
6014 |
user1.name_identifiers = ['xxy1'] |
|
6015 |
user1.store() |
|
6016 |
user2 = pub.user_class() |
|
6017 |
user2.roles = [role.id] |
|
6018 |
user2.name_identifiers = ['xxy2'] |
|
6019 |
user2.store() |
|
6020 | ||
6021 |
formdef.workflow_roles = {'_receiver': role.id} |
|
6022 | ||
6023 |
item.to = ['_receiver'] |
|
6024 |
item.perform(formdata) |
|
6025 |
assert http_requests.count() == 2 |
|
6026 |
assert {x['url'] for x in http_requests.requests} == { |
|
6027 |
'https://portal/api/notification/add/?NameID=xxy1', |
|
6028 |
'https://portal/api/notification/add/?NameID=xxy2', |
|
6029 |
} |
|
6030 | ||
6031 |
# test inactive users are ignored |
|
6032 |
user2.is_active = False |
|
6033 |
user2.store() |
|
6034 |
http_requests.empty() |
|
6035 |
item.perform(formdata) |
|
6036 |
assert http_requests.count() == 1 |
|
6037 |
assert {x['url'] for x in http_requests.requests} == {'https://portal/api/notification/add/?NameID=xxy1'} |
|
6038 | ||
6039 |
# check notifications are sent to interco portal if it exists |
|
6040 |
pub.site_options.set('variables', '_interco_portal_url', 'https://interco-portal/') |
|
6041 |
http_requests.empty() |
|
6042 |
item.perform(formdata) |
|
6043 |
assert http_requests.count() == 1 |
|
6044 |
assert {x['url'] for x in http_requests.requests} == { |
|
6045 |
'https://interco-portal/api/notification/add/?NameID=xxy1' |
|
6046 |
} |
|
6047 | ||
6048 | ||
6049 | 5950 |
def test_workflow_field_migration(pub): |
6050 | 5951 |
Workflow.wipe() |
6051 | 5952 |
wf = Workflow(name='wf with backoffice field') |
tests/workflow/test_notification.py | ||
---|---|---|
1 |
import datetime |
|
2 |
import json |
|
3 | ||
4 |
import pytest |
|
5 |
from quixote import cleanup |
|
6 | ||
7 |
from wcs import sessions |
|
8 |
from wcs.formdef import FormDef |
|
9 |
from wcs.qommon.http_request import HTTPRequest |
|
10 |
from wcs.wf.notification import SendNotificationWorkflowStatusItem |
|
11 | ||
12 |
from ..utilities import clean_temporary_pub, create_temporary_pub |
|
13 | ||
14 | ||
15 |
def setup_module(module): |
|
16 |
cleanup() |
|
17 | ||
18 | ||
19 |
def teardown_module(module): |
|
20 |
clean_temporary_pub() |
|
21 | ||
22 | ||
23 |
@pytest.fixture |
|
24 |
def pub(request): |
|
25 |
pub = create_temporary_pub() |
|
26 |
pub.cfg['language'] = {'language': 'en'} |
|
27 |
pub.write_cfg() |
|
28 |
req = HTTPRequest(None, {'SERVER_NAME': 'example.net', 'SCRIPT_NAME': ''}) |
|
29 |
req.response.filter = {} |
|
30 |
req._user = None |
|
31 |
pub._set_request(req) |
|
32 |
req.session = sessions.BasicSession(id=1) |
|
33 |
pub.set_config(req) |
|
34 |
return pub |
|
35 | ||
36 | ||
37 |
def test_notifications(pub, http_requests): |
|
38 |
formdef = FormDef() |
|
39 |
formdef.name = 'baz' |
|
40 |
formdef.fields = [] |
|
41 |
formdef.store() |
|
42 | ||
43 |
formdata = formdef.data_class()() |
|
44 |
formdata.just_created() |
|
45 |
formdata.store() |
|
46 | ||
47 |
assert not SendNotificationWorkflowStatusItem.is_available() |
|
48 | ||
49 |
if not pub.site_options.has_section('variables'): |
|
50 |
pub.site_options.add_section('variables') |
|
51 |
pub.site_options.set('variables', 'portal_url', 'https://portal/') |
|
52 |
assert SendNotificationWorkflowStatusItem.is_available() |
|
53 | ||
54 |
item = SendNotificationWorkflowStatusItem() |
|
55 |
assert item.to == ['_submitter'] |
|
56 |
item.title = 'xxx' |
|
57 |
item.body = 'XXX' |
|
58 | ||
59 |
# no user |
|
60 |
http_requests.empty() |
|
61 |
item.perform(formdata) |
|
62 |
assert http_requests.count() == 0 |
|
63 | ||
64 |
# user |
|
65 |
http_requests.empty() |
|
66 |
user = pub.user_class() |
|
67 |
user.name_identifiers = ['xxx'] |
|
68 |
user.store() |
|
69 |
formdata.user_id = user.id |
|
70 |
formdata.store() |
|
71 | ||
72 |
item.perform(formdata) |
|
73 |
assert http_requests.count() == 1 |
|
74 |
assert http_requests.get_last('url') == 'https://portal/api/notification/add/?NameID=xxx' |
|
75 |
assert json.loads(http_requests.get_last('body')) == { |
|
76 |
'body': 'XXX', |
|
77 |
'url': formdata.get_url(), |
|
78 |
'id': 'formdata:%s' % formdata.get_display_id(), |
|
79 |
'origin': '', |
|
80 |
'summary': 'xxx', |
|
81 |
} |
|
82 | ||
83 |
# deleted user |
|
84 |
http_requests.empty() |
|
85 |
user.deleted_timestamp = datetime.datetime.now() |
|
86 |
user.store() |
|
87 |
item.perform(formdata) |
|
88 |
assert http_requests.count() == 0 |
|
89 | ||
90 |
# roles (not exposed in current UI) |
|
91 |
http_requests.empty() |
|
92 |
user.deleted_timestamp = datetime.datetime.now() |
|
93 |
user.store() |
|
94 | ||
95 |
role = pub.role_class(name='blah') |
|
96 |
role.store() |
|
97 | ||
98 |
user1 = pub.user_class() |
|
99 |
user1.roles = [role.id] |
|
100 |
user1.name_identifiers = ['xxy1'] |
|
101 |
user1.store() |
|
102 |
user2 = pub.user_class() |
|
103 |
user2.roles = [role.id] |
|
104 |
user2.name_identifiers = ['xxy2'] |
|
105 |
user2.store() |
|
106 | ||
107 |
formdef.workflow_roles = {'_receiver': role.id} |
|
108 | ||
109 |
item.to = ['_receiver'] |
|
110 |
item.perform(formdata) |
|
111 |
assert http_requests.count() == 2 |
|
112 |
assert {x['url'] for x in http_requests.requests} == { |
|
113 |
'https://portal/api/notification/add/?NameID=xxy1', |
|
114 |
'https://portal/api/notification/add/?NameID=xxy2', |
|
115 |
} |
|
116 | ||
117 |
# test inactive users are ignored |
|
118 |
user2.is_active = False |
|
119 |
user2.store() |
|
120 |
http_requests.empty() |
|
121 |
item.perform(formdata) |
|
122 |
assert http_requests.count() == 1 |
|
123 |
assert {x['url'] for x in http_requests.requests} == {'https://portal/api/notification/add/?NameID=xxy1'} |
|
124 | ||
125 |
# check notifications are sent to interco portal if it exists |
|
126 |
pub.site_options.set('variables', '_interco_portal_url', 'https://interco-portal/') |
|
127 |
http_requests.empty() |
|
128 |
item.perform(formdata) |
|
129 |
assert http_requests.count() == 1 |
|
130 |
assert {x['url'] for x in http_requests.requests} == { |
|
131 |
'https://interco-portal/api/notification/add/?NameID=xxy1' |
|
132 |
} |
|
0 |
- |