Skip to content
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
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
interval: weekly
open-pull-requests-limit: 10
assignees:
- thenativeweb/internal_dev
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ analyze:
format:
@poetry run autopep8 --in-place --aggressive --max-line-length=100 --recursive eventsourcingdb tests

lock:
@poetry lock

test:
@poetry run pytest --maxfail=1

clean:

build: qa clean

.PHONY: analyze build clean format qa test
.PHONY: analyze build clean format lock qa test
7 changes: 4 additions & 3 deletions eventsourcingdb/handlers/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# CloudEvent field names
SPECVERSION_FIELD = "specversion"
TYPE_FIELD = "type"
PING_RECEIVED_TYPE = "io.eventsourcingdb.ping-received"
PING_RECEIVED_TYPE = "io.eventsourcingdb.api.ping-received"


async def ping(client: AbstractBaseClient) -> None:
Expand All @@ -34,8 +34,9 @@ async def ping(client: AbstractBaseClient) -> None:
isinstance(response_json, dict)
and SPECVERSION_FIELD in response_json
and TYPE_FIELD in response_json
and response_json.get(TYPE_FIELD) == PING_RECEIVED_TYPE
):
if response_json.get(TYPE_FIELD) == PING_RECEIVED_TYPE:
return
return


raise ServerError(f"Received unexpected response: {response_body}")
15 changes: 10 additions & 5 deletions eventsourcingdb/handlers/read_event_types/event_type.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import TypeVar
from typing import TypeVar, Any

from ...errors.validation_error import ValidationError

Expand All @@ -10,10 +10,10 @@
class EventType:
event_type: str
is_phantom: bool
schema: str | None = None
schema: dict[str, Any] | None = None

@staticmethod
def parse(unknown_object: dict) -> Self:
def parse(unknown_object: dict) -> "EventType":
event_type = unknown_object.get('eventType')
if not isinstance(event_type, str):
raise ValidationError(
Expand All @@ -27,9 +27,9 @@ def parse(unknown_object: dict) -> Self:
)

schema = unknown_object.get('schema')
if schema is not None and not isinstance(schema, str):
if schema is not None and not isinstance(schema, (dict)):
raise ValidationError(
f"Failed to parse schema '{schema}' to str."
f"Failed to parse schema '{schema}'. Schema must be dict."
)

return EventType(
Expand All @@ -39,4 +39,9 @@ def parse(unknown_object: dict) -> Self:
)

def __hash__(self):
# Convert dictionary schema to a hashable form (tuple of items)
if isinstance(self.schema, dict):
# Sort items to ensure consistent hashing
schema_items = tuple(sorted((k, str(v)) for k, v in self.schema.items()))
Comment thread
atstaeff marked this conversation as resolved.
return hash((self.event_type, self.is_phantom, schema_items))
return hash((self.event_type, self.is_phantom, self.schema))
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from http import HTTPStatus
from typing import Any

from ...abstract_base_client import AbstractBaseClient
from ...errors.custom_error import CustomError
Expand All @@ -14,7 +15,7 @@
async def register_event_schema(
client: AbstractBaseClient,
event_type: str,
json_schema: str,
json_schema: dict[str, Any],
) -> None:
try:
validate_type(event_type)
Expand All @@ -27,7 +28,7 @@ async def register_event_schema(

request_body = json.dumps({
'eventType': event_type,
'schema': json_schema,
'schema': json_schema,
})

response: Response
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/shared/docker/eventsourcingdb/Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM thenativeweb/eventsourcingdb:0.103.1
FROM thenativeweb/eventsourcingdb:0.113.2
14 changes: 10 additions & 4 deletions tests/test_read_event_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ async def test_reads_all_types_of_existing_events_and_registered_schemas(
),
])

await client.register_event_schema("org.ban.ban", '{"type":"object"}')
await client.register_event_schema("org.bing.chilling", '{"type":"object"}')
await client.register_event_schema(
"org.ban.ban",
{"type": "object"} # type: ignore
)
await client.register_event_schema(
"org.bing.chilling",
{"type": "object"} # type: ignore
)

actual_event_types: set[EventType] = set()
async for event_type in client.read_event_types():
Expand Down Expand Up @@ -81,12 +87,12 @@ async def test_reads_all_types_of_existing_events_and_registered_schemas(
EventType(
event_type="org.ban.ban",
is_phantom=True,
schema='{"type":"object"}',
schema={"type": "object"},
),
EventType(
event_type="org.bing.chilling",
is_phantom=True,
schema='{"type":"object"}',
schema={"type": "object"},
),
}

Expand Down
13 changes: 8 additions & 5 deletions tests/test_register_event_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ async def test_registers_new_schema_if_it_doesnt_conflict_with_existing_events(
):
client = database.with_authorization.client

await client.register_event_schema("com.bar.baz", '{"type":"object"}')
await client.register_event_schema(
"com.bar.baz",
{"type": "object"}
)

@staticmethod
@pytest.mark.asyncio
Expand All @@ -48,7 +51,7 @@ async def test_throws_error_if_schema_conflicts_with_existing_events(
with pytest.raises(ClientError, match="additionalProperties"):
await client.register_event_schema(
"com.gornisht.ekht",
'{"type":"object","additionalProperties":false}'
{"type": "object", "additionalProperties": False}
)

@staticmethod
Expand All @@ -60,13 +63,13 @@ async def test_throws_error_if_schema_already_exists(

await client.register_event_schema(
"com.gornisht.ekht",
'{"type":"object","additionalProperties":false}'
{"type": "object", "additionalProperties": False}
)

with pytest.raises(ClientError, match="schema already exists"):
await client.register_event_schema(
"com.gornisht.ekht",
'{"type":"object","additionalProperties":false}'
{"type": "object", "additionalProperties": False}
)

@staticmethod
Expand All @@ -77,7 +80,7 @@ async def test_throws_error_if_schema_is_invalid(
client = database.with_authorization.client

with pytest.raises(ClientError, match="'/type' does not validate"):
await client.register_event_schema("com.gornisht.ekht", '{"type":"gurkenwasser"}')
await client.register_event_schema("com.gornisht.ekht", {"type": "gurkenwasser"})


class TestRegisterEventSchemaWithMockServer:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_write_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ async def test_throws_error_if_event_does_not_match_schema(

await client.register_event_schema(
"com.super.duper",
'{"type":"object","additionalProperties":false}'
{"type": "object", "additionalProperties": False}
)

with pytest.raises(ClientError, match="event candidate does not match schema"):
Expand Down