Projet

Général

Profil

0001-misc-include-URL-in-sync-exceptions-errors-32975.patch

Frédéric Péters, 18 mai 2019 08:32

Télécharger (5,64 ko)

Voir les différences:

Subject: [PATCH] misc: include URL in sync exceptions errors (#32975)

 chrono/agendas/models.py | 5 +++--
 tests/test_agendas.py    | 8 ++++----
 tests/test_manager.py    | 6 +++---
 3 files changed, 10 insertions(+), 9 deletions(-)
chrono/agendas/models.py
484 484
            response = requests.get(url, proxies=settings.REQUESTS_PROXIES)
485 485
            response.raise_for_status()
486 486
        except requests.HTTPError as e:
487
            raise ICSError(_('Failed to retrieve remote calendar (HTTP error %s).') % e.response.status_code)
487
            raise ICSError(_('Failed to retrieve remote calendar (%s, HTTP error %s).') % (
488
                url, e.response.status_code))
488 489
        except requests.RequestException as e:
489
            raise ICSError(_('Failed to retrieve remote calendar (%s).') % e)
490
            raise ICSError(_('Failed to retrieve remote calendar (%s, %s).') % (url, e))
490 491

  
491 492
        return self.create_timeperiod_exceptions_from_ics(response.text, keep_synced_by_uid=True)
492 493

  
tests/test_agendas.py
327 327
    mocked_get.side_effect = mocked_requests_connection_error
328 328
    with pytest.raises(ICSError) as e:
329 329
        exceptions_count = desk.create_timeperiod_exceptions_from_remote_ics('http://example.com/sample.ics')
330
    assert str(e.value) == "Failed to retrieve remote calendar (unreachable)."
330
    assert str(e.value) == "Failed to retrieve remote calendar (http://example.com/sample.ics, unreachable)."
331 331

  
332 332
@mock.patch('chrono.agendas.models.requests.get')
333 333
def test_timeperiodexception_creation_from_forbidden_remote_ics(mocked_get):
......
344 344

  
345 345
    with pytest.raises(ICSError) as e:
346 346
        exceptions_count = desk.create_timeperiod_exceptions_from_remote_ics('http://example.com/sample.ics')
347
    assert str(e.value) == "Failed to retrieve remote calendar (HTTP error 403)."
347
    assert str(e.value) == "Failed to retrieve remote calendar (http://example.com/sample.ics, HTTP error 403)."
348 348

  
349 349
@mock.patch('chrono.agendas.models.requests.get')
350 350
def test_sync_desks_timeperiod_exceptions_from_ics(mocked_get, capsys):
351 351
    agenda = Agenda(label=u'Test 11 agenda')
352 352
    agenda.save()
353
    desk = Desk(label='Test 11 desk', agenda=agenda, timeperiod_exceptions_remote_url='http:example.com/sample.ics')
353
    desk = Desk(label='Test 11 desk', agenda=agenda, timeperiod_exceptions_remote_url='http://example.com/sample.ics')
354 354
    desk.save()
355 355
    mocked_response = mock.Mock()
356 356
    mocked_response.status_code = 403
......
360 360
    mocked_get.side_effect = mocked_requests_http_forbidden_error
361 361
    call_command('sync_desks_timeperiod_exceptions')
362 362
    out, err = capsys.readouterr()
363
    assert err == 'unable to create timeperiod exceptions for "Test 11 desk": Failed to retrieve remote calendar (HTTP error 403).\n'
363
    assert err == 'unable to create timeperiod exceptions for "Test 11 desk": Failed to retrieve remote calendar (http://example.com/sample.ics, HTTP error 403).\n'
364 364

  
365 365
@mock.patch('chrono.agendas.models.requests.get')
366 366
def test_sync_desks_timeperiod_exceptions_from_changing_ics(mocked_get, caplog):
tests/test_manager.py
1246 1246
        raise requests.exceptions.ConnectionError('unreachable')
1247 1247
    mocked_get.side_effect = mocked_requests_connection_error
1248 1248
    resp = resp.form.submit(status=200)
1249
    assert 'Failed to retrieve remote calendar (unreachable).' in resp.text
1249
    assert 'Failed to retrieve remote calendar (http://example.com/foo.ics, unreachable).' in resp.text
1250 1250

  
1251 1251
@mock.patch('chrono.agendas.models.requests.get')
1252 1252
def test_agenda_import_time_period_exception_from_forbidden_remote_ics(mocked_get, app, admin_user):
......
1272 1272
        raise requests.exceptions.HTTPError(response=mocked_response)
1273 1273
    mocked_get.side_effect = mocked_requests_http_forbidden_error
1274 1274
    resp = resp.form.submit(status=200)
1275
    assert 'Failed to retrieve remote calendar (HTTP error 403).' in resp.text
1275
    assert 'Failed to retrieve remote calendar (http://example.com/foo.ics, HTTP error 403).' in resp.text
1276 1276

  
1277 1277
@mock.patch('chrono.agendas.models.requests.get')
1278 1278
def test_agenda_import_time_period_exception_from_remote_ics_with_ssl_error(mocked_get, app, admin_user):
......
1296 1296
        raise requests.exceptions.SSLError('SSL error')
1297 1297
    mocked_get.side_effect = mocked_requests_http_ssl_error
1298 1298
    resp = resp.form.submit(status=200)
1299
    assert 'Failed to retrieve remote calendar (SSL error).' in resp.text
1299
    assert 'Failed to retrieve remote calendar (https://example.com/foo.ics, SSL error).' in resp.text
1300 1300

  
1301 1301
def test_agenda_day_view(app, admin_user, manager_user, api_user):
1302 1302
    agenda = Agenda.objects.create(label='New Example', kind='meetings')
1303
-