def test_request_cache_parameter(self):
        # When
        request = GetTodoAllRequest()

        # Then
        assert request.get_cache_key() == "GetTodoAllRequest"
        assert request.get_cache_duration() == 600
        assert request.get_cache_type() == CacheType.DISTRIBUTED
Exemplo n.º 2
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)
Exemplo n.º 3
0
    def test_handler_return_empty_list(self, mock_pydiator):
        # Given
        mock_pydiator.send.side_effect = [self.async_return([])]
        request = GetTodoAllRequest(id=1)
        expected_response = []

        # When
        response = self.async_loop(pydiator.send(request))

        # Then
        assert response == expected_response
Exemplo n.º 4
0
    def test_handler_return_list(self, mock_pydiator):
        # Given
        id_val = 1
        title_val = "title 1"
        mock_pydiator.send.side_effect = [
            self.async_return(
                [GetTodoAllDataResponse(id=id_val, title=title_val)])
        ]

        request = GetTodoAllRequest(id=id_val)
        expected_response = [GetTodoAllResponse(id=id_val, title=title_val)]

        # When
        response = self.async_loop(pydiator.send(request))

        # Then
        assert response == expected_response
Exemplo n.º 5
0
 def setUp(self):
     self.register_request(GetTodoAllRequest(), GetTodoAllHandler())
Exemplo n.º 6
0
async def get_todo_all():
    return await pydiator.send(GetTodoAllRequest())
Exemplo n.º 7
0
 async def handle(self, notification: BaseNotification):
     self.cache_provider.delete(GetTodoAllRequest().get_cache_key())