def db(app, account_id, client_id): event_store_db.create_all() operation_id = UniqueID() account_created_event = AccountCreated(operation_id=operation_id.value, client_id=client_id.value, account_id=account_id.value, account_name='test') account_credit_event = AccountCredited(operation_id=operation_id.value, dollars=23, cents=0, account_id=account_id.value) aggregate = AggregateModel(uuid=account_id.value, version=AGGREGATE_VERSION) event1 = EventModel(uuid=str(UniqueID()), aggregate_uuid=account_id.value, name=account_created_event.__class__.__name__, data=asdict(account_created_event)) event2 = EventModel(uuid=str(UniqueID()), aggregate_uuid=account_id.value, name=account_credit_event.__class__.__name__, data=asdict(account_credit_event)) # Add aggregate and event to the db. event_store_db.session.add(aggregate) event_store_db.session.flush() event_store_db.session.add(event1) event_store_db.session.commit() event_store_db.session.add(event2) event_store_db.session.commit() yield event_store_db # this is the object that the tests use event_store_db.drop_all()
def wrapped(target_id: UniqueID): if account_id == target_id: return EventStream([ AccountCreated(operation_id=str(UniqueID()), client_id=str(UniqueID()), account_id=str(account_id), account_name='test'), AccountCredited(dollars=20, cents=0, account_id=account_id.value, operation_id=str(UniqueID)) ], version=2) return None
def test_save_events_adds_related_events_to_new_aggregate( session: Session, postgres_event_store): account_id = UniqueID() account_created_event = AccountCreated(operation_id=str(UniqueID()), client_id=str(UniqueID()), account_id=str(account_id), account_name='test') credit_event = AccountCredited(dollars=22, cents=0, account_id=str(account_id), operation_id=str(UniqueID())) postgres_event_store.save_events( aggregate_id=account_id, events=[account_created_event, credit_event]) aggregate = session.query(AggregateModel).filter( AggregateModel.uuid == account_id.value).one() assert len(aggregate.events) == 2
def db(app, account_id: UniqueID, client_id: UniqueID, account_name: str): with app.app_context(): event_store_db.create_all() client_create_operation_id = UniqueID() client_created_event = ClientCreated( client_id=str(client_id), ssn=SocialSecurityNumber(123456789).value, operation_id=str(client_create_operation_id), first_name=FirstName('test').value, last_name=LastName('test').value, birthdate=Birthdate('27/02/1998').value) account_added_to_client = AccountAddedToClient( client_id=str(client_id), account_id=str(account_id), operation_id=str(client_create_operation_id), account_name=account_name) account_create_operation_id = UniqueID() account_created_event = AccountCreated( operation_id=account_create_operation_id.value, client_id=str(client_id), account_id=str(account_id), account_name=account_name) account_credit_event = AccountCredited( operation_id=account_create_operation_id.value, dollars=23, cents=0, account_id=str(account_id)) client_aggregate = AggregateModel(uuid=str(client_id), version=AGGREGATE_VERSION) client_created_db_event = EventModel( uuid=str(UniqueID()), aggregate_uuid=str(client_id), name=client_created_event.__class__.__name__, data=asdict(client_created_event)) account_added_to_client_db_event = EventModel( uuid=str(UniqueID()), aggregate_uuid=str(client_id), name=account_added_to_client.__class__.__name__, data=asdict(account_added_to_client)) account_aggregate = AggregateModel(uuid=str(account_id), version=AGGREGATE_VERSION) account_created_db_event = EventModel( uuid=str(UniqueID()), aggregate_uuid=account_id.value, name=account_created_event.__class__.__name__, data=asdict(account_created_event)) account_credited_db_event = EventModel( uuid=str(UniqueID()), aggregate_uuid=account_id.value, name=account_credit_event.__class__.__name__, data=asdict(account_credit_event)) event_store_db.session.add(client_aggregate) event_store_db.session.add(account_aggregate) event_store_db.session.flush() event_store_db.session.add(client_created_db_event) event_store_db.session.add(account_added_to_client_db_event) event_store_db.session.add(account_created_db_event) event_store_db.session.add(account_credited_db_event) event_store_db.session.commit() yield event_store_db # this is the object that the tests use event_store_db.drop_all()
def get_account_credited_event(account_id, amount: Amount): return AccountCredited(dollars=amount.dollars, cents=amount.cents, account_id=account_id.value, operation_id=str(UniqueID()))
def new_random_account_credit_event(new_random_account): amount = Amount(random.randint(0, 9999), random.randint(0, 300)) return AccountCredited(dollars=amount.dollars, cents=amount.cents, account_id=new_random_account.account_id.value, operation_id=str(UniqueID()))
def credit_event(account_id): return AccountCredited(dollars=random.randint(50, 100), cents=random.randint(0, 100), account_id=account_id.value, operation_id=str(UniqueID()))