from eventsourcing.application.sqlalchemy import SimpleApplication
from eventsourcing.exceptions import ConcurrencyError
from eventsourcing.application.sqlalchemy import SimpleApplication
from eventsourcing.exceptions import ConcurrencyError
from world import World
from eventsourcing.utils.random import encode_random_bytes
import os

# Keep this safe.
cipher_key = encode_random_bytes(num_bytes=32)

# Optional cipher key (random bytes encoded with Base64).
os.environ['CIPHER_KEY'] = cipher_key

# SQLAlchemy-style database connection string.
os.environ['DB_URI'] = 'sqlite:///:memory:'

# Construct simple application (used here as a context manager).
with SimpleApplication(persist_event_type=World.Event) as app:

    # 1. Call library factor method as 'Geekshub' user.
    world = World.__create__(ruler='Geekshub')

    # 2. Check if the ruler is Geekshub
    assert world.ruler == 'Geekshub'

    # 3. Change the ruler
    world.ruler = 'Lucas'

    # 4. Add
Exemple #2
0
import os

# Keep this safe.
cipher_key = encode_random_bytes(num_bytes=32)

# Optional cipher key (random bytes encoded with Base64).
os.environ['CIPHER_KEY'] = cipher_key

# SQLAlchemy-style database connection string.
os.environ['DB_URI'] = 'sqlite:///:memory:'

# Construct simple application (used here as a context manager).
with SimpleApplication(persist_event_type=World.Event) as app:

    # Call library factory method.
    world = World.__create__(ruler='gods')

    # Execute commands.
    world.make_it_so('dinosaurs')
    world.make_it_so('trucks')

    version = world.__version__  # note version at this stage
    world.make_it_so('internet')

    # Assign to event-sourced attribute.
    world.ruler = 'money'

    # View current state of aggregate.
    assert world.ruler == 'money'
    assert world.history[2].what == 'internet'
    assert world.history[1].what == 'trucks'