Projet

Général

Profil

0002-wf-mark-direct-usage-of-attachments-as-deprecated-56.patch

Lauréline Guérin, 06 septembre 2021 16:23

Télécharger (6,26 ko)

Voir les différences:

Subject: [PATCH 2/2] wf: mark direct usage of "attachments" as deprecated
 (#56613)

 tests/test_workflows.py | 40 +++++++++++++++++++++++++++++++---------
 wcs/formdata.py         |  2 +-
 wcs/workflows.py        |  8 ++++++--
 3 files changed, 38 insertions(+), 12 deletions(-)
tests/test_workflows.py
1143 1143
    assert formdata.evolution[-1].display_parts()[-1] == '<div><p>hello</p></div>'
1144 1144

  
1145 1145

  
1146
def test_register_comment_attachment(pub):
1147
    pub.substitutions.feed(MockSubstitutionVariables())
1146
def test_register_comment_attachment(two_pubs):
1147
    if two_pubs.is_using_postgresql():
1148
        two_pubs.loggederror_class.wipe()
1149
    two_pubs.substitutions.feed(MockSubstitutionVariables())
1148 1150

  
1149 1151
    formdef = FormDef()
1150 1152
    formdef.name = 'baz'
......
1174 1176

  
1175 1177
    item.comment = '{{ attachments.testfile.url }}'
1176 1178

  
1177
    pub.substitutions.feed(formdata)
1179
    two_pubs.substitutions.feed(formdata)
1178 1180
    item.perform(formdata)
1179 1181
    url1 = formdata.evolution[-1].parts[-1].content
1182
    if two_pubs.is_using_postgresql():
1183
        assert two_pubs.loggederror_class.count() == 1
1184
        error = two_pubs.loggederror_class.select()[0]
1185
        assert error.kind == 'deprecated_usage'
1186
        assert error.occurences_count == 1
1180 1187

  
1181
    pub.substitutions.feed(formdata)
1188
    two_pubs.substitutions.feed(formdata)
1182 1189
    item.comment = '{{ form_attachments.testfile.url }}'
1183 1190
    item.perform(formdata)
1184 1191
    url2 = formdata.evolution[-1].parts[-1].content
1192
    if two_pubs.is_using_postgresql():
1193
        assert two_pubs.loggederror_class.count() == 1
1194
        error = two_pubs.loggederror_class.select()[0]
1195
        assert error.kind == 'deprecated_usage'
1196
        assert error.occurences_count == 1
1185 1197

  
1186 1198
    assert len(os.listdir(os.path.join(get_publisher().app_dir, 'attachments'))) == 1
1187 1199
    for subdir in os.listdir(os.path.join(get_publisher().app_dir, 'attachments')):
......
1204 1216
    item.condition = {'type': 'django', 'value': 'form_attachments.missing'}
1205 1217
    assert item.check_condition(formdata) is False
1206 1218

  
1207
    pub.substitutions.feed(formdata)
1219
    two_pubs.substitutions.feed(formdata)
1208 1220
    item.comment = '[attachments.testfile.url]'
1209 1221
    item.perform(formdata)
1210 1222
    url3 = formdata.evolution[-1].parts[-1].content
1211
    pub.substitutions.feed(formdata)
1223
    if two_pubs.is_using_postgresql():
1224
        assert two_pubs.loggederror_class.count() == 1
1225
        error = two_pubs.loggederror_class.select()[0]
1226
        assert error.kind == 'deprecated_usage'
1227
        assert error.occurences_count == 2
1228
    two_pubs.substitutions.feed(formdata)
1212 1229
    item.comment = '[form_attachments.testfile.url]'
1213 1230
    item.perform(formdata)
1214 1231
    url4 = formdata.evolution[-1].parts[-1].content
1215 1232
    assert url3 == url4
1233
    if two_pubs.is_using_postgresql():
1234
        assert two_pubs.loggederror_class.count() == 1
1235
        error = two_pubs.loggederror_class.select()[0]
1236
        assert error.kind == 'deprecated_usage'
1237
        assert error.occurences_count == 2
1216 1238

  
1217 1239

  
1218 1240
def test_register_comment_with_attachment_file(pub):
......
2028 2050
    item.url = 'http://remote.example.net'
2029 2051
    item.request_signature_key = '{{ doesntexist }}'
2030 2052
    item.perform(formdata)
2031
    assert not 'signature=' in http_requests.get_last('url')
2053
    assert 'signature=' not in http_requests.get_last('url')
2032 2054

  
2033 2055
    item = WebserviceCallStatusItem()
2034 2056
    item.url = 'http://remote.example.net'
2035 2057
    item.request_signature_key = '{{ empty }}'
2036 2058
    item.perform(formdata)
2037
    assert not 'signature=' in http_requests.get_last('url')
2059
    assert 'signature=' not in http_requests.get_last('url')
2038 2060

  
2039 2061
    item = WebserviceCallStatusItem()
2040 2062
    item.url = 'http://remote.example.net'
2041 2063
    item.request_signature_key = '[empty]'
2042 2064
    item.perform(formdata)
2043
    assert not 'signature=' in http_requests.get_last('url')
2065
    assert 'signature=' not in http_requests.get_last('url')
2044 2066

  
2045 2067
    item = WebserviceCallStatusItem()
2046 2068
    item.url = 'http://remote.example.net'
wcs/formdata.py
950 950
        variables = CompatibilityNamesDict(
951 951
            {
952 952
                'form': self.get_as_lazy(),
953
                'attachments': AttachmentsSubstitutionProxy(self),
953
                'attachments': AttachmentsSubstitutionProxy(self, deprecated_usage=True),
954 954
            }
955 955
        )
956 956
        if self.formdef.category:
wcs/workflows.py
180 180

  
181 181

  
182 182
class AttachmentsSubstitutionProxy:
183
    def __init__(self, formdata):
183
    def __init__(self, formdata, deprecated_usage=False):
184 184
        self.formdata = formdata
185
        self.deprecated_usage = deprecated_usage
185 186

  
186 187
    def __getattr__(self, name):
187 188
        if name.startswith('__'):
......
192 193

  
193 194
        parts = [part for part in self.formdata.iter_evolution_parts() if has_varname_attachment(part)]
194 195
        if parts:
196
            if self.deprecated_usage:
197
                error_summary = _('Usage of "attachments" detected in "attachments_%s" expression') % name
198
                get_publisher().record_deprecated_usage(error_summary, formdata=self.formdata)
195 199
            return NamedAttachmentsSubstitutionProxy(self.formdata, parts)
196 200
        raise AttributeError(name)
197 201

  
......
317 321
    @classmethod
318 322
    def get_substitution_variables(cls, formdata):
319 323
        return {
320
            'attachments': AttachmentsSubstitutionProxy(formdata),
324
            'attachments': AttachmentsSubstitutionProxy(formdata, deprecated_usage=True),
321 325
            'form_attachments': AttachmentsSubstitutionProxy(formdata),
322 326
        }
323 327

  
324
-