Exemplo n.º 1
0
    def test_calls_the_search_api_index_method_correctly(self, search_api_client):
        for framework, doc_type_to_index_mapping in current_app.config['DM_FRAMEWORK_TO_ES_INDEX'].items():
            for doc_type, index_name in doc_type_to_index_mapping.items():

                index_object(framework, doc_type, 123, {'serialized': 'object'})

                search_api_client.index.assert_called_once_with(
                    index_name=index_name,
                    object_id=123,
                    serialized_object={'serialized': 'object'},
                    doc_type=doc_type,
                )
                search_api_client.reset_mock()
Exemplo n.º 2
0
    def test_logs_an_error_message_if_no_mapping_found(self, current_app, search_api_client):
        current_app.config = {
            'DM_FRAMEWORK_TO_ES_INDEX': {
                'not-a-framework': {
                    'services': 'g-cloud-9'
                }
            }
        }

        index_object('g-cloud-9', 'services', 123, {'serialized': 'object'})

        current_app.logger.error.assert_called_once_with(
            "Failed to find index name for framework 'g-cloud-9' with object type 'services'"
        )
Exemplo n.º 3
0
    def test_logs_an_error_message_if_no_mapping_found(self, current_app,
                                                       search_api_client):
        current_app.config = {
            'DM_FRAMEWORK_TO_ES_INDEX': {
                'not-a-framework': {
                    'services': 'g-cloud-9'
                }
            }
        }

        index_object('g-cloud-9', 'services', 123, {'serialized': 'object'})

        current_app.logger.error.assert_called_once_with(
            "Failed to find index name for framework 'g-cloud-9' with object type 'services'"
        )
Exemplo n.º 4
0
    def test_logs_a_warning_if_HTTPError_from_search_api(self, current_app, search_api_client):
        search_api_client.index.side_effect = HTTPError()
        current_app.config = {
            'DM_FRAMEWORK_TO_ES_INDEX': {
                'g-cloud-9': {
                    'services': 'g-cloud-9'
                }
            }
        }

        index_object('g-cloud-9', 'services', 123, {'serialized': 'object'})

        current_app.logger.warning.assert_called_once_with(
            'Failed to add services object with id 123 to g-cloud-9 index: Unknown request failure in dmapiclient'
        )
Exemplo n.º 5
0
    def test_calls_the_search_api_index_method_correctly(
            self, search_api_client):
        for framework, doc_type_to_index_mapping in current_app.config[
                'DM_FRAMEWORK_TO_ES_INDEX'].items():
            for doc_type, index_name in doc_type_to_index_mapping.items():

                index_object(framework, doc_type, 123,
                             {'serialized': 'object'})

                search_api_client.index.assert_called_once_with(
                    index_name=index_name,
                    object_id=123,
                    serialized_object={'serialized': 'object'},
                    doc_type=doc_type,
                )
                search_api_client.reset_mock()
Exemplo n.º 6
0
    def test_logs_a_warning_if_HTTPError_from_search_api(
            self, current_app, search_api_client):
        search_api_client.index.side_effect = HTTPError()
        current_app.config = {
            'DM_FRAMEWORK_TO_ES_INDEX': {
                'g-cloud-9': {
                    'services': 'g-cloud-9'
                }
            }
        }

        index_object('g-cloud-9', 'services', 123, {'serialized': 'object'})

        current_app.logger.warning.assert_called_once_with(
            'Failed to add services object with id 123 to g-cloud-9 index: Request failed'
        )
Exemplo n.º 7
0
    def test_calls_the_search_api_index_method_correctly(
            self, search_api_client, wait_for_response):
        for framework, doc_type_to_index_mapping in current_app.config[
                'DM_FRAMEWORK_TO_ES_INDEX'].items():
            for doc_type, index_name in doc_type_to_index_mapping.items():

                index_object(framework,
                             doc_type,
                             123, {'serialized': 'object'},
                             wait_for_response=wait_for_response)

                assert search_api_client.index.mock_calls == [
                    mock.call(
                        index_name=index_name,
                        object_id=123,
                        serialized_object={'serialized': 'object'},
                        doc_type=doc_type,
                        client_wait_for_response=wait_for_response,
                    )
                ]
                search_api_client.reset_mock()