misc: include URL in sync exceptions errors (#32975)

This commit is contained in:
Frédéric Péters 2019-05-18 08:20:22 +02:00
parent 34e8c83106
commit aeea3b78d6
3 changed files with 10 additions and 9 deletions

View File

@ -484,9 +484,10 @@ class Desk(models.Model):
response = requests.get(url, proxies=settings.REQUESTS_PROXIES)
response.raise_for_status()
except requests.HTTPError as e:
raise ICSError(_('Failed to retrieve remote calendar (HTTP error %s).') % e.response.status_code)
raise ICSError(_('Failed to retrieve remote calendar (%s, HTTP error %s).') % (
url, e.response.status_code))
except requests.RequestException as e:
raise ICSError(_('Failed to retrieve remote calendar (%s).') % e)
raise ICSError(_('Failed to retrieve remote calendar (%s, %s).') % (url, e))
return self.create_timeperiod_exceptions_from_ics(response.text, keep_synced_by_uid=True)

View File

@ -327,7 +327,7 @@ def test_timeperiodexception_creation_from_unreachable_remote_ics(mocked_get):
mocked_get.side_effect = mocked_requests_connection_error
with pytest.raises(ICSError) as e:
exceptions_count = desk.create_timeperiod_exceptions_from_remote_ics('http://example.com/sample.ics')
assert str(e.value) == "Failed to retrieve remote calendar (unreachable)."
assert str(e.value) == "Failed to retrieve remote calendar (http://example.com/sample.ics, unreachable)."
@mock.patch('chrono.agendas.models.requests.get')
def test_timeperiodexception_creation_from_forbidden_remote_ics(mocked_get):
@ -344,13 +344,13 @@ def test_timeperiodexception_creation_from_forbidden_remote_ics(mocked_get):
with pytest.raises(ICSError) as e:
exceptions_count = desk.create_timeperiod_exceptions_from_remote_ics('http://example.com/sample.ics')
assert str(e.value) == "Failed to retrieve remote calendar (HTTP error 403)."
assert str(e.value) == "Failed to retrieve remote calendar (http://example.com/sample.ics, HTTP error 403)."
@mock.patch('chrono.agendas.models.requests.get')
def test_sync_desks_timeperiod_exceptions_from_ics(mocked_get, capsys):
agenda = Agenda(label=u'Test 11 agenda')
agenda.save()
desk = Desk(label='Test 11 desk', agenda=agenda, timeperiod_exceptions_remote_url='http:example.com/sample.ics')
desk = Desk(label='Test 11 desk', agenda=agenda, timeperiod_exceptions_remote_url='http://example.com/sample.ics')
desk.save()
mocked_response = mock.Mock()
mocked_response.status_code = 403
@ -360,7 +360,7 @@ def test_sync_desks_timeperiod_exceptions_from_ics(mocked_get, capsys):
mocked_get.side_effect = mocked_requests_http_forbidden_error
call_command('sync_desks_timeperiod_exceptions')
out, err = capsys.readouterr()
assert err == 'unable to create timeperiod exceptions for "Test 11 desk": Failed to retrieve remote calendar (HTTP error 403).\n'
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'
@mock.patch('chrono.agendas.models.requests.get')
def test_sync_desks_timeperiod_exceptions_from_changing_ics(mocked_get, caplog):

View File

@ -1246,7 +1246,7 @@ def test_agenda_import_time_period_exception_from_remote_ics_with_connection_err
raise requests.exceptions.ConnectionError('unreachable')
mocked_get.side_effect = mocked_requests_connection_error
resp = resp.form.submit(status=200)
assert 'Failed to retrieve remote calendar (unreachable).' in resp.text
assert 'Failed to retrieve remote calendar (http://example.com/foo.ics, unreachable).' in resp.text
@mock.patch('chrono.agendas.models.requests.get')
def test_agenda_import_time_period_exception_from_forbidden_remote_ics(mocked_get, app, admin_user):
@ -1272,7 +1272,7 @@ def test_agenda_import_time_period_exception_from_forbidden_remote_ics(mocked_ge
raise requests.exceptions.HTTPError(response=mocked_response)
mocked_get.side_effect = mocked_requests_http_forbidden_error
resp = resp.form.submit(status=200)
assert 'Failed to retrieve remote calendar (HTTP error 403).' in resp.text
assert 'Failed to retrieve remote calendar (http://example.com/foo.ics, HTTP error 403).' in resp.text
@mock.patch('chrono.agendas.models.requests.get')
def test_agenda_import_time_period_exception_from_remote_ics_with_ssl_error(mocked_get, app, admin_user):
@ -1296,7 +1296,7 @@ def test_agenda_import_time_period_exception_from_remote_ics_with_ssl_error(mock
raise requests.exceptions.SSLError('SSL error')
mocked_get.side_effect = mocked_requests_http_ssl_error
resp = resp.form.submit(status=200)
assert 'Failed to retrieve remote calendar (SSL error).' in resp.text
assert 'Failed to retrieve remote calendar (https://example.com/foo.ics, SSL error).' in resp.text
def test_agenda_day_view(app, admin_user, manager_user, api_user):
agenda = Agenda.objects.create(label='New Example', kind='meetings')