Projet

Général

Profil

0005-misc-remove-complex-data-site-option-57260.patch

Lauréline Guérin, 24 septembre 2021 15:54

Télécharger (3,17 ko)

Voir les différences:

Subject: [PATCH 5/5] misc: remove complex-data site option (#57260)

 tests/workflow/test_all.py | 11 -----------
 wcs/publisher.py           |  3 +--
 wcs/qommon/publisher.py    |  9 ++-------
 wcs/workflows.py           |  2 +-
 4 files changed, 4 insertions(+), 21 deletions(-)
tests/workflow/test_all.py
2710 2710
    payload = json.loads(http_requests.get_last('body'))
2711 2711
    assert payload['bool'] is False
2712 2712

  
2713
    # check it's possible to disable complex data support
2714
    pub.load_site_options()
2715
    pub.site_options.set('options', 'complex-data', 'false')
2716

  
2717
    with get_publisher().complex_data():
2718
        item.perform(formdata)
2719
    assert http_requests.get_last('url') == 'http://remote.example.net'
2720
    assert http_requests.get_last('method') == 'POST'
2721
    payload = json.loads(http_requests.get_last('body'))
2722
    assert payload['items_raw'] == repr(['a', 'b'])
2723

  
2724 2713

  
2725 2714
def rewind(formdata, seconds):
2726 2715
    # utility function to move formdata back in time
wcs/publisher.py
431 431

  
432 432
    @contextmanager
433 433
    def complex_data(self):
434
        if self.has_site_option('complex-data'):
435
            self.complex_data_cache = {}
434
        self.complex_data_cache = {}
436 435
        try:
437 436
            yield True
438 437
        finally:
wcs/qommon/publisher.py
389 389
            return
390 390

  
391 391
    def has_site_option(self, option):
392
        defaults = {
393
            'complex-data': True,
394
        }
395 392
        if self.site_options is None:
396 393
            self.load_site_options()
397 394
        try:
398 395
            return self.site_options.get('options', option) == 'true'
399
        except configparser.NoSectionError:
400
            return defaults.get(option, False)
401
        except configparser.NoOptionError:
402
            return defaults.get(option, False)
396
        except (configparser.NoSectionError, configparser.NoOptionError):
397
            return False
403 398

  
404 399
    def get_site_option(self, option, section='options'):
405 400
        defaults = {
wcs/workflows.py
2261 2261
            )
2262 2262

  
2263 2263
        if expression['type'] == 'template':
2264
            vars['allow_complex'] = allow_complex and get_publisher().has_site_option('complex-data')
2264
            vars['allow_complex'] = allow_complex
2265 2265
            try:
2266 2266
                return Template(expression['value'], raises=raises, autoescape=False).render(vars)
2267 2267
            except TemplateError as e:
2268
-