def test_build_grid(datadir, mocker, keys: list, columns: list, dt_response_json: str, expected_json: str): import SetGridField import json import pandas as pd mocker.patch.object(SetGridField, 'demisto') SetGridField.demisto.dt.return_value = json.load( open(datadir[dt_response_json])) expected_grid = json.load(open(datadir[expected_json])) assert pd.DataFrame(expected_grid).to_dict() == SetGridField.build_grid( context_path=mocker.MagicMock(), keys=keys, columns=columns).to_dict()
def test_build_grid_command(datadir, mocker, keys: List[str], columns: List[str], unpack_nested_elements: bool, dt_response_path: str, expected_results_path: str): import json import SetGridField mocker.patch.object(SetGridField, 'get_current_table', return_value=[]) mocker.patch.object(SetGridField, 'demisto') SetGridField.demisto.dt.return_value = json.load(open(datadir[dt_response_path])) results = SetGridField.build_grid_command(grid_id='test', context_path=mocker.MagicMock(), keys=keys, columns=columns, overwrite=True, sort_by=None, unpack_nested_elements=unpack_nested_elements) expected_results = json.load(open(datadir[expected_results_path])) assert json.dumps(results) == json.dumps(expected_results)
def test_build_grid(datadir, mocker, keys: list, columns: list, dt_response_json: str, expected_json: str, unpack_nested: bool): import SetGridField import json import pandas as pd mocker.patch.object(SetGridField, 'demisto') with open(datadir[dt_response_json]) as json_file: SetGridField.demisto.dt.return_value = json.load(json_file) with open(datadir[expected_json]) as json_file: expected_grid = json.load(json_file) assert pd.DataFrame(expected_grid).to_dict() == SetGridField.build_grid( context_path=mocker.MagicMock(), keys=keys, columns=columns, unpack_nested_elements=unpack_nested).to_dict()
def test_build_grid(datadir, mocker, keys: list, columns: list, dt_response_json: str, expected_json: str, unpack_nested: bool): """Unit test Given - script args - a file When - build_grid command Then - Validate that the grid was created with the correct column names """ import SetGridField import json import pandas as pd mocker.patch.object(SetGridField, 'demisto') with open(datadir[dt_response_json]) as json_file: SetGridField.demisto.dt.return_value = json.load(json_file) with open(datadir[expected_json]) as json_file: expected_grid = json.load(json_file) assert pd.DataFrame(expected_grid).to_dict() == SetGridField.build_grid( context_path=mocker.MagicMock(), keys=keys, columns=columns, unpack_nested_elements=unpack_nested ).to_dict()
def test_build_grid_command(datadir, mocker, keys: List[str], columns: List[str], unpack_nested_elements: bool, dt_response_path: str, expected_results_path: str): """Unit test Given - script args - a file When - build_grid_command command Then - Validate that the grid was created with the correct column names """ import json import SetGridField mocker.patch.object(SetGridField, 'get_current_table', return_value=[]) mocker.patch.object(SetGridField, 'demisto') with open(datadir[dt_response_path]) as json_file: SetGridField.demisto.dt.return_value = json.load(json_file) results = SetGridField.build_grid_command(grid_id='test', context_path=mocker.MagicMock(), keys=keys, columns=columns, overwrite=True, sort_by=None, unpack_nested_elements=unpack_nested_elements) with open(datadir[expected_results_path]) as json_file: expected_results = json.load(json_file) assert json.dumps(results) == json.dumps(expected_results)