def test_read_default_values_when_create_instance(self):
        # Given

        # When
        container = MediatrContainer()

        # Then
        assert container.get_requests() == {}
        assert container.get_notifications() == {}
        assert container.get_pipelines() == []
    def test_register_request_return_when_handler_is_not_instance_of_base_handler(
            self):
        # Given
        request = TestRequest()
        container = MediatrContainer()

        # When
        container.register_request(req=request, handler={})

        # Then
        assert len(container.get_requests()) == 0
Esempio n. 3
0
    def test_handle_return_handle_response(self):
        # Given
        container = MediatrContainer()
        container.register_request(TestRequest(), TestHandler())
        self.pipeline = DefaultPipeline(container)

        # When
        response = self.async_loop(self.pipeline.handle(req=TestRequest()))

        # Then
        assert isinstance(response, BaseResponse)
    def test_register_request_return_when_request_is_not_instance_of_base_request(
            self):
        # Given
        handler = TestHandler()
        container = MediatrContainer()

        # When
        container.register_request(req=TestResponse(success=True),
                                   handler=handler)

        # Then
        assert len(container.get_requests()) == 0
    def test_prepare_pipes_when_pipelines_length_is_equal_1(self):
        # Given
        response = TestResponse(success=True)
        container = MediatrContainer()
        test_pipeline = TestPipeline(response)

        # When
        container.prepare_pipes(test_pipeline)

        # Then
        assert len(container.get_pipelines()) == 1
        assert test_pipeline.has_next() is False
Esempio n. 6
0
    def test_handle_return_exception_when_handler_is_not(self):
        # Given
        pipeline = DefaultPipeline(MediatrContainer())

        # When
        with self.assertRaises(Exception) as context:
            self.async_loop(pipeline.handle(req=TestRequest()))

        # Then
        assert context.exception.args[0] == f'handler_not_found_for_request_:{type(TestRequest()).__name__}'
    def test_register_notification_when_added_notification(self):
        # Given
        container = MediatrContainer()

        # When
        container.register_notification(TestNotification(),
                                        [TestNotificationHandler()])

        # Then
        assert container.get_requests() == {}
        assert container.get_pipelines() == []
        assert len(container.get_notifications()) == 1
    def test_register_pipeline(self):
        # Given
        container = MediatrContainer()
        response = TestResponse(success=True)

        # When
        container.register_pipeline(TestPipeline(response))

        # Then
        assert container.get_requests() == {}
        assert container.get_notifications() == {}
        assert len(container.get_pipelines()) == 1
    def test_register_request(self):
        # Given
        request = TestRequest()
        handler = TestHandler()
        container = MediatrContainer()

        # When
        container.register_request(req=request, handler=handler)

        # Then
        assert container.get_notifications() == {}
        assert len(container.get_requests()) == 1
        assert container.get_requests()[type(request).__name__] is not None
        assert container.get_requests()[type(request).__name__] == handler
Esempio n. 10
0
    def test_get_pipelines(self):
        # Given
        response = TestResponse(success=True)
        container = MediatrContainer()
        pipeline = TestPipeline(response)

        # When
        container.register_pipeline(pipeline)
        response = container.get_pipelines()

        # Then
        assert container.get_requests() == {}
        assert container.get_notifications() == {}
        assert len(response) == 1
        assert response[0] is pipeline
Esempio n. 11
0
    def test_get_notifications(self):
        # Given
        container = MediatrContainer()
        notification = TestNotification()
        handlers = [TestNotificationHandler()]

        # When
        container.register_notification(notification, handlers)
        response = container.get_notifications()

        # Then
        assert container.get_requests() == {}
        assert container.get_pipelines() == []
        assert len(response) == 1
        assert response[type(notification).__name__] is not None
        assert response[type(notification).__name__] == handlers
Esempio n. 12
0
    def test_prepare_pipes_when_pipelines_length_is_greater_than_1(self):
        # Given
        response = TestResponse(success=True)
        test_pipeline = TestPipeline(response)
        test_default_pipeline = TestPipeline(response)

        container = MediatrContainer()
        container.register_pipeline(test_pipeline)

        # When
        container.prepare_pipes(test_default_pipeline)

        # Then
        assert len(container.get_pipelines()) == 2
        assert test_pipeline.has_next()
        assert test_default_pipeline.has_next() is False
Esempio n. 13
0
def set_up_pydiator():
    container = MediatrContainer()
    container.register_pipeline(LogPipeline())
    if cache_pipeline_is_active is True:
        cache_pipeline = CachePipeline(get_distributed_cache_provider())
        container.register_pipeline(cache_pipeline)

    # Service handlers mapping
    container.register_request(GetTodoAllRequest(), GetTodoAllHandler())
    container.register_request(GetTodoByIdRequest(), GetTodoByIdHandler())
    container.register_request(AddTodoRequest(), AddTodoHandler())
    container.register_request(UpdateTodoRequest(), UpdateTodoHandler())
    container.register_request(DeleteTodoByIdRequest(),
                               DeleteTodoByIdHandler())

    # Data handlers mapping
    container.register_request(GetTodoAllDataRequest(),
                               GetTodoAllDataHandler())
    container.register_request(GetTodoByIdDataRequest(),
                               GetTodoByIdDataHandler())
    container.register_request(AddTodoDataRequest(), AddTodoDataHandler())
    container.register_request(DeleteTodoByIdDataRequest(),
                               DeleteTodoByIdDataHandler())
    container.register_request(UpdateTodoDataRequest(),
                               UpdateTodoDataHandler())

    # Notification mapping
    container.register_notification(TodoChangeNotification(),
                                    [TodoCacheRemoveNotificationHandler()])

    # Start
    pydiator.ready(container)
Esempio n. 14
0
 def register_request(req, handler):
     container = MediatrContainer()
     container.register_request(req, handler)
     pydiator.ready(container)