Skip to content

Commit

Permalink
Don't check certificate in meteoview
Browse files Browse the repository at this point in the history
  • Loading branch information
aptiko committed Jun 7, 2024
1 parent a0389d3 commit 818973b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions enhydris/telemetry/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def test_logs_on(self):
"data": json.dumps(
{"email": "[email protected]", "key": "topsecret"}
),
"verify": False,
},
)

Expand Down
15 changes: 13 additions & 2 deletions enhydris/telemetry/tests/test_types/test_meteoview2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from unittest import TestCase
from unittest.mock import MagicMock, patch

import requests
from freezegun import freeze_time
from requests import Timeout

from enhydris.models import Timeseries
from enhydris.telemetry import TelemetryError
Expand Down Expand Up @@ -55,7 +55,7 @@ def setUp(self):
@patch("enhydris.telemetry.types.meteoview2.requests.request")
class MakeRequestTestCase(TelemetryAPIClientTestCaseBase):
def test_raises_on_bad_status_code(self, mock_request):
mock_request.return_value.raise_for_status.side_effect = Timeout
mock_request.return_value.raise_for_status.side_effect = requests.Timeout
with self.assertRaises(TelemetryError):
self.telemetry_api_client.make_request("GET", "/")

Expand All @@ -69,6 +69,11 @@ def test_raises_when_code_is_not_200(self, mock_request):
with self.assertRaises(TelemetryError):
self.telemetry_api_client.make_request("GET", "/")

def test_raises_on_ssl_error(self, mock_request):
mock_request.side_effect = requests.exceptions.SSLError
with self.assertRaises(TelemetryError):
self.telemetry_api_client.make_request("GET", "/")

def test_ok_when_code_is_200(self, mock_request):
mock_request.return_value.json.return_value = {"code": "200"}
self.assertEqual(
Expand All @@ -88,6 +93,7 @@ def test_makes_request(self, mock_request):
data=json.dumps(
{"email": "[email protected]", "key": "topsecretapikey"}
),
verify=False,
)

def test_sets_token(self, mock_request):
Expand Down Expand Up @@ -117,6 +123,7 @@ def test_makes_request(self, mock_request):
"POST",
"https://meteoview2.gr/api/stations",
headers={"Authorization": "Bearer topsecretapitoken"},
verify=False,
)

def test_returns_stations(self, mock_request):
Expand Down Expand Up @@ -149,6 +156,7 @@ def test_makes_request(self, mock_request):
"Authorization": "Bearer topsecretapitoken",
},
data=json.dumps({"station_code": 823}),
verify=False,
)

def test_returns_sensors(self, mock_request):
Expand Down Expand Up @@ -213,6 +221,7 @@ def test_ignores_timezone(self, mock_request):
"dateto": "2022-12-11",
}
),
"verify": False,
},
)

Expand Down Expand Up @@ -249,6 +258,7 @@ def test_makes_request(self, mock_request):
"dateto": "2022-12-11",
}
),
verify=False,
)

def test_return_value(self, mock_request):
Expand Down Expand Up @@ -284,6 +294,7 @@ def test_request_when_no_start_date(self, mock_request):
"dateto": "1990-06-30",
}
),
verify=False,
)

def _set_successful_request_result(self, mock_request):
Expand Down
4 changes: 2 additions & 2 deletions enhydris/telemetry/types/meteoview2.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ def make_request(self, method, url, *args, **kwargs):
kwargs.setdefault("headers", {})
kwargs["headers"]["content-type"] = "application/json"
kwargs["data"] = json.dumps(kwargs["data"])
response = requests.request(method, url, *args, **kwargs)
try:
response = requests.request(method, url, verify=False, *args, **kwargs)
response.raise_for_status()
except requests.RequestException as e:
except (requests.exceptions.SSLError, requests.RequestException) as e:
raise TelemetryError(str(e))
data = response.json()
if "code" not in data:
Expand Down

0 comments on commit 818973b

Please sign in to comment.