Skip to content

Commit

Permalink
Merge pull request #9 from cloudblue/LITE-23458-add-event-definitions…
Browse files Browse the repository at this point in the history
…-in-setup-response

LITE-23458 add event definitions to setup response
  • Loading branch information
Francesco Faraone authored May 5, 2022
2 parents bbaf76d + cdfa074 commit 9b7ac68
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions connect/eaas/core/proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,19 @@ class Logging(BaseModel):
meta: Optional[LogMeta]


class EventDefinition(BaseModel):
event_type: str
api_resource_endpoint: str
api_collection_endpoint: str
api_collection_filter: str


class SetupResponse(BaseModel):
variables: Optional[dict]
# delete after stop using version 1
environment_type: Optional[str]
logging: Optional[Logging]
event_definitions: Optional[List[EventDefinition]]


class Schedulable(BaseModel):
Expand Down
27 changes: 27 additions & 0 deletions tests/connect/eaas/core/test_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

from connect.eaas.core.proto import (
EventDefinition,
Logging,
LogMeta,
Message,
Expand Down Expand Up @@ -133,6 +134,7 @@
'hub_id': None,
},
},
'event_definitions': None,
}
SETUP_RESPONSE_DATA_V1 = {
'configuration': {'conf1': 'val1'},
Expand Down Expand Up @@ -396,3 +398,28 @@ def test_serialize_v2(msg_type, data):
assert serialized['version'] == 2
assert serialized['message_type'] == msg_type
assert serialized['data'] == data


def test_serialize_setup_response_with_events_definitions():
data = copy.deepcopy(SETUP_RESPONSE_DATA)
data['event_definitions'] = [
{
'event_type': 'event_type',
'api_resource_endpoint': 'api_resource_endpoint',
'api_collection_endpoint': 'api_collection_endpoint',
'api_collection_filter': 'api_collection_filter',
},
]
msg = Message(
version=2,
message_type=MessageType.SETUP_RESPONSE,
data=data,
)

assert isinstance(msg.data.event_definitions[0], EventDefinition)

serialized = msg.serialize()

assert serialized['version'] == 2
assert serialized['message_type'] == MessageType.SETUP_RESPONSE
assert serialized['data'] == data

0 comments on commit 9b7ac68

Please sign in to comment.