Ejemplo n.º 1
0
 def tearDown(self):
     assert_event_handlers_empty()
     clear_event_handlers()
     try:
         del os.environ["DB_URI"]
     except KeyError:
         pass
Ejemplo n.º 2
0
 def tearDown(self):
     try:
         del (os.environ['DB_URI'])
     except KeyError:
         pass
     try:
         assert_event_handlers_empty()
     finally:
         clear_event_handlers()
Ejemplo n.º 3
0
    def tearDown(self):
        # Unset environment.
        try:
            del os.environ["DB_URI"]
        except KeyError:
            pass

        try:
            assert_event_handlers_empty()
        finally:
            clear_event_handlers()
    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()
Ejemplo n.º 5
0
    def tearDown(self):
        clear_event_handlers()

        # Need to drop the stored events, because the __main__#Order topics
        # mess up the multiprocessing tests (because the Orders application
        # has the same ID so events from one test cause another to fail).
        os.environ[
            "DB_URI"] = "mysql+pymysql://{}:{}@{}/eventsourcing?charset=utf8mb4&binary_prefix=true".format(
                os.getenv("MYSQL_USER", "root"),
                os.getenv("MYSQL_PASSWORD", ""),
                os.getenv("MYSQL_HOST", "127.0.0.1"),
            )
        database = SQLAlchemyDatastore(settings=SQLAlchemySettings())
        database.setup_connection()
        # Might as well drop everything....
        Base.metadata.drop_all(database._engine)

        del os.environ["DB_URI"]
 def tearDown(self):
     clear_event_handlers()
    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()
Ejemplo n.º 8
0
 def tearDown(self):
     try:
         assert_event_handlers_empty()
     except EventHandlersNotEmptyError:
         clear_event_handlers()
         raise