Add generic ENLYZE power meter pipeline

This commit is contained in:
2026-10-01 11:59:34 +02:00
parent 4a3ed625ce
commit e9f9cf6f3c
15 changed files with 680 additions and 4 deletions
+23
View File
@@ -9,6 +9,7 @@ from production_analytics.enlyze.exploration import (
AuthenticationError,
ExplorationClient,
ExplorationSettings,
HttpResponseError,
NonJsonResponseError,
load_secret_file,
)
@@ -78,6 +79,28 @@ class ExplorationClientTests(unittest.TestCase):
with self.assertRaisesRegex(AuthenticationError, "HTTP 401"):
ExplorationClient(self.settings).get("/observed/path")
@patch("production_analytics.enlyze.exploration.urlopen")
def test_http_error_keeps_sanitized_bounded_body(self, urlopen_mock: object) -> None:
urlopen_mock.side_effect = HTTPError(
"https://example.invalid", 422, "Unprocessable", {},
io.BytesIO(b'{"message":"bad variable","token":"must not echo"}'),
) # type: ignore[attr-defined]
with self.assertRaises(HttpResponseError) as caught:
ExplorationClient(self.settings).get("/observed/path")
self.assertEqual(caught.exception.response_body["message"], "bad variable")
self.assertEqual(caught.exception.response_body["token"], "<redacted-secret>")
@patch("production_analytics.enlyze.exploration.urlopen")
def test_get_all_pages_follows_cursor(self, urlopen_mock: object) -> None:
urlopen_mock.side_effect = [
_Response(b'{"data":[1],"metadata":{"next_cursor":"next"}}'),
_Response(b'{"data":[2],"metadata":{"next_cursor":null}}'),
]
pages = ExplorationClient(self.settings).get_all_pages("/v2/variables", {"machine": "m"})
self.assertEqual([page.body["data"] for page in pages], [[1], [2]])
class SanitizationTests(unittest.TestCase):
def test_sanitization_preserves_shape_and_redacts_sensitive_values(self) -> None: