From c9962648fcbab7bcf9b817b9bdc224260e30fdd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20T=C3=A9tard?= Date: Fri, 29 Mar 2024 12:45:57 +0100 Subject: [PATCH] test: Autoconfigure intake URL in storage --- tests/connectors/test_connector.py | 29 +++++++++++-------- .../connector_sample_connector.json | 3 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/tests/connectors/test_connector.py b/tests/connectors/test_connector.py index 5ed868e..25a9d34 100644 --- a/tests/connectors/test_connector.py +++ b/tests/connectors/test_connector.py @@ -1,4 +1,3 @@ -import os from unittest.mock import Mock, PropertyMock, patch import pytest @@ -14,6 +13,12 @@ EVENTS = ["foo", "bar"] +@pytest.fixture(autouse=True) +def configure_intake_url(config_storage): + with (config_storage / "intake_url").open("w") as f: + f.write("https://intake.sekoia.io") + + class DummyConnector(Connector): def run(self): raise NotImplementedError @@ -136,25 +141,25 @@ def test_push_event_to_intake_with_chunks(test_connector, mocked_trigger_logs): assert result == ["001", "002", "003", "004"] -def test_push_event_to_intake_custom_url(test_connector, mocked_trigger_logs): +def test_push_event_to_intake_custom_url( + test_connector, mocked_trigger_logs, config_storage +): url = "https://fra2.app.sekoia.io/v1/intake-http/batch" batch_mock = mocked_trigger_logs.post( url, json={"event_ids": ["001"]}, additional_matcher=match_events("foo") ) # With trailing slash - with patch.dict( - os.environ, {"INTAKE_URL": "https://fra2.app.sekoia.io/v1/intake-http/"} - ): - test_connector.push_events_to_intakes(["foo"]) - assert batch_mock.call_count == 1 + with (config_storage / "intake_url").open("w") as f: + f.write("https://fra2.app.sekoia.io/v1/intake-http/") + test_connector.push_events_to_intakes(["foo"]) + assert batch_mock.call_count == 1 # Without trailing slash + with (config_storage / "intake_url").open("w") as f: + f.write("https://fra2.app.sekoia.io/v1/intake-http") mocked_trigger_logs.reset_mock() - with patch.dict( - os.environ, {"INTAKE_URL": "https://fra2.app.sekoia.io/v1/intake-http"} - ): - test_connector.push_events_to_intakes(["foo"]) - assert batch_mock.call_count == 1 + test_connector.push_events_to_intakes(["foo"]) + assert batch_mock.call_count == 1 def test_push_event_to_intake_with_chunks_executor_stopped( diff --git a/tests/expectations/sample_module/connector_sample_connector.json b/tests/expectations/sample_module/connector_sample_connector.json index a15b2e5..822d4c9 100644 --- a/tests/expectations/sample_module/connector_sample_connector.json +++ b/tests/expectations/sample_module/connector_sample_connector.json @@ -9,7 +9,6 @@ "properties": { "intake_server": { "title": "Intake Server", - "default": "https://intake.sekoia.io", "type": "string" }, "intake_key": { @@ -22,4 +21,4 @@ ] }, "results": {} -} \ No newline at end of file +}