Example #1
0
 def tearDown(self):
     assert_event_handlers_empty()
     clear_event_handlers()
     try:
         del os.environ["DB_URI"]
     except KeyError:
         pass
    def tearDown(self):
        assert_event_handlers_empty()

        try:
            del (os.environ['DB_URI'])
        except KeyError:
            pass
 def tearDown(self):
     self.datastore.drop_tables()
     self.datastore.drop_connection()
     if self.policy is not None:
         self.policy.close()
     super(TestEventPlayer, self).tearDown()
     assert_event_handlers_empty()
Example #4
0
    def setUp(self):
        assert_event_handlers_empty()
        contract_valuation_repo = MagicMock(spec=ContractValuationRepository)
        contract_valuation_repo.__getitem__.return_value = Mock(
            spec=ContractValuation)
        market_simulation_repo = MagicMock(spec=MarketSimulationRepository)
        market_simulation_repo.__getitem__.return_value = Mock(
            spec=MarketSimulation)
        call_leafs_repo = MagicMock(spec=CallLeafsRepository)
        call_leafs_repo.__getitem__.return_value = Mock(spec=CallLeafs)
        call_dependents_repo = MagicMock(spec=CallDependentsRepository)
        perturbation_dependencies_repo = MagicMock(
            spec=PerturbationDependenciesRepo)
        simulated_price_requirements_repo = MagicMock(
            spec=SimulatedPriceRequirementsRepo)

        self.evaluation_subscriber = EvaluationSubscriber(
            contract_valuation_repo=contract_valuation_repo,
            call_link_repo=MagicMock(spec=CallLinkRepository),
            call_dependencies_repo=MagicMock(spec=CallDependenciesRepository),
            call_requirement_repo=MagicMock(spec=CallRequirementRepository),
            call_result_repo=MagicMock(spec=CallResultRepository),
            simulated_price_repo=MagicMock(spec=SimulatedPriceRepository),
            market_simulation_repo=market_simulation_repo,
            call_leafs_repo=call_leafs_repo,
            call_evaluation_queue=None,
            call_dependents_repo=call_dependents_repo,
            perturbation_dependencies_repo=perturbation_dependencies_repo,
            simulated_price_requirements_repo=simulated_price_requirements_repo
        )
 def setUp(self):
     assert_event_handlers_empty()
     # Setup the repo, and a persistence subscriber.
     stored_event_repo = PythonObjectsStoredEventRepository()
     event_store = EventStore(stored_event_repo=stored_event_repo)
     self.repo = CollectionRepo(event_store=event_store)
     self.ps = PersistenceSubscriber(event_store=event_store)
 def setUp(self):
     assert_event_handlers_empty()
     # Setup the repo, and a persistence subscriber.
     stored_event_repo = PythonObjectsStoredEventRepository()
     event_store = EventStore(stored_event_repo=stored_event_repo)
     self.repo = CollectionRepo(event_store=event_store)
     self.ps = PersistenceSubscriber(event_store=event_store)
Example #7
0
 def setUp(self):
     assert_event_handlers_empty()
     market_simulation_repo = MagicMock(spec=MarketSimulationRepository)
     market_calibration_repo = MagicMock(spec=MarketCalibrationRepository)
     simulated_price_repo = MagicMock(spec=SimulatedPriceRepository)
     self.simulation_subscriber = SimulationSubscriber(
         market_calibration_repo, market_simulation_repo,
         simulated_price_repo)
Example #8
0
    def setUp(self):
        if not self.skip_assert_event_handers_empty:
            assert_event_handlers_empty()
        # super(ContractValuationTestCase, self).setUp()

        scipy.random.seed(1354802735)

        self.setup_application()
Example #9
0
 def tearDown(self):
     self.app.terminate()
     sleep(1)
     self.app.kill()
     sleep(1)
     self.app.wait()
     super(TestFlaskApp, self).tearDown()
     assert_event_handlers_empty()
 def tearDown(self):
     self.app.terminate()
     sleep(1)
     self.app.kill()
     sleep(1)
     self.app.wait()
     super(TestFlaskApp, self).tearDown()
     assert_event_handlers_empty()
Example #11
0
    def tearDown(self):
        # Close the persistence subscriber.
        self.persistence_subscriber.close()

        super(LogTestCase, self).tearDown()

        # Check we finished clean, event handler-wise.
        assert_event_handlers_empty()
Example #12
0
    def tearDown(self):
        # Close the persistence subscriber.
        self.persistence_subscriber.close()

        super(LogTestCase, self).tearDown()

        # Check we finished clean, event handler-wise.
        assert_event_handlers_empty()
Example #13
0
 def tearDown(self):
     try:
         del (os.environ['DB_URI'])
     except KeyError:
         pass
     try:
         assert_event_handlers_empty()
     finally:
         clear_event_handlers()
 def tearDown(self):
     self.datastore.drop_tables()
     self.datastore.drop_connection()
     if self.entity_persistence_policy is not None:
         self.entity_persistence_policy.close()
     if self.snapshot_persistence_policy is not None:
         self.snapshot_persistence_policy.close()
     super(TestEventPlayer, self).tearDown()
     assert_event_handlers_empty()
 def setUp(self):
     assert_event_handlers_empty()
     market_simulation_repo = MagicMock(spec=MarketSimulationRepository)
     market_calibration_repo = MagicMock(spec=MarketCalibrationRepository)
     simulated_price_repo = MagicMock(spec=SimulatedPriceRepository)
     self.simulation_subscriber = SimulationSubscriber(
         market_calibration_repo,
         market_simulation_repo,
         simulated_price_repo
     )
 def setUp(self):
     assert_event_handlers_empty()
     self.es = EventStore(PythonObjectsStoredEventRepository())
     self.ps = PersistenceSubscriber(self.es)
     # self.call_result_repo = CallResultRepo(self.es)
     self.call_result_repo = {}
     self.call_dependencies_repo = CallDependenciesRepo(self.es)
     self.call_dependents_repo = CallDependentsRepo(self.es)
     self.call_requirement_repo = CallRequirementRepo(self.es)
     self.policy = CallResultPolicy(call_result_repo=self.call_result_repo)
Example #17
0
    def tearDown(self):
        # Unset environment.
        try:
            del os.environ["DB_URI"]
        except KeyError:
            pass

        try:
            assert_event_handlers_empty()
        finally:
            clear_event_handlers()
Example #18
0
    def setUp(self):
        super(LogTestCase, self).setUp()

        # Check we're starting clean, event handler-wise.
        assert_event_handlers_empty()

        # Setup the persistence subscriber.
        self.event_store = EventStore(self.stored_event_repo)
        self.persistence_subscriber = PersistenceSubscriber(event_store=self.event_store)

        self.log_repo = LogRepo(self.event_store)
Example #19
0
    def test_subscribe_to_decorator(self):
        entity_id1 = uuid4()
        event1 = Example.Created(
            originator_id=entity_id1,
            originator_topic=get_topic(Example),
            a=1, b=2
        )
        event2 = Example.Discarded(
            originator_id=entity_id1,
            originator_version=1,
        )
        handler = mock.Mock()

        # Check we can assert there are no event handlers subscribed.
        assert_event_handlers_empty()

        @subscribe_to(Example.Created)
        def test_handler(e):
            """Doc string"""
            handler(e)

        # Check the decorator doesn't mess with the function doc string.
        self.assertEqual('Doc string', test_handler.__doc__)

        # Check can fail to assert event handlers empty.
        self.assertRaises(EventHandlersNotEmptyError, assert_event_handlers_empty)

        # Check event is received when published individually.
        publish(event1)
        handler.assert_called_once_with(event1)

        # Check event of wrong type is not received.
        handler.reset_mock()
        publish(event2)
        self.assertFalse(handler.call_count)

        # Check a list of events can be filtered.
        handler.reset_mock()
        publish([event1, event2])
        handler.assert_called_once_with(event1)

        handler.reset_mock()
        publish([event1, event1])
        self.assertEqual(2, handler.call_count)

        handler.reset_mock()
        publish([event2, event2])
        self.assertEqual(0, handler.call_count)

        _event_handlers.clear()
    def tearDown(self):
        # Unset environment.
        try:
            del os.environ["DB_URI"]
        except KeyError:
            pass

        try:
            # Shutdown base actor system.
            shutdown_actor_system()
        finally:
            # Clear event handlers.
            try:
                assert_event_handlers_empty()
            finally:
                clear_event_handlers()
    def test_subscribe_to_decorator(self):
        entity_id1 = uuid4()
        event = Example.Created(originator_id=entity_id1, a=1, b=2)
        handler = mock.Mock()

        # Check we can assert there are no event handlers subscribed.
        assert_event_handlers_empty()

        @subscribe_to(Example.Created)
        def test_handler(e):
            handler(e)

        # Check we can assert there are event handlers subscribed.
        self.assertRaises(EventHandlersNotEmptyError, assert_event_handlers_empty)

        # Check what happens when an event is published.
        publish(event)
        handler.assert_called_once_with(event)
Example #22
0
    def test_subscribe_to_decorator(self):
        entity_id1 = uuid4()
        event = Example.Created(originator_id=entity_id1, a=1, b=2)
        handler = mock.Mock()

        # Check we can assert there are no event handlers subscribed.
        assert_event_handlers_empty()

        @subscribe_to(Example.Created)
        def test_handler(e):
            handler(e)

        # Check we can assert there are event handlers subscribed.
        self.assertRaises(EventHandlersNotEmptyError,
                          assert_event_handlers_empty)

        # Check what happens when an event is published.
        publish(event)
        handler.assert_called_once_with(event)
    def setUp(self):
        assert_event_handlers_empty()
        super(TestEventPlayer, self).setUp()

        self.datastore.setup_connection()
        self.datastore.setup_tables()

        # Setup an event store for version entity events.
        self.version_entity_event_store = EventStore(
            active_record_strategy=SQLAlchemyActiveRecordStrategy(
                datastore=self.datastore,
                active_record_class=SqlIntegerSequencedItem,
                sequenced_item_class=SequencedItem,
            ),
            sequenced_item_mapper=SequencedItemMapper(
                sequenced_item_class=SequencedItem,
                event_sequence_id_attr='entity_id',
                event_position_attr='entity_version',
            ),
        )

        # Setup an event store for timestamp entity events.
        self.timestamp_entity_event_store = EventStore(
            active_record_strategy=SQLAlchemyActiveRecordStrategy(
                datastore=self.datastore,
                active_record_class=SqlTimestampSequencedItem,
                sequenced_item_class=SequencedItem,
            ),
            sequenced_item_mapper=SequencedItemMapper(
                sequenced_item_class=SequencedItem,
                event_sequence_id_attr='entity_id',
                event_position_attr='timestamp',
            ),
        )

        self.policy = None
    def setUp(self):
        assert_event_handlers_empty()
        super(TestEventPlayer, self).setUp()

        self.datastore.setup_connection()
        self.datastore.setup_tables()

        # Setup an event store for versioned entity events.
        self.entity_event_store = EventStore(
            active_record_strategy=SQLAlchemyActiveRecordStrategy(
                session=self.datastore.session,
                active_record_class=IntegerSequencedItemRecord,
                sequenced_item_class=SequencedItem,
            ),
            sequenced_item_mapper=SequencedItemMapper(
                sequenced_item_class=SequencedItem,
                sequence_id_attr_name='originator_id',
                position_attr_name='originator_version',
            ),
        )

        # Setup an event store for snapshots.
        self.snapshot_store = EventStore(
            active_record_strategy=SQLAlchemyActiveRecordStrategy(
                session=self.datastore.session,
                active_record_class=SnapshotRecord,
                sequenced_item_class=SequencedItem,
            ),
            sequenced_item_mapper=SequencedItemMapper(
                sequenced_item_class=SequencedItem,
                sequence_id_attr_name='originator_id',
                position_attr_name='originator_version',
            ),
        )
        self.entity_persistence_policy = None
        self.snapshot_persistence_policy = None
    def setUp(self):
        assert_event_handlers_empty()
        super(TestEventPlayer, self).setUp()

        self.datastore.setup_connection()
        self.datastore.setup_tables()

        # Setup an event store for versioned entity events.
        self.entity_event_store = EventStore(
            active_record_strategy=SQLAlchemyActiveRecordStrategy(
                session=self.datastore.session,
                active_record_class=IntegerSequencedItemRecord,
                sequenced_item_class=SequencedItem,
            ),
            sequenced_item_mapper=SequencedItemMapper(
                sequenced_item_class=SequencedItem,
                sequence_id_attr_name='originator_id',
                position_attr_name='originator_version',
            ),
        )

        # Setup an event store for snapshots.
        self.snapshot_store = EventStore(
            active_record_strategy=SQLAlchemyActiveRecordStrategy(
                session=self.datastore.session,
                active_record_class=SnapshotRecord,
                sequenced_item_class=SequencedItem,
            ),
            sequenced_item_mapper=SequencedItemMapper(
                sequenced_item_class=SequencedItem,
                sequence_id_attr_name='originator_id',
                position_attr_name='originator_version',
            ),
        )
        self.entity_persistence_policy = None
        self.snapshot_persistence_policy = None
Example #26
0
    def test_publish_subscribe_unsubscribe(self):
        # Check subscribing event handlers with predicates.
        # - when predicate is True, handler should be called
        event = mock.Mock()
        predicate = mock.Mock()
        handler = mock.Mock()

        # Check we can assert there are no event handlers subscribed.
        assert_event_handlers_empty()

        # When predicate is True, handler should be called ONCE.
        subscribe(handler=handler, predicate=predicate)

        # Check we can assert there are event handlers subscribed.
        self.assertRaises(EventHandlersNotEmptyError,
                          assert_event_handlers_empty)

        # Check what happens when an event is published.
        publish(event)
        predicate.assert_called_once_with(event)
        handler.assert_called_once_with(event)

        # When predicate is True, after unsubscribing, handler should NOT be called again.
        unsubscribe(handler=handler, predicate=predicate)
        publish(event)
        predicate.assert_called_once_with(event)
        handler.assert_called_once_with(event)

        # Check we can assert there are no event handlers subscribed.
        assert_event_handlers_empty()

        # When predicate is False, handler should NOT be called.
        predicate = lambda x: False
        handler = mock.Mock()
        subscribe(handler=handler, predicate=predicate)
        publish(event)
        self.assertEqual(0, handler.call_count)

        # Unsubscribe.
        unsubscribe(handler=handler, predicate=predicate)

        # Check we can assert there are no event handlers subscribed.
        assert_event_handlers_empty()
    def test_publish_subscribe_unsubscribe(self):
        # Check subscribing event handlers with predicates.
        # - when predicate is True, handler should be called
        event = mock.Mock()
        predicate = mock.Mock()
        handler = mock.Mock()

        # Check we can assert there are no event handlers subscribed.
        assert_event_handlers_empty()

        # When predicate is True, handler should be called ONCE.
        subscribe(handler=handler, predicate=predicate)

        # Check we can assert there are event handlers subscribed.
        self.assertRaises(EventHandlersNotEmptyError, assert_event_handlers_empty)

        # Check what happens when an event is published.
        publish(event)
        predicate.assert_called_once_with(event)
        handler.assert_called_once_with(event)

        # When predicate is True, after unsubscribing, handler should NOT be called again.
        unsubscribe(handler=handler, predicate=predicate)
        publish(event)
        predicate.assert_called_once_with(event)
        handler.assert_called_once_with(event)

        # Check we can assert there are no event handlers subscribed.
        assert_event_handlers_empty()

        # When predicate is False, handler should NOT be called.
        predicate = lambda x: False
        handler = mock.Mock()
        subscribe(handler=handler, predicate=predicate)
        publish(event)
        self.assertEqual(0, handler.call_count)

        # Unsubscribe.
        unsubscribe(handler=handler, predicate=predicate)

        # Check we can assert there are no event handlers subscribed.
        assert_event_handlers_empty()
Example #28
0
 def setUp(self):
     assert_event_handlers_empty()
     super(ApplicationTestCase, self).setUp()
     self.app = get_app()
     numpy.random.seed(1354802735)
Example #29
0
 def setUp(self):
     assert_event_handlers_empty()
     super(TestFlaskApp, self).setUp()
     self.app = self.start_app()
Example #30
0
 def tearDown(self):
     if self.app is not None:
         self.app.close()
     if not self.skip_assert_event_handers_empty:
         assert_event_handlers_empty()
 def tearDown(self):
     self.simulation_subscriber.close()
     assert_event_handlers_empty()
Example #32
0
 def tearDown(self):
     super(ApplicationTestCase, self).tearDown()
     self.app.close()
     assert_event_handlers_empty()
 def setUp(self):
     assert_event_handlers_empty()
     self.ps = None
Example #34
0
 def tearDown(self):
     self.evaluation_subscriber.close()
     assert_event_handlers_empty()
Example #35
0
 def tearDown(self):
     assert_event_handlers_empty()
Example #36
0
 def tearDown(self):
     try:
         assert_event_handlers_empty()
     except EventHandlersNotEmptyError:
         clear_event_handlers()
         raise
 def setUp(self):
     assert_event_handlers_empty()
     self.published_events = []
     self.subscription = (lambda x: True, lambda x: self.published_events.append(x))
     subscribe(*self.subscription)
Example #38
0
 def tearDown(self):
     assert_event_handlers_empty()
 def tearDown(self):
     self.persistence_subscriber.close()
     assert_event_handlers_empty()
 def tearDown(self):
     if self.ps is not None:
         self.ps.close()
     assert_event_handlers_empty()
 def tearDown(self) -> None:
     self.app.close()
     super(TestExampleAggregateRoot, self).tearDown()
     assert_event_handlers_empty()
 def setUp(self):
     assert_event_handlers_empty()
     super(TestFlaskApp, self).setUp()
     self.app = self.start_app()
    def test_subscribe_to_decorator(self):
        entity_id1 = uuid4()
        event1 = Example.Created(originator_id=entity_id1,
                                 originator_topic=get_topic(Example),
                                 a=1,
                                 b=2)
        event2 = Example.Discarded(originator_id=entity_id1,
                                   originator_version=1)
        handler1 = mock.Mock()
        handler2 = mock.Mock()
        handler3 = mock.Mock()

        # Check we can assert there are no event handlers subscribed.
        assert_event_handlers_empty()

        # Original style (one event class arg).
        @subscribe_to(Example.Created)
        def test_handler1(e):
            """Doc string"""
            handler1(e)

        # Naked style (not called).
        @subscribe_to
        def test_handler2(e):
            """Doc string"""
            handler2(e)

        # Multi-event style (many event class args).
        @subscribe_to((Example.Created, Example.Discarded))
        def test_handler3(e):
            """Doc string"""
            handler3(e)

        # Check the decorator doesn't mess with the function doc string.
        self.assertEqual("Doc string", test_handler1.__doc__)
        self.assertEqual("Doc string", test_handler2.__doc__)
        self.assertEqual("Doc string", test_handler3.__doc__)

        # Check can fail to assert event handlers empty.
        self.assertRaises(EventHandlersNotEmptyError,
                          assert_event_handlers_empty)

        # Check event is received when published individually.
        publish([event1])
        handler1.assert_called_once_with(event1)
        handler2.assert_called_once_with(event1)
        handler3.assert_called_once_with(event1)

        # Check event of wrong type is not received.
        handler1.reset_mock()
        handler2.reset_mock()
        handler3.reset_mock()
        publish([event2])
        self.assertFalse(handler1.call_count)
        handler2.assert_called_once_with(event2)
        handler3.assert_called_once_with(event2)

        # Check a list of events can be filtered.
        handler1.reset_mock()
        handler2.reset_mock()
        handler3.reset_mock()
        publish([event1, event2])
        handler1.assert_called_once_with(event1)
        self.assertEqual(handler2.call_count, 2)
        self.assertEqual(handler3.call_count, 2)

        handler1.reset_mock()
        handler2.reset_mock()
        handler3.reset_mock()
        publish([event1, event1])
        self.assertEqual(2, handler1.call_count)
        self.assertEqual(2, handler2.call_count)
        self.assertEqual(2, handler3.call_count)

        handler1.reset_mock()
        handler2.reset_mock()
        handler3.reset_mock()
        publish([event2, event2])
        self.assertEqual(0, handler1.call_count)
        self.assertEqual(2, handler2.call_count)
        self.assertEqual(2, handler3.call_count)

        clear_event_handlers()
 def setUp(self):
     assert_event_handlers_empty()
     self.ps = None
 def tearDown(self):
     unsubscribe(*self.subscription)
     assert_event_handlers_empty()
 def setUp(self) -> None:
     assert_event_handlers_empty()
     super(TestExampleAggregateRoot, self).setUp()
     self.app: ExampleDDDApplication = ExampleDDDApplication(self.datastore)
 def tearDown(self):
     if self.ps is not None:
         self.ps.close()
     assert_event_handlers_empty()
 def setUp(self) -> None:
     assert_event_handlers_empty()
 def tearDown(self):
     self.ps.close()
     assert_event_handlers_empty()