Projet

Général

Profil

0002-dataviz-do-not-raise-error-in-check_validity-65615.patch

Valentin Deniaud, 24 mai 2022 15:04

Télécharger (2,06 ko)

Voir les différences:

Subject: [PATCH 2/2] dataviz: do not raise error in check_validity (#65615)

 combo/apps/dataviz/models.py |  2 +-
 tests/test_dataviz.py        | 13 ++++++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)
combo/apps/dataviz/models.py
302 302
        resp = None
303 303
        try:
304 304
            resp = self.get_statistic_data()
305
        except RequestException:
305
        except (RequestException, MissingRequest, MissingVariable):
306 306
            pass
307 307

  
308 308
        self.set_validity_from_url(
tests/test_dataviz.py
2114 2114

  
2115 2115

  
2116 2116
def test_dataviz_check_validity(nocache):
2117
    page = Page.objects.create(title='One', slug='index')
2117
    page = Page.objects.create(title='One', slug='index', extra_variables={'foo': 'bar'})
2118 2118
    stat = Statistic.objects.create(url='https://stat.com/stats/1/')
2119 2119
    cell = ChartNgCell.objects.create(page=page, order=1, placeholder='content', statistic=stat)
2120 2120

  
......
2126 2126
        cell.check_validity()
2127 2127
    assert ValidityInfo.objects.exists() is False
2128 2128

  
2129
    # cell using page variable is valid even if it cannot be evaluated
2130
    cell.filter_params = {'test': 'variable:foo'}
2131
    cell.save()
2132

  
2133
    with HTTMock(url_mock):
2134
        cell.check_validity()
2135
    assert ValidityInfo.objects.exists() is False
2136

  
2137
    cell.filter_params.clear()
2138
    cell.save()
2139

  
2129 2140
    @urlmatch(scheme='https', netloc=r'stat.com', path='/stats/1/')
2130 2141
    def url_mock2(url, request):
2131 2142
        return {'content': json.dumps({'data': [], 'err': 1}), 'status_code': 404}
2132
-