Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
a-leonardi committed Oct 9, 2023
1 parent 5ed6672 commit a895e7f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
6 changes: 4 additions & 2 deletions sekoia_automation/connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ class DefaultConnectorConfiguration(BaseModel):

class Connector(Trigger, ABC):
CONNECTOR_CONFIGURATION_FILE_NAME = "connector-configuration"

seconds_without_events = 3600 * 6

@property # type: ignore[override]
# Required for Pydantic to correctly type the configuration object
configuration: DefaultConnectorConfiguration

@property # type: ignore[override, no-redef]
def configuration(self) -> DefaultConnectorConfiguration:
if self._configuration is None:
try:
Expand Down
30 changes: 28 additions & 2 deletions tests/connectors/test_connector.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from unittest.mock import Mock, patch
from unittest.mock import Mock, PropertyMock, patch

import pytest
from tenacity import Retrying, stop_after_attempt, wait_none

from sekoia_automation.connector import Connector
from sekoia_automation.connector import Connector, DefaultConnectorConfiguration
from sekoia_automation.constants import CHUNK_BYTES_MAX_SIZE, EVENT_BYTES_MAX_SIZE
from sekoia_automation.exceptions import TriggerConfigurationError
from sekoia_automation.module import Module
from sekoia_automation.trigger import Trigger
from tests.utils import match_events

EVENTS = ["foo", "bar"]
Expand Down Expand Up @@ -194,3 +196,27 @@ def test_query_exception_api(test_connector, requests_mock):
)
test_connector._retry = lambda: Retrying(reraise=True)
assert test_connector.push_events_to_intakes(EVENTS) == ["001", "002"]


def test_connector_configuration(test_connector):
test_connector._configuration = None
config = DefaultConnectorConfiguration(intake_key="foo")
with patch.object(
Module, "load_config", return_value=config
) as mock_load_config, patch("sentry_sdk.set_context") as mock_set_sentry_context:
assert test_connector.configuration == config
mock_set_sentry_context.assert_called_with(
"connector_configuration", config.dict()
)
mock_load_config.assert_called_with(
test_connector.CONNECTOR_CONFIGURATION_FILE_NAME, "json"
)


def test_connector_configuration_file_not_found(test_connector):
test_connector._configuration = None
config = "foo"
with patch.object(
Trigger, "configuration", new_callable=PropertyMock, return_value=config
):
assert test_connector.configuration == config

0 comments on commit a895e7f

Please sign in to comment.