eventsourcing 9.2.22__py3-none-any.whl → 9.3.0a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of eventsourcing might be problematic. Click here for more details.

Files changed (144) hide show
  1. eventsourcing/__init__.py +1 -1
  2. eventsourcing/application.py +106 -135
  3. eventsourcing/cipher.py +15 -12
  4. eventsourcing/dispatch.py +31 -91
  5. eventsourcing/domain.py +138 -143
  6. eventsourcing/examples/__init__.py +0 -0
  7. eventsourcing/examples/aggregate1/__init__.py +0 -0
  8. eventsourcing/examples/aggregate1/application.py +27 -0
  9. eventsourcing/examples/aggregate1/domainmodel.py +16 -0
  10. eventsourcing/examples/aggregate1/test_application.py +37 -0
  11. eventsourcing/examples/aggregate2/__init__.py +0 -0
  12. eventsourcing/examples/aggregate2/application.py +27 -0
  13. eventsourcing/examples/aggregate2/domainmodel.py +22 -0
  14. eventsourcing/examples/aggregate2/test_application.py +37 -0
  15. eventsourcing/examples/aggregate3/__init__.py +0 -0
  16. eventsourcing/examples/aggregate3/application.py +27 -0
  17. eventsourcing/examples/aggregate3/domainmodel.py +38 -0
  18. eventsourcing/examples/aggregate3/test_application.py +37 -0
  19. eventsourcing/examples/aggregate4/__init__.py +0 -0
  20. eventsourcing/examples/aggregate4/application.py +27 -0
  21. eventsourcing/examples/aggregate4/domainmodel.py +128 -0
  22. eventsourcing/examples/aggregate4/test_application.py +38 -0
  23. eventsourcing/examples/aggregate5/__init__.py +0 -0
  24. eventsourcing/examples/aggregate5/application.py +27 -0
  25. eventsourcing/examples/aggregate5/domainmodel.py +131 -0
  26. eventsourcing/examples/aggregate5/test_application.py +38 -0
  27. eventsourcing/examples/aggregate6/__init__.py +0 -0
  28. eventsourcing/examples/aggregate6/application.py +30 -0
  29. eventsourcing/examples/aggregate6/domainmodel.py +123 -0
  30. eventsourcing/examples/aggregate6/test_application.py +38 -0
  31. eventsourcing/examples/aggregate6a/__init__.py +0 -0
  32. eventsourcing/examples/aggregate6a/application.py +40 -0
  33. eventsourcing/examples/aggregate6a/domainmodel.py +149 -0
  34. eventsourcing/examples/aggregate6a/test_application.py +45 -0
  35. eventsourcing/examples/aggregate7/__init__.py +0 -0
  36. eventsourcing/examples/aggregate7/application.py +48 -0
  37. eventsourcing/examples/aggregate7/domainmodel.py +144 -0
  38. eventsourcing/examples/aggregate7/persistence.py +57 -0
  39. eventsourcing/examples/aggregate7/test_application.py +38 -0
  40. eventsourcing/examples/aggregate7/test_compression_and_encryption.py +45 -0
  41. eventsourcing/examples/aggregate7/test_snapshotting_intervals.py +67 -0
  42. eventsourcing/examples/aggregate7a/__init__.py +0 -0
  43. eventsourcing/examples/aggregate7a/application.py +56 -0
  44. eventsourcing/examples/aggregate7a/domainmodel.py +170 -0
  45. eventsourcing/examples/aggregate7a/test_application.py +46 -0
  46. eventsourcing/examples/aggregate7a/test_compression_and_encryption.py +45 -0
  47. eventsourcing/examples/aggregate8/__init__.py +0 -0
  48. eventsourcing/examples/aggregate8/application.py +47 -0
  49. eventsourcing/examples/aggregate8/domainmodel.py +65 -0
  50. eventsourcing/examples/aggregate8/persistence.py +57 -0
  51. eventsourcing/examples/aggregate8/test_application.py +37 -0
  52. eventsourcing/examples/aggregate8/test_compression_and_encryption.py +44 -0
  53. eventsourcing/examples/aggregate8/test_snapshotting_intervals.py +38 -0
  54. eventsourcing/examples/bankaccounts/__init__.py +0 -0
  55. eventsourcing/examples/bankaccounts/application.py +70 -0
  56. eventsourcing/examples/bankaccounts/domainmodel.py +56 -0
  57. eventsourcing/examples/bankaccounts/test.py +173 -0
  58. eventsourcing/examples/cargoshipping/__init__.py +0 -0
  59. eventsourcing/examples/cargoshipping/application.py +126 -0
  60. eventsourcing/examples/cargoshipping/domainmodel.py +330 -0
  61. eventsourcing/examples/cargoshipping/interface.py +143 -0
  62. eventsourcing/examples/cargoshipping/test.py +231 -0
  63. eventsourcing/examples/contentmanagement/__init__.py +0 -0
  64. eventsourcing/examples/contentmanagement/application.py +118 -0
  65. eventsourcing/examples/contentmanagement/domainmodel.py +69 -0
  66. eventsourcing/examples/contentmanagement/test.py +180 -0
  67. eventsourcing/examples/contentmanagement/utils.py +26 -0
  68. eventsourcing/examples/contentmanagementsystem/__init__.py +0 -0
  69. eventsourcing/examples/contentmanagementsystem/application.py +54 -0
  70. eventsourcing/examples/contentmanagementsystem/postgres.py +17 -0
  71. eventsourcing/examples/contentmanagementsystem/sqlite.py +17 -0
  72. eventsourcing/examples/contentmanagementsystem/system.py +14 -0
  73. eventsourcing/examples/contentmanagementsystem/test_system.py +174 -0
  74. eventsourcing/examples/searchablecontent/__init__.py +0 -0
  75. eventsourcing/examples/searchablecontent/application.py +45 -0
  76. eventsourcing/examples/searchablecontent/persistence.py +23 -0
  77. eventsourcing/examples/searchablecontent/postgres.py +118 -0
  78. eventsourcing/examples/searchablecontent/sqlite.py +136 -0
  79. eventsourcing/examples/searchablecontent/test_application.py +111 -0
  80. eventsourcing/examples/searchablecontent/test_recorder.py +69 -0
  81. eventsourcing/examples/searchabletimestamps/__init__.py +0 -0
  82. eventsourcing/examples/searchabletimestamps/application.py +32 -0
  83. eventsourcing/examples/searchabletimestamps/persistence.py +20 -0
  84. eventsourcing/examples/searchabletimestamps/postgres.py +110 -0
  85. eventsourcing/examples/searchabletimestamps/sqlite.py +99 -0
  86. eventsourcing/examples/searchabletimestamps/test_searchabletimestamps.py +91 -0
  87. eventsourcing/examples/test_invoice.py +176 -0
  88. eventsourcing/examples/test_parking_lot.py +206 -0
  89. eventsourcing/interface.py +2 -2
  90. eventsourcing/persistence.py +85 -81
  91. eventsourcing/popo.py +30 -31
  92. eventsourcing/postgres.py +361 -578
  93. eventsourcing/sqlite.py +91 -99
  94. eventsourcing/system.py +42 -57
  95. eventsourcing/tests/application.py +20 -32
  96. eventsourcing/tests/application_tests/__init__.py +0 -0
  97. eventsourcing/tests/application_tests/test_application_with_automatic_snapshotting.py +55 -0
  98. eventsourcing/tests/application_tests/test_application_with_popo.py +22 -0
  99. eventsourcing/tests/application_tests/test_application_with_postgres.py +75 -0
  100. eventsourcing/tests/application_tests/test_application_with_sqlite.py +72 -0
  101. eventsourcing/tests/application_tests/test_cache.py +134 -0
  102. eventsourcing/tests/application_tests/test_event_sourced_log.py +162 -0
  103. eventsourcing/tests/application_tests/test_notificationlog.py +232 -0
  104. eventsourcing/tests/application_tests/test_notificationlogreader.py +126 -0
  105. eventsourcing/tests/application_tests/test_processapplication.py +110 -0
  106. eventsourcing/tests/application_tests/test_processingpolicy.py +109 -0
  107. eventsourcing/tests/application_tests/test_repository.py +504 -0
  108. eventsourcing/tests/application_tests/test_snapshotting.py +68 -0
  109. eventsourcing/tests/application_tests/test_upcasting.py +459 -0
  110. eventsourcing/tests/docs_tests/__init__.py +0 -0
  111. eventsourcing/tests/docs_tests/test_docs.py +293 -0
  112. eventsourcing/tests/domain.py +1 -1
  113. eventsourcing/tests/domain_tests/__init__.py +0 -0
  114. eventsourcing/tests/domain_tests/test_aggregate.py +1159 -0
  115. eventsourcing/tests/domain_tests/test_aggregate_decorators.py +1604 -0
  116. eventsourcing/tests/domain_tests/test_domainevent.py +80 -0
  117. eventsourcing/tests/interface_tests/__init__.py +0 -0
  118. eventsourcing/tests/interface_tests/test_remotenotificationlog.py +258 -0
  119. eventsourcing/tests/persistence.py +49 -50
  120. eventsourcing/tests/persistence_tests/__init__.py +0 -0
  121. eventsourcing/tests/persistence_tests/test_aes.py +93 -0
  122. eventsourcing/tests/persistence_tests/test_connection_pool.py +722 -0
  123. eventsourcing/tests/persistence_tests/test_eventstore.py +72 -0
  124. eventsourcing/tests/persistence_tests/test_infrastructure_factory.py +21 -0
  125. eventsourcing/tests/persistence_tests/test_mapper.py +113 -0
  126. eventsourcing/tests/persistence_tests/test_noninterleaving_notification_ids.py +69 -0
  127. eventsourcing/tests/persistence_tests/test_popo.py +124 -0
  128. eventsourcing/tests/persistence_tests/test_postgres.py +1121 -0
  129. eventsourcing/tests/persistence_tests/test_sqlite.py +348 -0
  130. eventsourcing/tests/persistence_tests/test_transcoder.py +44 -0
  131. eventsourcing/tests/postgres_utils.py +7 -7
  132. eventsourcing/tests/system_tests/__init__.py +0 -0
  133. eventsourcing/tests/system_tests/test_runner.py +935 -0
  134. eventsourcing/tests/system_tests/test_system.py +287 -0
  135. eventsourcing/tests/utils_tests/__init__.py +0 -0
  136. eventsourcing/tests/utils_tests/test_utils.py +226 -0
  137. eventsourcing/utils.py +47 -50
  138. {eventsourcing-9.2.22.dist-info → eventsourcing-9.3.0a1.dist-info}/METADATA +28 -80
  139. eventsourcing-9.3.0a1.dist-info/RECORD +144 -0
  140. {eventsourcing-9.2.22.dist-info → eventsourcing-9.3.0a1.dist-info}/WHEEL +1 -2
  141. eventsourcing-9.2.22.dist-info/AUTHORS +0 -10
  142. eventsourcing-9.2.22.dist-info/RECORD +0 -25
  143. eventsourcing-9.2.22.dist-info/top_level.txt +0 -1
  144. {eventsourcing-9.2.22.dist-info → eventsourcing-9.3.0a1.dist-info}/LICENSE +0 -0
@@ -0,0 +1,110 @@
1
+ from unittest.case import TestCase
2
+
3
+ from eventsourcing.application import RecordingEvent
4
+ from eventsourcing.dispatch import singledispatchmethod
5
+ from eventsourcing.domain import AggregateEvent
6
+ from eventsourcing.persistence import Transcoder
7
+ from eventsourcing.system import (
8
+ Follower,
9
+ Leader,
10
+ ProcessApplication,
11
+ ProcessingEvent,
12
+ RecordingEventReceiver,
13
+ )
14
+ from eventsourcing.tests.application import BankAccounts, EmailAddressAsStr
15
+ from eventsourcing.tests.application_tests.test_processingpolicy import (
16
+ EmailNotification,
17
+ )
18
+ from eventsourcing.tests.domain import BankAccount
19
+
20
+
21
+ class TestProcessApplication(TestCase):
22
+ def test_pull_and_process(self):
23
+ leader_cls = type(
24
+ BankAccounts.__name__,
25
+ (BankAccounts, Leader),
26
+ {},
27
+ )
28
+
29
+ accounts = leader_cls()
30
+ email_process = EmailProcess()
31
+ email_process.follow(
32
+ accounts.name,
33
+ accounts.notification_log,
34
+ )
35
+
36
+ section = email_process.notification_log["1,5"]
37
+ self.assertEqual(len(section.items), 0)
38
+
39
+ accounts.open_account("Alice", "alice@example.com")
40
+
41
+ email_process.pull_and_process(BankAccounts.name)
42
+
43
+ section = email_process.notification_log["1,5"]
44
+ self.assertEqual(len(section.items), 1)
45
+
46
+ # Check we have processed the first event.
47
+ self.assertEqual(email_process.recorder.max_tracking_id(BankAccounts.name), 1)
48
+
49
+ # Check reprocessing first event changes nothing (swallows IntegrityError).
50
+ email_process.pull_and_process(BankAccounts.name, start=1)
51
+ self.assertEqual(email_process.recorder.max_tracking_id(BankAccounts.name), 1)
52
+
53
+ # Check we can continue from the next position.
54
+ email_process.pull_and_process(BankAccounts.name, start=2)
55
+
56
+ # Check we haven't actually processed anything further.
57
+ self.assertEqual(email_process.recorder.max_tracking_id(BankAccounts.name), 1)
58
+ section = email_process.notification_log["1,5"]
59
+ self.assertEqual(len(section.items), 1)
60
+
61
+ # Subscribe for notifications.
62
+ accounts.lead(PromptForwarder(email_process))
63
+
64
+ # Create another notification.
65
+ accounts.open_account("Bob", "bob@example.com")
66
+
67
+ # Check we have processed the next notification.
68
+ section = email_process.notification_log["1,5"]
69
+ self.assertEqual(len(section.items), 2)
70
+
71
+ # Check we have actually processed the second event.
72
+ self.assertEqual(email_process.recorder.max_tracking_id(BankAccounts.name), 2)
73
+
74
+
75
+ class EmailProcess(ProcessApplication):
76
+ def register_transcodings(self, transcoder: Transcoder) -> None:
77
+ super().register_transcodings(transcoder)
78
+ transcoder.register(EmailAddressAsStr())
79
+
80
+ @singledispatchmethod
81
+ def policy(
82
+ self,
83
+ domain_event: AggregateEvent,
84
+ processing_event: ProcessingEvent,
85
+ ):
86
+ """Default policy"""
87
+
88
+ @policy.register
89
+ def _(
90
+ self,
91
+ domain_event: BankAccount.Opened,
92
+ processing_event: ProcessingEvent,
93
+ ):
94
+ notification = EmailNotification.create(
95
+ to=domain_event.email_address,
96
+ subject="Your New Account",
97
+ message=f"Dear {domain_event.full_name}, ...",
98
+ )
99
+ processing_event.collect_events(notification)
100
+
101
+
102
+ class PromptForwarder(RecordingEventReceiver):
103
+ def __init__(self, application: Follower):
104
+ self.application = application
105
+
106
+ def receive_recording_event(self, recording_event: RecordingEvent) -> None:
107
+ self.application.pull_and_process(
108
+ leader_name=recording_event.application_name,
109
+ start=recording_event.recordings[0].notification.id,
110
+ )
@@ -0,0 +1,109 @@
1
+ import warnings
2
+ from unittest.case import TestCase
3
+ from uuid import uuid4
4
+
5
+ from eventsourcing.domain import Aggregate
6
+ from eventsourcing.persistence import Tracking
7
+ from eventsourcing.system import ProcessingEvent
8
+ from eventsourcing.tests.domain import BankAccount
9
+
10
+
11
+ def policy(domain_event, processing_event: ProcessingEvent):
12
+ if isinstance(domain_event, BankAccount.Opened):
13
+ notification = EmailNotification.create(
14
+ to=domain_event.email_address,
15
+ subject="Your New Account",
16
+ message=f"Dear {domain_event.full_name}",
17
+ )
18
+ processing_event.collect_events(notification)
19
+
20
+
21
+ def policy_legacy_save(domain_event, processing_event: ProcessingEvent):
22
+ if isinstance(domain_event, BankAccount.Opened):
23
+ notification = EmailNotification.create(
24
+ to=domain_event.email_address,
25
+ subject="Your New Account",
26
+ message=f"Dear {domain_event.full_name}",
27
+ )
28
+ processing_event.save(notification)
29
+
30
+
31
+ class TestProcessingPolicy(TestCase):
32
+ def test_policy(self):
33
+ # Open an account.
34
+ account = BankAccount.open(
35
+ full_name="Alice",
36
+ email_address="alice@example.com",
37
+ )
38
+ events = account.collect_events()
39
+ created_event = events[0]
40
+
41
+ processing_event = ProcessingEvent(
42
+ tracking=Tracking(
43
+ application_name="upstream_app",
44
+ notification_id=5,
45
+ )
46
+ )
47
+
48
+ policy(created_event, processing_event)
49
+
50
+ self.assertEqual(len(processing_event.events), 1)
51
+ self.assertIsInstance(
52
+ processing_event.events[0],
53
+ EmailNotification.Created,
54
+ )
55
+
56
+ def test_legacy_save(self):
57
+ # Open an account.
58
+ account = BankAccount.open(
59
+ full_name="Alice",
60
+ email_address="alice@example.com",
61
+ )
62
+ events = account.collect_events()
63
+ created_event = events[0]
64
+
65
+ processing_event = ProcessingEvent(
66
+ tracking=Tracking(
67
+ application_name="upstream_app",
68
+ notification_id=5,
69
+ )
70
+ )
71
+
72
+ # Verify deprecation warning.
73
+ with warnings.catch_warnings(record=True) as w:
74
+ policy_legacy_save(created_event, processing_event)
75
+
76
+ self.assertEqual(1, len(w))
77
+ self.assertIs(w[-1].category, DeprecationWarning)
78
+ self.assertEqual(
79
+ "'save()' is deprecated, use 'collect_events()' instead",
80
+ w[-1].message.args[0],
81
+ )
82
+
83
+ self.assertEqual(len(processing_event.events), 1)
84
+ self.assertIsInstance(
85
+ processing_event.events[0],
86
+ EmailNotification.Created,
87
+ )
88
+
89
+
90
+ class EmailNotification(Aggregate):
91
+ def __init__(self, to, subject, message):
92
+ self.to = to
93
+ self.subject = subject
94
+ self.message = message
95
+
96
+ @classmethod
97
+ def create(cls, to, subject, message):
98
+ return cls._create(
99
+ cls.Created,
100
+ id=uuid4(),
101
+ to=to,
102
+ subject=subject,
103
+ message=message,
104
+ )
105
+
106
+ class Created(Aggregate.Created):
107
+ to: str
108
+ subject: str
109
+ message: str