def test_arg_quiet(self, mock_build_config, mock_os_getuid): """TEST: CLI quiet is True from ARG '-q'""" mock_os_getuid.return_value = 0 mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-q"]): app = PacmanMirrors() app.config["config_file"] = conf.CONFIG_FILE app.config = configFn.setup_config() cliFn.parse_command_line(app, True) assert app.quiet is True
def test_arg_max_wait_time(self, mock_build_config, mock_os_getuid): """TEST: CLI max_wait_time is 5 from ARG '-t 5'""" mock_os_getuid.return_value = 0 mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-t5"]): app = PacmanMirrors() app.config["config_file"] = mock.CONFIG_FILE app.config = configFn.setup_config() cliFn.parse_command_line(app, True) assert app.max_wait_time == 5
def test_arg_onlycountry(self, mock_build_config, mock_os_getuid): """TEST: CLI config[only_country] from ARG '-c France,Germany'""" mock_os_getuid.return_value = 0 mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-c", "France,Germany"]): app = PacmanMirrors() app.config["config_file"] = conf.CONFIG_FILE app.config = configFn.setup_config() cliFn.parse_command_line(app, True) assert app.config["country_pool"] == ["France", "Germany"]
def test_arg_method(self, mock_build_config, mock_os_getuid): """TEST: CLI config[method] from ARG '-m random'""" mock_os_getuid.return_value = 0 mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-m", "random"]): app = PacmanMirrors() app.config["config_file"] = conf.CONFIG_FILE app.config = configFn.setup_config() cliFn.parse_command_line(app, True) assert app.config["method"] == "random"
def run(self): """ Run # Setup config: retunrs the config dictionary and true/false on custom # Parse commandline # i686 check - change branch to x32-$branch # sanitize config # Check network # Update mirror pool # Check if mirrorlist is not to be touched - normal exit # Handle missing network # Load default mirror pool # Build mirror list """ (self.config, self.custom) = config_setup.setup_config() fileFn.create_dir(self.config["work_dir"]) cliFn.parse_command_line(self, gtk_available=GTK_AVAILABLE) util.i686_check(self, write=True) util.aarch64_check(self, write=True) if not config_setup.sanitize_config(config=self.config): sys.exit(2) self.network = httpFn.check_internet_connection(tty=self.tty) if self.network: httpFn.download_mirror_pool(config=self.config, tty=self.tty, quiet=self.quiet) if self.no_mirrorlist: sys.exit(0) if not self.network: if not self.quiet: pacman_mirrors.functions.util.internet_message(tty=self.tty) self.config["method"] = "random" self.fasttrack = False """ # Load configured mirror pool """ defaultFn.load_config_mirror_pool(self) """ # Decide which type of mirrorlist to create * Fasttrack * Interactive * Default """ if self.use_async: util.async_disclaimer() resp = input() if resp.lower() == "n": exit(0) if self.fasttrack: fasttrack.build_mirror_list(self, limit=self.fasttrack) elif self.interactive: interactive.build_mirror_list(self) else: common.build_mirror_list(self)
def test_full_run_rank(self, mock_build_config, mock_os_getuid): """TEST: pacman-mirrors -c all""" mock_os_getuid.return_value = 0 mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-c", "all"]): app = PacmanMirrors() app.config = configFn.setup_config() fileFn.create_dir(test_conf["work_dir"]) cliFn.parse_command_line(app, True) httpFn.update_mirror_pool(app.config) defaultFn.load_default_mirror_pool(app) common.build_mirror_list(app)
def test_geoip_available(self, mock_build_config, mock_get_geoip_country, mock_os_getuid): """TEST: geoip country IS avaiable""" mock_os_getuid.return_value = 0 mock_build_config.return_value = test_conf mock_get_geoip_country.return_value = ["Denmark"] with unittest.mock.patch("sys.argv", ["pacman-mirrors", "--geoip"]): app = PacmanMirrors() app.config = configFn.setup_config() cliFn.parse_command_line(app, True) defaultFn.load_default_mirror_pool(app) app.selected_countries = httpFn.get_ip_country() assert app.selected_countries == ["Denmark"]
def run(self): """ Run # Setup config: retunrs the config dictionary and true/false on custom # Parse commandline # i686 check - change branch to x32-$branch # sanitize config # Check network # Update mirror pool # Check if mirrorlist is not to be touched - normal exit # Handle missing network # Load default mirror pool # Build mirror list """ (self.config, self.custom) = configFn.setup_config() fileFn.create_dir(self.config["work_dir"]) cliFn.parse_command_line(self, GTK_AVAILABLE) util.i686_check(self, write=True) if not configFn.sanitize_config(self.config): sys.exit(2) self.network = httpFn.inet_conn_check() if self.network: httpFn.update_mirror_pool(self.config, quiet=self.quiet) if self.no_mirrorlist: sys.exit(0) if not self.network: if not self.quiet: pacman_mirrors.functions.util.internet_message() self.config["method"] = "random" self.fasttrack = False """ # Load configured mirror pool """ defaultFn.load_config_mirror_pool(self) """ # Decide which type of mirrorlist to create * Fasttrack * Interactive * Default """ if self.fasttrack: fasttrack.build_mirror_list(self, self.fasttrack) elif self.interactive: interactive.build_mirror_list(self) else: common.build_mirror_list(self)
def test_geoip_available(self, mock_build_config, mock_get_geoip_country, mock_os_getuid): """TEST: geoip country IS avaiable""" mock_os_getuid.return_value = 0 mock_build_config.return_value = test_conf mock_get_geoip_country.return_value = ["Denmark"] with unittest.mock.patch("sys.argv", ["pacman-mirrors", "--geoip"]): app = PacmanMirrors() app.config = configFn.setup_config() cliFn.parse_command_line(app, True) defaultFn.load_default_mirror_pool(app) app.selected_countries = httpFn.get_geoip_country() assert app.selected_countries == ["Denmark"]