# Path: pacman_mirrors/builder/common.py
# def build_mirror_list(self):
# 
# Path: pacman_mirrors/builder/fasttrack.py
# def build_mirror_list(self, number):
# 
# Path: pacman_mirrors/functions/fileFn.py
# def check_existance_of(filename, folder=False):
# def create_dir(foldername):
# def delete_file(filename):
# def return_mirror_filename(config):
# def write_mirror_list(config, servers, custom=False,
#                       quiet=False, interactive=False):
# def read_mirror_file(filename):
# def write_mirrorlist_header(handle, custom=False):
# def write_mirrorlist_entry(handle, mirror):
# 
# Path: pacman_mirrors/functions/configFn.py
# def setup_config():
# def sanitize_config(config):
# 
# Path: pacman_mirrors/functions/cliFn.py
# def parse_command_line(self, gtk_available):
# 
# Path: pacman_mirrors/functions/defaultFn.py
# def load_config_mirror_pool(self):
# def load_default_mirror_pool(self):
# def seed_mirrors(self, file, status=False):
# def sort_mirror_countries(self):
# 
# Path: pacman_mirrors/functions/httpFn.py
# def download_mirrors(config):
# def get_geoip_country():
# def get_mirror_response(url, maxwait=2, count=1, quiet=False, ssl_verify=True):
# def inet_conn_check(maxwait=2):
# def ping_host(host, count=1):
# def update_mirror_pool(config, quiet=False):
# 
# Path: pacman_mirrors/pacman_mirrors.py
# class PacmanMirrors:
#     """Class PacmanMirrors"""
# 
#     def __init__(self):
#         """Init"""
#         self.config = {
#             "config_file": conf.CONFIG_FILE
#         }
#         self.custom = False
#         self.default = False
#         self.fasttrack = None
#         self.geoip = False
#         self.interactive = False
#         self.max_wait_time = 2
#         self.mirrors = Mirror()
#         self.network = True
#         self.no_display = False
#         self.no_mirrorlist = False
#         self.no_status = False
#         self.quiet = False
#         self.selected_countries = []
# 
#     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)


import unittest
from unittest.mock import patch
from pacman_mirrors.builder import common, fasttrack
from pacman_mirrors.functions import fileFn, configFn, cliFn, defaultFn
from pacman_mirrors.functions import httpFn
from pacman_mirrors.pacman_mirrors import PacmanMirrors
from . import mock_configuration as conf
    "repo_arch": conf.REPO_ARCH,
    "status_file": conf.STATUS_FILE,
    "ssl_verify": True,
    "url_mirrors_json": conf.URL_MIRROR_JSON,
    "url_status_json": conf.URL_STATUS_JSON,
    "x32": False
}


class TestPacmanMirrors(unittest.TestCase):
    """Pacman Mirrors Test suite"""
    def setUp(self):
        """Setup tests"""
        pass

    @patch("os.getuid")
    @patch.object(configFn, "setup_config")
    def test_full_run_fasttrack(self,
                                mock_build_config,
                                mock_os_getuid):
        """TEST: pacman-mirrors -f5"""
        mock_os_getuid.return_value = 0
        mock_build_config.return_value = test_conf
        with unittest.mock.patch("sys.argv",
                                 ["pacman-mirrors",
                                  "-f5"]):
            app = PacmanMirrors()
            app.config = configFn.setup_config()
            fileFn.create_dir(test_conf["work_dir"])
            cliFn.parse_command_line(app, True)

# Path: pacman_mirrors/builder/common.py
# def build_mirror_list(self):
# 
# Path: pacman_mirrors/builder/fasttrack.py
# def build_mirror_list(self, number):
# 
# Path: pacman_mirrors/functions/fileFn.py
# def check_existance_of(filename, folder=False):
# def create_dir(foldername):
# def delete_file(filename):
# def return_mirror_filename(config):
# def write_mirror_list(config, servers, custom=False,
#                       quiet=False, interactive=False):
# def read_mirror_file(filename):
# def write_mirrorlist_header(handle, custom=False):
# def write_mirrorlist_entry(handle, mirror):
# 
# Path: pacman_mirrors/functions/configFn.py
# def setup_config():
# def sanitize_config(config):
# 
# Path: pacman_mirrors/functions/cliFn.py
# def parse_command_line(self, gtk_available):
# 
# Path: pacman_mirrors/functions/defaultFn.py
# def load_config_mirror_pool(self):
# def load_default_mirror_pool(self):
# def seed_mirrors(self, file, status=False):
# def sort_mirror_countries(self):
# 
# Path: pacman_mirrors/functions/httpFn.py
# def download_mirrors(config):
# def get_geoip_country():
# def get_mirror_response(url, maxwait=2, count=1, quiet=False, ssl_verify=True):
# def inet_conn_check(maxwait=2):
# def ping_host(host, count=1):
# def update_mirror_pool(config, quiet=False):
# 
# Path: pacman_mirrors/pacman_mirrors.py
# class PacmanMirrors:
#     """Class PacmanMirrors"""
# 
#     def __init__(self):
#         """Init"""
#         self.config = {
#             "config_file": conf.CONFIG_FILE
#         }
#         self.custom = False
#         self.default = False
#         self.fasttrack = None
#         self.geoip = False
#         self.interactive = False
#         self.max_wait_time = 2
#         self.mirrors = Mirror()
#         self.network = True
#         self.no_display = False
#         self.no_mirrorlist = False
#         self.no_status = False
#         self.quiet = False
#         self.selected_countries = []
# 
#     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)


# Path: tests/test_pacman_mirrors.py
import unittest
from unittest.mock import patch
from pacman_mirrors.builder import common, fasttrack
from pacman_mirrors.functions import fileFn, configFn, cliFn, defaultFn
from pacman_mirrors.functions import httpFn
from pacman_mirrors.pacman_mirrors import PacmanMirrors
from . import mock_configuration as conf

    "repo_arch": conf.REPO_ARCH,
    "status_file": conf.STATUS_FILE,
    "ssl_verify": True,
    "url_mirrors_json": conf.URL_MIRROR_JSON,
    "url_status_json": conf.URL_STATUS_JSON,
    "x32": False
}


class TestPacmanMirrors(unittest.TestCase):
    """Pacman Mirrors Test suite"""
    def setUp(self):
        """Setup tests"""
        pass

    @patch("os.getuid")
    @patch.object(configFn, "setup_config")
    def test_full_run_fasttrack(self,
                                mock_build_config,
                                mock_os_getuid):
        """TEST: pacman-mirrors -f5"""
        mock_os_getuid.return_value = 0
        mock_build_config.return_value = test_conf
        with unittest.mock.patch("sys.argv",
                                 ["pacman-mirrors",
                                  "-f5"]):
            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)