예제 #1
0
    def test_remove_extant(self, client_and_opname,
                           inserted_index_and_response):
        """ Test removal of index known to ES client. """

        client, opname = client_and_opname

        # Insert index and validate insertion.
        index, response = inserted_index_and_response
        assert index in client.indices.get_alias().keys()

        call_cli_func("index {} {}".format(opname, index), client=client)
        assert index not in client.indices.get_alias().keys()
예제 #2
0
    def test_unsupported_index_operation_subcommand(
            self, inserted_index_and_response,
            unsupported_index_operation_name):
        """ Attempt to use unsupported subcommand is erroneous/exceptional. """

        # Insert dummy test Index into default ES client and assert existence.
        index, response = inserted_index_and_response
        assert index in ES_CLIENT.indices.get_alias().keys()

        command = "index {} {}".format(unsupported_index_operation_name, index)

        # Attempt to execute unsupported subcommand fails on argparse.
        with pytest.raises(SystemExit):
            call_cli_func(command)
예제 #3
0
 def test_index_does_not_exist(self, es_client,
                               inserted_index_and_response):
     """ When Index with given name is unknown, existence is False. """
     index, response = inserted_index_and_response
     assert index in es_client.indices.get_alias().keys()
     unknown_index = "{}_unknown_suffix".format(index)
     assert not call_cli_func("index exists {}".format(unknown_index))
예제 #4
0
    def build_index(operation, name=DEFAULT_TEST_INDEX_NAME, client=ES_CLIENT):
        """
        Build Elasticsearch index with name for client.

        :param str operation: specific name for operation for Index creation
        :param str name: name for ES Index to build;
            this should begin with designated prefix for test index names
        :param elasticsearch.client.Elasticsearch client: ES client
            to use for Index construction
        :raises ValueError: if name for test index to construct
            does not begin with the designated test index name prefix
        """

        # Self-protection; require test-indicative name prefix.
        if not name.startswith(TEST_INDEX_PREFIX):
            raise ValueError("Name for ES Index in test context "
                             "should begin with {}; got {}".format(
                                 TEST_INDEX_PREFIX, name))

        # Parse arguments for Index construction and execute.
        call_cli_func("index {op} {index}".format(op=operation, index=name),
                      client=client)
예제 #5
0
 def test_index_does_exist(self, es_client, inserted_index_and_response):
     """ When Index with given name is known, existence is True. """
     index, response = inserted_index_and_response
     assert index in es_client.indices.get_alias().keys()
     assert call_cli_func("index exists {}".format(index))
예제 #6
0
 def test_remove_nonexistent(self, client_and_opname):
     """ Attempt to remove nonexistent index is fine, no effect. """
     client, opname = client_and_opname
     call_cli_func("index {} do_not_build".format(opname), client=client)