Public Access
make temperature proxy host and port configurable in the configuration tab
This commit is contained in:
1 parent
f562255c75
commit
5f558e4f03
4 files changed
+62
-12
No files matched your search
@@ -22,7 +22,7 @@ class TestTemperatureProxyClient(unittest.TestCase):
|
||||
return io.BytesIO(json.dumps(payload).encode("utf-8"))
|
||||
|
||||
@patch("damaris.gui.TemperatureProxyClient.urlopen")
|
||||
def test_get_history_uses_fixed_endpoint_and_converts_readings(self, mock_urlopen):
|
||||
def test_get_history_uses_default_endpoint_and_converts_readings(self, mock_urlopen):
|
||||
mock_urlopen.return_value = self.response({
|
||||
"readings": [
|
||||
{"t": 101.5, "pv": 293.15},
|
||||
@@ -35,13 +35,25 @@ class TestTemperatureProxyClient(unittest.TestCase):
|
||||
args, kwargs = mock_urlopen.call_args
|
||||
parsed_url = urlparse(args[0])
|
||||
self.assertEqual(parsed_url.scheme, "http")
|
||||
self.assertEqual(parsed_url.netloc, "localhost:8000")
|
||||
self.assertEqual(parsed_url.netloc, "127.0.0.1:18007")
|
||||
self.assertEqual(parsed_url.path, "/v1/readings")
|
||||
self.assertEqual(parse_qs(parsed_url.query), {"start": ["100.0"], "end": ["110.0"]})
|
||||
self.assertEqual(kwargs, {"timeout": TemperatureProxyClient.TIMEOUT})
|
||||
self.assertEqual(result.x, [1.5, 4.0])
|
||||
self.assertEqual(result.y, [293.15, 294.25])
|
||||
|
||||
@patch("damaris.gui.TemperatureProxyClient.urlopen")
|
||||
def test_custom_host_and_port_are_used(self, mock_urlopen):
|
||||
mock_urlopen.return_value = self.response({"readings": [{"t": 101.0, "pv": 293.0}]})
|
||||
|
||||
client = TemperatureProxyClient(host="proxy.example.org", port=9000)
|
||||
client.get_history(100.0, 110.0)
|
||||
|
||||
args, _ = mock_urlopen.call_args
|
||||
parsed_url = urlparse(args[0])
|
||||
self.assertEqual(parsed_url.netloc, "proxy.example.org:9000")
|
||||
self.assertEqual(parsed_url.path, "/v1/readings")
|
||||
|
||||
@patch("damaris.gui.TemperatureProxyClient.urlopen")
|
||||
def test_empty_readings_return_none(self, mock_urlopen):
|
||||
mock_urlopen.return_value = self.response({"readings": []})
|
||||
@@ -62,7 +74,7 @@ class TestTemperatureProxyClient(unittest.TestCase):
|
||||
OSError("connection refused"),
|
||||
TimeoutError("request timed out"),
|
||||
http.client.BadStatusLine("not an HTTP response"),
|
||||
HTTPError(TemperatureProxyClient.URL, 500, "server error", {}, None),
|
||||
HTTPError(self.client.url, 500, "server error", {}, None),
|
||||
)
|
||||
for failure in failures:
|
||||
with self.subTest(failure=failure):
|
||||
|
||||
Reference in new issue
Block a user