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(drivers-event-listener-griptape-cloud): add type/timestamp fallbacks for custom events #1758

Merged
merged 1 commit into from
Feb 24, 2025
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os
import time
from typing import Optional
from urllib.parse import urljoin

Expand Down Expand Up @@ -72,8 +73,8 @@ def try_publish_event_payload_batch(self, event_payload_batch: list[dict]) -> No
def _get_event_request(self, event_payload: dict) -> dict:
return {
"payload": event_payload,
"timestamp": event_payload["timestamp"],
"type": event_payload["type"],
"timestamp": event_payload.get("timestamp", time.time()),
"type": event_payload.get("type", "UserEvent"),
}

def _post_event(self, json: list[dict] | dict) -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import time
from unittest.mock import MagicMock, Mock
from unittest.mock import ANY, MagicMock, Mock

import pytest

Expand Down Expand Up @@ -104,3 +104,27 @@ def test_try_publish_event_payload_batch(self, mock_post, driver):
json=driver._get_event_request(event.to_dict()),
headers={"Authorization": "Bearer foo bar"},
)

@pytest.mark.parametrize(
("event", "expected"),
[
(
MockEvent().to_dict(),
{
"payload": {
"id": ANY,
"meta": {},
"timestamp": ANY,
"type": "MockEvent",
},
"timestamp": ANY,
"type": "MockEvent",
},
),
({}, {"payload": {}, "timestamp": ANY, "type": "UserEvent"}),
],
)
def test__get_event_request(self, driver, event, expected):
result = driver._get_event_request(event)

assert result == expected