def test_files__missing_file(self): query = Query() with pytest.raises(QueryExecutionError) as e: query.add_query_file(os.path.join(VALID_QUERY_DIRECTORY, "not_exist.query")) assert "File or path not found" in str(e.value)
def test_directory___success(self): query = Query() expected_results = [ {"query_1": "query 1"}, {"query_2": "query 2"}, {"query_3": "query 3"}, ] query.add_query_file(VALID_QUERY_DIRECTORY) results = query.execute() assert results == expected_results
def test_files___success(self): query = Query() expected_results = [ {"query_3": "query 3"}, {"query_1": "query 1"}, ] query.add_query_file(os.path.join(VALID_QUERY_DIRECTORY, "query_3.query")) query.add_query_file(os.path.join(VALID_QUERY_DIRECTORY, "query_1.query")) results = query.execute() assert results == expected_results
def perform_query_from_file(self, query_file, **query_variables): """ Perform Query From File: Gathers data from the current VSD or ES connection using a file in the query language syntax. Result data will be returned. More information about `query` can be found at: [https://github.com/nuagenetworks/nuage-metroae-config|Nuage MetroAE Config] ``query_file`` A file containing query language to perform on the VSD or ES. ``query_variables`` A dictionary of variable values to provide or override during the query. """ reader = self.current_reader if reader is None: raise Exception("No VSD or ES connection has been made") query = Query() self.last_query = query query.set_logger(logger) query.set_reader(reader) self._register_query_readers(query) query.add_query_file(query_file) results = query.execute(None, **query_variables) return results