|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# |
|
3
|
|
|
# This file is part of SENAITE.HEALTH. |
|
4
|
|
|
# |
|
5
|
|
|
# SENAITE.HEALTH is free software: you can redistribute it and/or modify it |
|
6
|
|
|
# under the terms of the GNU General Public License as published by the Free |
|
7
|
|
|
# Software Foundation, version 2. |
|
8
|
|
|
# |
|
9
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT |
|
10
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
11
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
12
|
|
|
# details. |
|
13
|
|
|
# |
|
14
|
|
|
# You should have received a copy of the GNU General Public License along with |
|
15
|
|
|
# this program; if not, write to the Free Software Foundation, Inc., 51 |
|
16
|
|
|
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
17
|
|
|
# |
|
18
|
|
|
# Copyright 2018-2019 by it's authors. |
|
19
|
|
|
# Some rights reserved, see README and LICENSE. |
|
20
|
|
|
|
|
21
|
|
|
from bika.lims.exportimport.load_setup_data import LoadSetupData |
|
22
|
|
|
from plone.app.testing import (PLONE_FIXTURE, SITE_OWNER_NAME, |
|
23
|
|
|
FunctionalTesting, PloneSandboxLayer, login, |
|
24
|
|
|
logout) |
|
25
|
|
|
from plone.testing import z2 |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
from Products.CMFCore.utils import getToolByName |
|
29
|
|
|
from Products.CMFPlone.setuphandlers import setupPortalContent |
|
30
|
|
|
from Testing.makerequest import makerequest |
|
31
|
|
|
|
|
32
|
|
|
import Products.ATExtensions |
|
33
|
|
|
import collective.js.jqueryui |
|
34
|
|
|
import plone.app.iterate |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
class BaseLayer(PloneSandboxLayer): |
|
38
|
|
|
defaultBases = (PLONE_FIXTURE,) |
|
39
|
|
|
|
|
40
|
|
|
def setUpZope(self, app, configurationContext): |
|
41
|
|
|
import bika.lims |
|
42
|
|
|
import bika.health |
|
43
|
|
|
import archetypes.schemaextender |
|
44
|
|
|
# Load ZCML |
|
45
|
|
|
self.loadZCML(package=Products.ATExtensions) |
|
46
|
|
|
self.loadZCML(package=plone.app.iterate) |
|
47
|
|
|
self.loadZCML(package=collective.js.jqueryui) |
|
48
|
|
|
self.loadZCML(package=archetypes.schemaextender) |
|
49
|
|
|
self.loadZCML(package=bika.lims) |
|
50
|
|
|
self.loadZCML(package=bika.health) |
|
51
|
|
|
|
|
52
|
|
|
# Required by Products.CMFPlone:plone-content |
|
53
|
|
|
z2.installProduct(app, 'Products.PythonScripts') |
|
54
|
|
|
z2.installProduct(app, 'bika.lims') |
|
55
|
|
|
z2.installProduct(app, 'bika.health') |
|
56
|
|
|
|
|
57
|
|
|
def setUpPloneSite(self, portal): |
|
58
|
|
|
# Install into Plone site using portal_setup |
|
59
|
|
|
self.applyProfile(portal, 'bika.lims:default') |
|
60
|
|
|
self.applyProfile(portal, 'bika.health:default') |
|
61
|
|
|
|
|
62
|
|
|
def tearDownZope(self, app): |
|
63
|
|
|
# Uninstall product |
|
64
|
|
|
z2.uninstallProduct(app, 'bika.lims') |
|
65
|
|
|
z2.uninstallProduct(app, 'bika.health') |
|
66
|
|
|
z2.uninstallProduct(app, 'Products.PythonScripts') |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
class DataLayer(BaseLayer): |
|
70
|
|
|
"""Layer including Demo Data |
|
71
|
|
|
""" |
|
72
|
|
|
|
|
73
|
|
|
def setup_data_load(self, portal, request): |
|
74
|
|
|
login(portal.aq_parent, SITE_OWNER_NAME) |
|
75
|
|
|
|
|
76
|
|
|
wf = getToolByName(portal, 'portal_workflow') |
|
77
|
|
|
wf.setDefaultChain('plone_workflow') |
|
78
|
|
|
setupPortalContent(portal) |
|
79
|
|
|
|
|
80
|
|
|
# make sure we have folder_listing as a template |
|
81
|
|
|
portal.getTypeInfo().manage_changeProperties( |
|
82
|
|
|
view_methods=['folder_listing'], |
|
83
|
|
|
default_view='folder_listing') |
|
84
|
|
|
# Add some test users |
|
85
|
|
|
for role in ('LabManager', |
|
86
|
|
|
'LabClerk', |
|
87
|
|
|
'Analyst', |
|
88
|
|
|
'Verifier', |
|
89
|
|
|
'Sampler', |
|
90
|
|
|
'Preserver', |
|
91
|
|
|
'Publisher', |
|
92
|
|
|
'Member', |
|
93
|
|
|
'Reviewer', |
|
94
|
|
|
'RegulatoryInspector'): |
|
95
|
|
|
for user_nr in range(2): |
|
96
|
|
|
if user_nr == 0: |
|
97
|
|
|
username = "test_%s" % (role.lower()) |
|
98
|
|
|
else: |
|
99
|
|
|
username = "test_%s%s" % (role.lower(), user_nr) |
|
100
|
|
|
member = portal.portal_registration.addMember( |
|
101
|
|
|
username, |
|
102
|
|
|
username, |
|
103
|
|
|
properties={ |
|
104
|
|
|
'username': username, |
|
105
|
|
|
'email': username + "@example.com", |
|
106
|
|
|
'fullname': username} |
|
107
|
|
|
) |
|
108
|
|
|
# Add user to all specified groups |
|
109
|
|
|
group_id = role + "s" |
|
110
|
|
|
group = portal.portal_groups.getGroupById(group_id) |
|
111
|
|
|
if group: |
|
112
|
|
|
group.addMember(username) |
|
113
|
|
|
# Add user to all specified roles |
|
114
|
|
|
member._addRole(role) |
|
115
|
|
|
# If user is in LabManagers, add Owner local role on clients folder |
|
116
|
|
|
if role == 'LabManager': |
|
117
|
|
|
portal.clients.manage_setLocalRoles(username, ['Owner', ]) |
|
118
|
|
|
|
|
119
|
|
|
# load test data |
|
120
|
|
|
request = makerequest(portal.aq_parent).REQUEST |
|
121
|
|
|
request.form['setupexisting'] = 1 |
|
122
|
|
|
request.form['existing'] = "bika.health:test" |
|
123
|
|
|
lsd = LoadSetupData(portal, request) |
|
124
|
|
|
lsd() |
|
125
|
|
|
|
|
126
|
|
|
logout() |
|
127
|
|
|
|
|
128
|
|
|
def setUpPloneSite(self, portal): |
|
129
|
|
|
super(DataLayer, self).setUpPloneSite(portal) |
|
130
|
|
|
|
|
131
|
|
|
# Install Demo Data |
|
132
|
|
|
self.setup_data_load(portal, portal.REQUEST) |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
BASE_LAYER_FIXTURE = BaseLayer() |
|
136
|
|
|
BASE_TESTING = FunctionalTesting( |
|
137
|
|
|
bases=(BASE_LAYER_FIXTURE,), name="SENAITE.HEALTH:BaseTesting") |
|
138
|
|
|
|
|
139
|
|
|
DATA_LAYER_FIXTURE = DataLayer() |
|
140
|
|
|
DATA_TESTING = FunctionalTesting( |
|
141
|
|
|
bases=(DATA_LAYER_FIXTURE,), name="SENAITE.HEALTH:DataTesting") |
|
142
|
|
|
|