Skip to content

Commit

Permalink
Updated packages and improved test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbywater committed Jul 15, 2024
1 parent 4182316 commit ed3d190
Show file tree
Hide file tree
Showing 8 changed files with 354 additions and 496 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
eventstore-image-tag: [ "21.10.9-buster-slim", "22.10.3-buster-slim", "23.10.0-bookworm-slim" ]
env:
EVENTSTORE_IMAGE_TAG: ${{ matrix.eventstore-image-tag }}
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ start-eventstoredb-insecure:
--env "EVENTSTORE_ADVERTISE_HTTP_PORT_TO_CLIENT_AS=2113" \
--name my-eventstoredb-insecure \
$(EVENTSTORE_IMAGE_NAME):$(EVENTSTORE_IMAGE_TAG) \
--insecure
--insecure \
--enable-atom-pub-over-http

.PHONY: start-eventstoredb-secure
start-eventstoredb-secure:
Expand Down
18 changes: 4 additions & 14 deletions eventsourcing_eventstoredb/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,10 @@ def __init__(self, env: Environment):
f"{', '.join(self.env.create_keys(self.EVENTSTOREDB_URI))!r}"
)
root_certificates = self.env.get(self.EVENTSTOREDB_ROOT_CERTIFICATES)
try:
self.client = EventStoreDBClient(
uri=eventstoredb_uri,
root_certificates=root_certificates,
)
except ValueError as e:
if "root_certificates" in e.args[0]:
raise EnvironmentError(
"Please configure environment variable "
f"'{self.EVENTSTOREDB_ROOT_CERTIFICATES}' "
"when connecting to a secure server."
) from e
else:
raise
self.client = EventStoreDBClient(
uri=eventstoredb_uri,
root_certificates=root_certificates,
)

def aggregate_recorder(self, purpose: str = "events") -> AggregateRecorder:
return EventStoreDBAggregateRecorder(
Expand Down
16 changes: 7 additions & 9 deletions eventsourcing_eventstoredb/recorders.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ def _insert_events(
limit=1,
)
)
if len(recorded_snapshots) > 0:
last_snapshot = recorded_snapshots[0]
if (
last_snapshot.originator_version
> stored_events[0].originator_version
):
return []
if (
len(recorded_snapshots) > 0
and recorded_snapshots[0].originator_version
> stored_events[0].originator_version
):
return []
else:
# Make sure all stored events have same originator ID.
originator_ids = list(set([e.originator_id for e in stored_events]))
Expand Down Expand Up @@ -229,8 +228,7 @@ def select_notifications(
# subtract 1, and then drop the first event.
if start > 0:
start_commit_position = start - 1
if limit is not None:
limit += 1
limit += 1
else:
start_commit_position = None

Expand Down
771 changes: 308 additions & 463 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "eventsourcing-eventstoredb"
version = "1.0.1"
version = "1.1"
description = "Python package for eventsourcing with EventStoreDB"
authors = [
"John Bywater <[email protected]>",
Expand All @@ -15,7 +15,6 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python",
Expand All @@ -26,11 +25,11 @@ repository = "https://github.com/pyeventsourcing/eventsourcing-eventstoredb"
include = ["eventsourcing_eventstoredb/py.typed"]

[tool.poetry.dependencies]
python = "^3.7"
python = "^3.8"
eventsourcing = { version = "~9.2.14" }
#eventsourcing = { path = "../eventsourcing/", develop = true }
#esdbclient = { path = "../esdbclient/", develop = true }
esdbclient = "^1"
esdbclient = { version = "~1.1.0" }


[tool.poetry.dev-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from itertools import chain
from uuid import uuid4

from esdbclient.exceptions import SSLError
from eventsourcing.application import Application, EventSourcedLog
from eventsourcing.domain import Aggregate, DomainEvent
from eventsourcing.system import NotificationLogReader
Expand Down Expand Up @@ -287,10 +288,9 @@ def test_construct_without_uri(self) -> None:
self.assertIn("EVENTSTOREDB_URI", str(cm.exception))

def test_construct_secure_without_root_certificates(self) -> None:
os.environ["EVENTSTOREDB_URI"] = "esdb://localhost"
with self.assertRaises(EnvironmentError) as cm:
os.environ["EVENTSTOREDB_URI"] = "esdb://admin:changeit@localhost"
with self.assertRaises(SSLError):
BankAccounts(env={"IS_SNAPSHOTTING_ENABLED": "y"})
self.assertIn("EVENTSTOREDB_ROOT_CERTIFICATES", str(cm.exception))


del ExampleApplicationTestCase
27 changes: 26 additions & 1 deletion tests/test_recorders.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
from typing import cast
from uuid import uuid4

from esdbclient import EventStoreDBClient
from esdbclient import EventStoreDBClient, NewEvent, StreamState
from eventsourcing.persistence import (
AggregateRecorder,
ApplicationRecorder,
PersistenceError,
ProgrammingError,
StoredEvent,
)
Expand Down Expand Up @@ -476,6 +478,29 @@ def test_insert_select(self) -> None:
self.assertEqual(notifications[1].originator_id, originator_id1)
self.assertEqual(notifications[1].originator_version, self.INITIAL_VERSION + 1)

# Cover exception handling when stream name is not a UUID.
max_notification_id4 = recorder.max_notification_id()

cast(EventStoreDBApplicationRecorder, recorder).client.append_to_stream(
stream_name=f"not-a-uuid-{uuid4()}",
events=NewEvent(type="SomethingHappened", data=b"{}"),
current_version=StreamState.NO_STREAM,
)
with self.assertRaises(ValueError) as cm1:
recorder.select_notifications(
start=max_notification_id4 + 1, limit=10, stop=max_notification_id2
)
self.assertIn("badly formed hexadecimal UUID string", str(cm1.exception))

# Cover non-wrong-current-version exception handling when appending events.
cast(EventStoreDBApplicationRecorder, recorder).client.close()
cast(
EventStoreDBApplicationRecorder, recorder
).client.connection_spec._targets = ["127.0.0.1:1000"]
with self.assertRaises(PersistenceError) as cm2:
recorder.insert_events([stored_event3])
self.assertIn("failed to connect", str(cm2.exception))

def test_concurrent_no_conflicts(self) -> None:
super().test_concurrent_no_conflicts()

Expand Down

0 comments on commit ed3d190

Please sign in to comment.