Skip to content

Commit

Permalink
Updated packages and reformatted (new black).
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbywater committed Mar 28, 2024
1 parent ffd9c4b commit 4aef44e
Show file tree
Hide file tree
Showing 5 changed files with 489 additions and 499 deletions.
28 changes: 16 additions & 12 deletions eventsourcing/examples/contentmanagementsystem/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,27 @@ def policy(
processing_event: ProcessingEvent,
) -> None:
if isinstance(domain_event, Page.Created):
processing_event.saved_kwargs["insert_pages"] = [(
domain_event.originator_id,
domain_event.slug,
domain_event.title,
domain_event.body,
)]
processing_event.saved_kwargs["insert_pages"] = [
(
domain_event.originator_id,
domain_event.slug,
domain_event.title,
domain_event.body,
)
]
elif isinstance(domain_event, Page.BodyUpdated):
recorder = cast(SearchableContentRecorder, self.recorder)
page_id = domain_event.originator_id
page_slug, page_title, page_body = recorder.select_page(page_id)
page_body = apply_patch(page_body, domain_event.diff)
processing_event.saved_kwargs["update_pages"] = [(
page_id,
page_slug,
page_title,
page_body,
)]
processing_event.saved_kwargs["update_pages"] = [
(
page_id,
page_slug,
page_title,
page_body,
)
]

def search(self, query: str) -> List[UUID]:
recorder = cast(SearchableContentRecorder, self.recorder)
Expand Down
52 changes: 28 additions & 24 deletions eventsourcing/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,41 @@ def get_log_section(self, section_id: str) -> str:
from a notification log.
"""
section = self.app.notification_log[section_id]
return json.dumps({
"id": section.id,
"next_id": section.next_id,
"items": [
{
"id": item.id,
"originator_id": item.originator_id.hex,
"originator_version": item.originator_version,
"topic": item.topic,
"state": b64encode(item.state).decode("utf8"),
}
for item in section.items
],
})
return json.dumps(
{
"id": section.id,
"next_id": section.next_id,
"items": [
{
"id": item.id,
"originator_id": item.originator_id.hex,
"originator_version": item.originator_version,
"topic": item.topic,
"state": b64encode(item.state).decode("utf8"),
}
for item in section.items
],
}
)

def get_notifications(
self, start: int, limit: int, topics: Sequence[str] = ()
) -> str:
notifications = self.app.notification_log.select(
start=start, limit=limit, topics=topics
)
return json.dumps([
{
"id": notification.id,
"originator_id": notification.originator_id.hex,
"originator_version": notification.originator_version,
"topic": notification.topic,
"state": b64encode(notification.state).decode("utf8"),
}
for notification in notifications
])
return json.dumps(
[
{
"id": notification.id,
"originator_id": notification.originator_id.hex,
"originator_version": notification.originator_version,
"topic": notification.topic,
"state": b64encode(notification.state).decode("utf8"),
}
for notification in notifications
]
)


class NotificationLogJSONClient(NotificationLog):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,12 @@ def __init__(self, interface: BankAccountsInterface):
self.log = NotificationLogJSONClient(interface)

def open_account(self, full_name, email_address) -> UUID:
body = json.dumps({
"full_name": full_name,
"email_address": email_address,
})
body = json.dumps(
{
"full_name": full_name,
"email_address": email_address,
}
)
body = self.interface.open_account(body)
return UUID(json.loads(body)["account_id"])

Expand Down
12 changes: 8 additions & 4 deletions eventsourcing/tests/system_tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,14 @@ def test_ignores_recording_event_if_seen_subsequent(self):

def test_received_notifications_accumulate(self):
self.start_runner(
System([[
BankAccounts,
EmailProcess,
]])
System(
[
[
BankAccounts,
EmailProcess,
]
]
)
)

accounts = self.runner.get(BankAccounts)
Expand Down
Loading

0 comments on commit 4aef44e

Please sign in to comment.