diff --git a/combo/apps/dataviz/__init__.py b/combo/apps/dataviz/__init__.py index 7aba25e3..2e90348a 100644 --- a/combo/apps/dataviz/__init__.py +++ b/combo/apps/dataviz/__init__.py @@ -51,10 +51,13 @@ class AppConfig(django.apps.AppConfig): for site_key, site_dict in sites.items(): site_title = site_dict.pop('title', '') - result = requests.get( + response = requests.get( url, remote_service=site_dict, without_user=True, headers={'accept': 'application/json'} - ).json() + ) + if response.status_code != 200: + continue + result = response.json() if isinstance(result, dict): result = result['data'] # detect new api diff --git a/tests/test_dataviz.py b/tests/test_dataviz.py index ede0cd92..917eee7d 100644 --- a/tests/test_dataviz.py +++ b/tests/test_dataviz.py @@ -1204,11 +1204,19 @@ def test_dataviz_api_list_statistics(new_api_statistics, settings): catalog = {'data': [{'url': 'https://stat.com/stats/1/', 'name': 'Test', 'id': 'test'}]} @urlmatch(scheme='https', netloc=r'stat.com', path='/stats/') - def url_mock(url, request): - return {'content': json.dumps(catalog), 'status_code': 200} + def server_error(url, request): + return {'content': 'error', 'status_code': 500} appconfig = apps.get_app_config('dataviz') - with HTTMock(url_mock): + with HTTMock(server_error): + appconfig.hourly() + assert Statistic.objects.count() == statistics_count + + @urlmatch(scheme='https', netloc=r'stat.com', path='/stats/') + def success(url, request): + return {'content': json.dumps(catalog), 'status_code': 200} + + with HTTMock(success): appconfig.hourly() assert Statistic.objects.count() == statistics_count + 1