Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixes batch url computation #90

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fixes batch url computation

## [1.6.0] - 2023-10-20

### Added
Expand Down
4 changes: 2 additions & 2 deletions sekoia_automation/connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from concurrent.futures import wait as wait_futures
from datetime import datetime, time
from functools import cached_property
from os.path import join as urljoin
from typing import Any
from urllib.parse import urljoin

import orjson
import requests
Expand Down Expand Up @@ -150,7 +150,7 @@ def push_events_to_intakes(
self._error_count = 0
self._last_events_time = datetime.utcnow()
intake_host = os.getenv("INTAKE_URL", self.configuration.intake_server)
batch_api = urljoin(intake_host, "/batch")
batch_api = urljoin(intake_host, "batch")

# Dict to collect event_ids for the API
collect_ids: dict[int, list] = {}
Expand Down
22 changes: 22 additions & 0 deletions tests/connectors/test_connector.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from unittest.mock import Mock, PropertyMock, patch

import pytest
Expand Down Expand Up @@ -124,6 +125,27 @@ 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):
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

# Without trailing slash
mocked_trigger_logs.reset_mock()
with patch.dict(
os.environ, {"INTAKE_URL": "https://fra2.app.sekoia.io/v1/intake-http"}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure the test is doing what you want, when testing on cli, the url generated seems incorrect :/

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not relevant due to import updated.

):
test_connector.push_events_to_intakes(["foo"])
assert batch_mock.call_count == 1


def test_push_event_to_intake_with_chunks_executor_stopped(
test_connector, mocked_trigger_logs
):
Expand Down
Loading