예제 #1
0
    def test_prepare_index_test_settings_aliases_improperly_configured(self):
        """Assert raise when name and test name are the same."""
        servers = {}
        indices = {
            'index': {
                'NAME': 'index',
                'ALIASES': ['alias_prod', 'alias_prod_2'],
                'TEST': {
                    'NAME': 'index_valid_test_name',
                    'ALIASES': ['alias_prod', 'alias_test']
                }
            }
        }

        handler = ConnectionHandler(servers, indices)
        handler.ensure_index_defaults('index')

        with self.assertRaises(ImproperlyConfigured) as raised:
            # A simple call to servers must raise.
            handler.prepare_index_test_settings('index')

        assert str(raised.exception) == (
            'Index \'index\' uses improperly the same index alias in ALIASES '
            'and in TEST\'s ALIASES settings: \'alias_prod\'.'
        )
예제 #2
0
    def test_ensure_index_defaults_not_exists(self):
        """Assert raise when the argument given is not a configured index."""
        servers = {}
        indices = {}

        handler = ConnectionHandler(servers, indices)

        with self.assertRaises(IndexDoesNotExist) as raised:
            handler.ensure_index_defaults('index')

        assert str(raised.exception) == '%r' % 'index'
예제 #3
0
    def test_ensure_index_defaults_not_exists(self):
        """Assert raise when the argument given is not a configured index."""
        servers = {}
        indices = {}

        handler = ConnectionHandler(servers, indices)

        with self.assertRaises(IndexDoesNotExist) as raised:
            handler.ensure_index_defaults('index')

        assert str(raised.exception) == '%r' % 'index'
예제 #4
0
    def test_empty_ensure_index_defaults(self):
        """Assert default values are set properly on an empty index."""
        indices = {'index': {}}

        handler = ConnectionHandler({}, indices)
        handler.ensure_index_defaults('index')

        index = handler.indices['index']

        expected_index = {
            'NAME': 'index',
            'ALIASES': [],
            'SETTINGS': None,
        }

        assert index == expected_index
예제 #5
0
    def test_empty_prepare_index_test_settings(self):
        indices = {'index': {}}

        handler = ConnectionHandler({}, indices)
        handler.ensure_index_defaults('index')
        handler.prepare_index_test_settings('index')

        index = handler.indices['index']

        expected_test_index = {
            'NAME': 'index_test',
            'ALIASES': [],
            'SETTINGS': None,
        }

        assert 'TEST' in index
        assert index['TEST'] == expected_test_index
예제 #6
0
    def test_empty_ensure_index_defaults(self):
        """Assert default values are set properly on an empty index."""
        indices = {
            'index': {}
        }

        handler = ConnectionHandler({}, indices)
        handler.ensure_index_defaults('index')

        index = handler.indices['index']

        expected_index = {
            'NAME': 'index',
            'ALIASES': [],
            'SETTINGS': None,
        }

        assert index == expected_index
예제 #7
0
    def test_empty_prepare_index_test_settings(self):
        indices = {
            'index': {}
        }

        handler = ConnectionHandler({}, indices)
        handler.ensure_index_defaults('index')
        handler.prepare_index_test_settings('index')

        index = handler.indices['index']

        expected_test_index = {
            'NAME': 'index_test',
            'ALIASES': [],
            'SETTINGS': None,
        }

        assert 'TEST' in index
        assert index['TEST'] == expected_test_index
예제 #8
0
    def test_prepare_index_test_settings_aliases_improperly_configured(self):
        """Assert raise when name and test name are the same."""
        servers = {}
        indices = {
            'index': {
                'NAME': 'index',
                'ALIASES': ['alias_prod', 'alias_prod_2'],
                'TEST': {
                    'NAME': 'index_valid_test_name',
                    'ALIASES': ['alias_prod', 'alias_test']
                }
            }
        }

        handler = ConnectionHandler(servers, indices)
        handler.ensure_index_defaults('index')

        with self.assertRaises(ImproperlyConfigured) as raised:
            # A simple call to servers must raise.
            handler.prepare_index_test_settings('index')

        assert str(raised.exception) == (
            'Index \'index\' uses improperly the same index alias in ALIASES '
            'and in TEST\'s ALIASES settings: \'alias_prod\'.')