def test_find_docker_not_installed(fake_process): def raise_FNF(process): raise FileNotFoundError fake_process.register_subprocess(["docker", "inspect", "pihole"], stdout="not running FNF", callback=raise_FNF) result = utils.find_docker() assert result == [False, None] def raise_CPE(process): raise CalledProcessError(returncode=1, cmd="test") fake_process.register_subprocess(["docker", "inspect", "pihole"], stdout="not running CPE", callback=raise_CPE) result = utils.find_docker() assert result == [False, None]
def BROKEN_test_find_docker_image_found(fake_process, shared_datadir): """ Not actually launching mock process """ path = "/home/jesse/projects/pihole/etc-pihole" output = (shared_datadir / "docker_inspect_pihole.json").read_text().strip() fake_process.register_subprocess( ["docker", "inspect", "pihole"], stdout=output, ) result = utils.find_docker() # os.path.exists.assert_called_once_with(path) assert result == [True, path]
def test_find_docker_image_not_running(fake_process): fake_process.register_subprocess(["docker", "inspect", "pihole"], stdout="not running", returncode=1) result = utils.find_docker() assert result == [False, None]
def BROKEN_test_find_docker_image_not_found(fake_process): """ Not actually launching mock process """ fake_process.register_subprocess(["docker", "inspect", "pihole"], stdout="bad json") result = utils.find_docker() assert result == [False, None]
def main(): """main method""" conn = None try: utils.clear() banner.display() use_docker = False docker = utils.find_docker() if docker[0] is True: utils.success(f"+ Found Running Docker config: {docker[1]}") use_docker = prompts.confirm("Use Docker-ized config?", "n") if use_docker: db_file = docker[1] if not use_docker: print() db_file = prompts.ask_db() # ask_db validates the db, pass this connection round for easy access & "global" mgmt conn = sqlite3.connect(db_file) cur = conn.cursor() default = constants.BLOCKLIST option = "" any_save = False while option != constants.EXIT: stats.stat_bar(cur) option = prompts.main_menu(default) save = False if option == constants.BLOCKLIST: save = blocklists.manage_blocklists(cur) if option == constants.ALLOWLIST: save = allowlists.manage_allowlists(cur) if option == constants.STATS: stats.header(cur) if save: any_save = True default = constants.EXIT conn.commit() if option == constants.ALLOWLIST: stats.allow_header(cur) if option == constants.BLOCKLIST: stats.block_header(cur) if prompts.confirm("Are you finished?"): break conn.close() if any_save: update_gravity(use_docker) utils.info("\n\tBye!\n") except (KeyboardInterrupt, KeyError): if conn: conn.close() sys.exit(0)