Skip to content

Commit 7686283

Browse files
Meerdere foutmeldingen Buienradar API #776
1 parent 56e0776 commit 7686283

File tree

7 files changed

+35
-12
lines changed

7 files changed

+35
-12
lines changed

docs/changelog.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Changelog
44
v2.11.0 - 2019-xx-xx
55

66
- [`#774 <https://github.com/dennissiemensma/dsmr-reader/issues/774>`_] Generic performance improvements
7-
7+
- [`#776 <https://github.com/dennissiemensma/dsmr-reader/issues/776>`_] Meerdere foutmeldingen Buienradar API
88

99
----
1010

dsmr_mindergas/services.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ def export():
7676

7777
if response.status_code != 201:
7878
logger.error('MinderGas: Upload failed (HTTP %s): %s', response.status_code, response.text)
79-
raise AssertionError(_('Invalid status code'))
79+
raise AssertionError(_('Unexpected status code received'))

dsmr_weather/services.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,23 @@ def run(scheduled_process):
3232
def get_temperature_from_api():
3333
# For backend logging in Supervisor.
3434
logger.debug('Buienradar: Reading temperature: %s', settings.DSMRREADER_BUIENRADAR_API_URL)
35-
response = requests.get(settings.DSMRREADER_BUIENRADAR_API_URL)
35+
36+
try:
37+
response = requests.get(settings.DSMRREADER_BUIENRADAR_API_URL)
38+
except Exception as error:
39+
logger.exception(error)
40+
raise AssertionError(_('Failed to connect to or read from Buienradar API'))
3641

3742
if response.status_code != 200:
3843
logger.error('Buienradar: Failed reading temperature: HTTP %s', response.status_code)
39-
raise EnvironmentError('Unexpected status code received')
44+
raise AssertionError(_('Unexpected status code received'))
4045

4146
# Find our selected station.
4247
station_id = WeatherSettings.get_solo().buienradar_station
4348
station_data = [x for x in response.json()['actual']['stationmeasurements'] if x['stationid'] == station_id]
4449

4550
if not station_data:
46-
raise EnvironmentError('Selected station info not found')
51+
raise AssertionError(_('Selected station info not found'))
4752

4853
temperature = station_data[0]['groundtemperature']
4954
logger.debug('Buienradar: Read temperature: %s', temperature)

dsmr_weather/tests/test_services.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def setUp(self):
2424
@mock.patch('django.utils.timezone.now')
2525
def test_exception_handling(self, now_mock, get_temperature_from_api_mock, display_dashboard_message_mock):
2626
now_mock.return_value = timezone.make_aware(timezone.datetime(2017, 1, 1))
27-
get_temperature_from_api_mock.side_effect = EnvironmentError('TEST') # Simulate any exception.
27+
get_temperature_from_api_mock.side_effect = AssertionError('TEST') # Simulate any exception.
2828

2929
dsmr_weather.services.run(self.schedule_process)
3030
self.assertTrue(display_dashboard_message_mock.called)
@@ -60,13 +60,22 @@ def test_okay(self, now_mock, requests_mock):
6060

6161
@mock.patch('requests.get')
6262
@mock.patch('django.utils.timezone.now')
63-
def test_fail_http(self, now_mock, requests_mock):
63+
def test_fail_http_connection(self, now_mock, requests_mock):
64+
now_mock.return_value = timezone.make_aware(timezone.datetime(2017, 1, 1))
65+
requests_mock.side_effect = IOError('Failed to connect') # Any error is fine.
66+
67+
with self.assertRaises(AssertionError):
68+
dsmr_weather.services.get_temperature_from_api()
69+
70+
@mock.patch('requests.get')
71+
@mock.patch('django.utils.timezone.now')
72+
def test_fail_http_response(self, now_mock, requests_mock):
6473
now_mock.return_value = timezone.make_aware(timezone.datetime(2017, 1, 1))
6574
response_mock = mock.MagicMock()
6675
type(response_mock).status_code = mock.PropertyMock(return_value=500)
6776
requests_mock.return_value = response_mock
6877

69-
with self.assertRaises(EnvironmentError):
78+
with self.assertRaises(AssertionError):
7079
dsmr_weather.services.get_temperature_from_api()
7180

7281
@mock.patch('requests.get')
@@ -85,5 +94,5 @@ def test_fail_station(self, now_mock, requests_mock):
8594
type(response_mock).status_code = mock.PropertyMock(return_value=200)
8695
requests_mock.return_value = response_mock
8796

88-
with self.assertRaises(EnvironmentError):
97+
with self.assertRaises(AssertionError):
8998
dsmr_weather.services.get_temperature_from_api()

dsmrreader/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.utils.version import get_version
22

3-
VERSION = (2, 11, 0, 'beta', 2)
3+
VERSION = (2, 11, 0, 'beta', 3)
44

55
__version__ = get_version(VERSION)
212 Bytes
Binary file not shown.

dsmrreader/locales/nl/LC_MESSAGES/django.po

+11-2
Original file line numberDiff line numberDiff line change
@@ -1300,8 +1300,8 @@ msgstr "Exporteren naar MinderGas gefaald: {}"
13001300
msgid "No recent gas reading found"
13011301
msgstr "Geen recente gasmeting gevonden"
13021302

1303-
msgid "Invalid status code"
1304-
msgstr "Ongeldige statuscode"
1303+
msgid "Unexpected status code received"
1304+
msgstr "Onverwachte statuscode ontvangen"
13051305

13061306
msgid "Detailed instructions for configuring MQTT can be found here: <a href=\"https://dsmr-reader.readthedocs.io/nl/v2/mqtt.html\">Documentation</a>"
13071307
msgstr "Gedetailleerde instructies voor configureren van MQTT kun je hier terugvinden: <a href=\"https://dsmr-reader.readthedocs.io/nl/v2/mqtt.html\">Documentatie</a>"
@@ -2179,12 +2179,21 @@ msgstr "Weergegevensconfiguratie"
21792179
msgid "Failed to read Buienradar API: {}"
21802180
msgstr "Uitlezen van Buienradar API mislukt: {}"
21812181

2182+
msgid "Failed to connect to or read from Buienradar API"
2183+
msgstr "Kan niet verbinden naar of lezen van de Buienradar API"
2184+
2185+
msgid "Selected station info not found"
2186+
msgstr "Geselecteerd weerstation niet gevonden"
2187+
21822188
msgid "Dutch"
21832189
msgstr "Nederlands"
21842190

21852191
msgid "English"
21862192
msgstr "Engels"
21872193

2194+
#~ msgid "Invalid status code"
2195+
#~ msgstr "Ongeldige statuscode"
2196+
21882197
#~ msgid "Internals"
21892198
#~ msgstr "Intern"
21902199

0 commit comments

Comments
 (0)