Projet

Général

Profil

0001-misc-don-t-check-validity-for-links-with-multiple-va.patch

Frédéric Péters, 29 mars 2020 13:38

Télécharger (2,71 ko)

Voir les différences:

Subject: [PATCH] misc: don't check validity for links with multiple variables
 (#41139)

 combo/data/models.py |  4 ++++
 tests/test_cells.py  | 30 ++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
combo/data/models.py
1171 1171
            self.mark_as_invalid('data_url_not_defined')
1172 1172
            return
1173 1173

  
1174
        if self.url.count('{{') > 1:
1175
            self.mark_as_valid()
1176
            return
1177

  
1174 1178
        resp = None
1175 1179
        try:
1176 1180
            resp = requests.get(self.get_url(), timeout=settings.REQUESTS_TIMEOUT)
tests/test_cells.py
204 204
    assert validity_info.invalid_reason_code == 'data_url_invalid'
205 205
    assert validity_info.invalid_since is not None
206 206

  
207
    # external link with a single variable
208
    cell.link_page = None
209
    cell.anchor = ''
210
    cell.url = '{{test_url}}'
211
    with override_settings(TEMPLATE_VARS={'test_url': 'http://www.example.net/'}):
212
        with mock.patch('combo.data.models.requests.get') as requests_get:
213
            mock_json = mock.Mock(status_code=200)
214
            requests_get.return_value = mock_json
215
            cell.save()
216
        assert requests_get.call_args_list[0][0][0] == 'http://www.example.net/'
217
        assert ValidityInfo.objects.exists() is False
218

  
219
    with override_settings(TEMPLATE_VARS={'test_url': 'http://www.example.net/'}):
220
        with mock.patch('combo.data.models.requests.get') as requests_get:
221
            mock_json = mock.Mock(status_code=404)
222
            requests_get.return_value = mock_json
223
            cell.save()
224
        assert requests_get.call_args_list[0][0][0] == 'http://www.example.net/'
225
        assert ValidityInfo.objects.exists() is True
226

  
227
    # external link with two variables
228
    cell.url = '{{test_url}}/path/{{other}}'
229
    with override_settings(TEMPLATE_VARS={'test_url': 'http://www.example.net/'}):
230
        with mock.patch('combo.data.models.requests.get') as requests_get:
231
            mock_json = mock.Mock(status_code=200)
232
            requests_get.return_value = mock_json
233
            cell.save()
234
        assert requests_get.call_args_list == []
235
        assert ValidityInfo.objects.exists() is False
236

  
207 237

  
208 238
def test_link_list_cell():
209 239
    page = Page.objects.create(title='example page', slug='example-page')
210
-