def output(cls, ns, explorer): if ns.catalog["format"] == "ascii_table": headers = ["schema", "table", "column", "has_pii"] tableprint.table(explorer.get_tabular(ns.list_all), headers) elif ns.catalog["format"] == "json": FileStore.save_schemas(explorer) elif ns.catalog["format"] == "db": DbStore.save_schemas(explorer)
def dispatch(cls, ns): logging.debug("File Dispatch entered") explorer = cls(ns) explorer.scan() if ns.catalog['format'] == "ascii_table": headers = ["Path", "Mime/Type", "pii"] tableprint.table(explorer.get_tabular(), headers) elif ns.catalog['format'] == "json": FileStore.save_schemas(explorer)
def test_file(tmp_path): tmp_file = tmp_path / "schema.json" explorer = MockExplorer( Namespace(catalog={ 'file': tmp_file, 'format': 'json' }, include_schema=(), exclude_schema=(), include_table=(), exclude_table=())) explorer._load_catalog() FileStore.save_schemas(explorer) obj = None with open(tmp_file, 'r') as fh: obj = json.load(fh) assert len(obj) > 0 assert obj[0]['name'] == 'test_store' assert len(obj[0]['tables']) == 3
def test_stdout(capsys): explorer = MockExplorer( Namespace(catalog={ 'file': None, 'format': 'json' }, include_schema=(), exclude_schema=(), include_table=(), exclude_table=())) explorer._load_catalog() FileStore.save_schemas(explorer) out, err = capsys.readouterr() obj = json.loads(out) assert len(obj) > 0 assert obj[0]['name'] == 'test_store' assert len(obj[0]['tables']) == 3
def test_stdout(capsys): explorer = MockExplorer( Namespace( catalog={"file": None, "format": "json"}, include_schema=(), exclude_schema=(), include_table=(), exclude_table=(), ) ) explorer._load_catalog() FileStore.save_schemas(explorer) out, err = capsys.readouterr() obj = json.loads(out) assert len(obj) > 0 assert obj[0]["name"] == "test_store" assert len(obj[0]["tables"]) == 3
def test_file(tmp_path): tmp_file = tmp_path / "schema.json" tmp_fh = open(tmp_file, "w") explorer = MockExplorer( Namespace( catalog={"file": tmp_fh, "format": "json"}, include_schema=(), exclude_schema=(), include_table=(), exclude_table=(), ) ) explorer._load_catalog() FileStore.save_schemas(explorer) tmp_fh.close() obj = None with open(tmp_file, "r") as fh: obj = json.load(fh) assert len(obj) > 0 assert obj[0]["name"] == "test_store" assert len(obj[0]["tables"]) == 3