1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
#
# Nicolas Delaby <nicolas@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import unittest
import transaction
from Products.ERP5Type.tests.Sequence import Sequence, SequenceList
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
clear_module_name_list = """
data_protection_request_module
""".strip().split()
class TestDataProtection(ERP5TypeTestCase):
document_edit_kw = {'description': 'Description with compromised data'}
# Selection name of listbox's form
# DataProtectionRequest_viewEraseSomeOriginalDataDialog
selection_name = 'data_protection_request_erase_data_selection'
def getTitle(self):
return "Data Protection"
def getBusinessTemplateList(self):
return ('erp5_base',
'erp5_data_protection',)
def beforeTearDown(self):
# clear modules if necessary
for module_name in clear_module_name_list:
module = getattr(self.portal, module_name)
module.manage_delObjects(list(module.objectIds()))
self.tic()
def stepCreatePersonDocument(self, sequence=None, sequence_list=None, **kw):
"""
"""
portal = self.getPortal()
portal_type = 'Person'
module = portal.getDefaultModule(portal_type)
person = module.newContent(portal_type=portal_type)
sequence.set('document_relative_url', person.getRelativeUrl())
def stepEditDocument(self, sequence=None, sequence_list=None, **kw):
"""
"""
portal = self.getPortal()
document = portal.restrictedTraverse(sequence.get('document_relative_url'))
document.edit(**self.document_edit_kw)
def stepValidateDocument(self, sequence=None, sequence_list=None, **kw):
"""
"""
portal = self.getPortal()
document = portal.restrictedTraverse(sequence.get('document_relative_url'))
portal.portal_workflow.doActionFor(document, 'validate_action',
comment='Comment with compromised data')
def stepCreateDataProtectionRequest(self, sequence=None,
sequence_list=None, **kw):
"""
"""
portal = self.getPortal()
portal_type = 'Data Protection Request'
document = portal.restrictedTraverse(sequence.get('document_relative_url'))
document.Base_addDataProtectionRequest(
description='I think the description is compromised')
transaction.commit()
self.tic()
data_protection = document.getFollowUpRelatedValueList(
portal_type=portal_type)[0]
sequence.set('data_protection_request_relative_url',
data_protection.getRelativeUrl())
def stepSubmitDataProtectionRequest(self, sequence=None,
sequence_list=None, **kw):
"""
"""
portal = self.getPortal()
data_protection = portal.restrictedTraverse(
sequence.get('data_protection_request_relative_url'))
data_protection.submit()
def stepEraseDocumentProperties(self, sequence=None,
sequence_list=None, **kw):
"""
"""
portal = self.getPortal()
data_protection = portal.restrictedTraverse(
sequence.get('data_protection_request_relative_url'))
portal.portal_selections.setSelectionCheckedUidsFor(self.selection_name,
self.document_edit_kw.keys())
# False means keep workflow history comments
data_protection.DataProtectionRequest_eraseSomeOriginalData('View', False)
def stepCheckErasedDataProperties(self, sequence=None,
sequence_list=None, **kw):
"""
"""
portal = self.getPortal()
document = portal.restrictedTraverse(sequence.get('document_relative_url'))
for property_id in self.document_edit_kw.keys():
# Properties are now deleted, so check that None
# or default value is returned.
self.assertFalse(document.getProperty(property_id))
# View History permission is now granted only for Manager
self.assertEquals(document._View_History_Permission, ('Manager',))
def stepEraseWorkflowHistoryCommentList(self, sequence=None,
sequence_list=None, **kw):
"""
"""
portal = self.getPortal()
data_protection = portal.restrictedTraverse(
sequence.get('data_protection_request_relative_url'))
# True means delete workflow history comments
data_protection.DataProtectionRequest_eraseSomeOriginalData('View', True)
def stepCheckErasedWorkflowHistoryCommentList(self, sequence=None,
sequence_list=None, **kw):
"""
"""
portal = self.getPortal()
document = portal.restrictedTraverse(sequence.get('document_relative_url'))
workflow_history = document.workflow_history
for workflow_id in workflow_history:
# All comments are removed except last one
self.assertFalse([history for history in
workflow_history[workflow_id][:-1]
if history.get('comment')])
# Last comment of edit workflow is filled by data protection action
self.assertTrue(workflow_history['edit_workflow'][-1].get('comment'))
# View History permission is now granted only for Manager
self.assertEquals(document._View_History_Permission, ('Manager',))
def test_01_dataProtectionRequest(self):
"""This test create a person with a compromised description.
A data protection request is create from this document.
Then user erase properties and workflow history and check
expected result.
- property on object are deleted
- Worlkflow history comments are deleted
- Permission "View History" is granted only for Manager
"""
sequence_list = SequenceList()
sequence_string = '\
CreatePersonDocument \
EditDocument \
ValidateDocument \
Tic \
CreateDataProtectionRequest \
Tic \
SubmitDataProtectionRequest \
Tic \
EraseDocumentProperties \
Tic \
CheckErasedDataProperties \
EraseWorkflowHistoryCommentList \
Tic \
CheckErasedWorkflowHistoryCommentList \
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestDataProtection))
return suite