Newer
Older
#!/usr/bin/env python
"""
test_pacman-mirrors
----------------------------------
Tests for `pacman-mirrors` module.
"""
import unittest
from unittest.mock import patch
from pacman_mirrors.pacman_mirrors import PacmanMirrors
from . import mock_configuration as conf
class TestCommandLineParse(unittest.TestCase):
"""Pacman Mirrors Test suite"""
def setUp(self):
"""Setup tests"""
pass
@patch("os.getuid")
@patch.object(configfn, "build_config")
def test_arg_branch_unstable(self, mock_build_config, mock_os_getuid):
"""TEST: config[branch] from arg -b unstable"""
mock_os_getuid.return_value = 0
mock_build_config.return_value = {
"branch": "stable",
"method": "rank",
"mirror_dir": conf.MIRROR_DIR,
"mirror_file": conf.MIRROR_FILE,
"mirror_list": conf.MIRROR_LIST,
"no_update": False,
"only_country": [],
"repo_arch": conf.REPO_ARCH,
"status_file": conf.STATUS_FILE,
"url_mirrors_json": conf.URL_MIRROR_JSON,
"url_status_json": conf.URL_STATUS_JSON
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-b", "unstable"]):
app = PacmanMirrors()
app.command_line_parse()
assert app.config["branch"] == "unstable"
@patch("os.getuid")
@patch.object(configfn, "build_config")
def test_arg_branch_testing(self, mock_build_config, mock_os_getuid):
"""TEST: config[branch] from arg -b testing"""
mock_os_getuid.return_value = 0
mock_build_config.return_value = {
"branch": "stable",
"method": "rank",
"mirror_dir": conf.MIRROR_DIR,
"mirror_file": conf.MIRROR_FILE,
"mirror_list": conf.MIRROR_LIST,
"no_update": False,
"only_country": [],
"repo_arch": conf.REPO_ARCH,
"status_file": conf.STATUS_FILE,
"url_mirrors_json": conf.URL_MIRROR_JSON,
"url_status_json": conf.URL_STATUS_JSON
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-b", "testing"]):
app = PacmanMirrors()
app.command_line_parse()
assert app.config["branch"] == "testing"
@patch("os.getuid")
@patch.object(configfn, "build_config")
def test_arg_method(self, mock_build_config, mock_os_getuid):
"""TEST: config[method] from arg -m random"""
mock_os_getuid.return_value = 0
mock_build_config.return_value = {
"branch": "stable",
"method": "rank",
"mirror_dir": conf.MIRROR_DIR,
"mirror_file": conf.MIRROR_FILE,
"mirror_list": conf.MIRROR_LIST,
"no_update": False,
"only_country": [],
"repo_arch": conf.REPO_ARCH,
"status_file": conf.STATUS_FILE,
"url_mirrors_json": conf.URL_MIRROR_JSON,
"url_status_json": conf.URL_STATUS_JSON
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-m", "random"]):
app = PacmanMirrors()
app.command_line_parse()
assert app.config["method"] == "random"
@patch("os.getuid")
@patch.object(configfn, "build_config")
def test_arg_mirrordir(self, mock_build_config, mock_os_getuid):
"""TEST: config[mirror_dir] from arg -d /another/dir"""
mock_os_getuid.return_value = 0
mock_build_config.return_value = {
"branch": "stable",
"method": "rank",
"mirror_dir": conf.MIRROR_DIR,
"mirror_file": conf.MIRROR_FILE,
"mirror_list": conf.MIRROR_LIST,
"no_update": False,
"only_country": [],
"repo_arch": conf.REPO_ARCH,
"status_file": conf.STATUS_FILE,
"url_mirrors_json": conf.URL_MIRROR_JSON,
"url_status_json": conf.URL_STATUS_JSON
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-d", "/another/dir/"]):
app = PacmanMirrors()
app.command_line_parse()
assert app.config["mirror_dir"] == "/another/dir/"
@patch("os.getuid")
@patch.object(configfn, "build_config")
def test_arg_mirrorlist(self, mock_build_config, mock_os_getuid):
"""TEST: config[mirror_list] from arg -o /another/list"""
mock_os_getuid.return_value = 0
mock_build_config.return_value = {
"branch": "stable",
"method": "rank",
"mirror_dir": conf.MIRROR_DIR,
"mirror_file": conf.MIRROR_FILE,
"mirror_list": conf.MIRROR_LIST,
"no_update": False,
"only_country": [],
"repo_arch": conf.REPO_ARCH,
"status_file": conf.STATUS_FILE,
"url_mirrors_json": conf.URL_MIRROR_JSON,
"url_status_json": conf.URL_STATUS_JSON
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-o", "/another/list"]):
app = PacmanMirrors()
app.command_line_parse()
assert app.config["mirror_list"] == "/another/list"
@patch("os.getuid")
@patch.object(configfn, "build_config")
def test_arg_onlycountry(self, mock_build_config, mock_os_getuid):
"""TEST: config[only_country] from arg -c France,Germany"""
mock_os_getuid.return_value = 0
mock_build_config.return_value = {
"branch": "stable",
"method": "rank",
"mirror_dir": conf.MIRROR_DIR,
"mirror_file": conf.MIRROR_FILE,
"mirror_list": conf.MIRROR_LIST,
"no_update": False,
"only_country": [],
"repo_arch": conf.REPO_ARCH,
"status_file": conf.STATUS_FILE,
"url_mirrors_json": conf.URL_MIRROR_JSON,
"url_status_json": conf.URL_STATUS_JSON
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-c", "France,Germany"]):
app = PacmanMirrors()
app.command_line_parse()
assert app.config["only_country"] == ["France", "Germany"]
@patch.object(configfn, "build_config")
def test_arg_custom_country(self, mock_build_config, mock_os_getuid):
"""TEST: custom is True from arg -c Denmark"""
mock_os_getuid.return_value = 0
mock_build_config.return_value = {
"branch": "stable",
"method": "rank",
"mirror_dir": conf.MIRROR_DIR,
"mirror_file": conf.MIRROR_FILE,
"mirror_list": conf.MIRROR_LIST,
"no_update": False,
"only_country": [],
"repo_arch": conf.REPO_ARCH,
"status_file": conf.STATUS_FILE,
"url_mirrors_json": conf.URL_MIRROR_JSON,
"url_status_json": conf.URL_STATUS_JSON
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-c Denmark"]):
app = PacmanMirrors()
@patch.object(configfn, "build_config")
def test_arg_geoip(self, mock_build_config, mock_os_getuid):
mock_build_config.return_value = {
"branch": "stable",
"method": "rank",
"mirror_dir": conf.MIRROR_DIR,
"mirror_file": conf.MIRROR_FILE,
"mirror_list": conf.MIRROR_LIST,
"no_update": False,
"only_country": [],
"repo_arch": conf.REPO_ARCH,
"status_file": conf.STATUS_FILE,
"url_mirrors_json": conf.URL_MIRROR_JSON,
"url_status_json": conf.URL_STATUS_JSON
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"--geoip"]):
app = PacmanMirrors()
@patch.object(configfn, "build_config")
def test_arg_fasttrack(self, mock_build_config, mock_os_getuid):
mock_build_config.return_value = {
"branch": "stable",
"method": "rank",
"mirror_dir": conf.MIRROR_DIR,
"mirror_file": conf.MIRROR_FILE,
"mirror_list": conf.MIRROR_LIST,
"no_update": False,
"only_country": [],
"repo_arch": conf.REPO_ARCH,
"status_file": conf.STATUS_FILE,
"url_mirrors_json": conf.URL_MIRROR_JSON,
"url_status_json": conf.URL_STATUS_JSON
@patch.object(configfn, "build_config")
def test_arg_interactive(self, mock_build_config, mock_os_getuid):
"""TEST: interactive is true from arg -i"""
mock_os_getuid.return_value = 0
mock_build_config.return_value = {
"branch": "stable",
"method": "rank",
"mirror_dir": conf.MIRROR_DIR,
"mirror_file": conf.MIRROR_FILE,
"mirror_list": conf.MIRROR_LIST,
"no_update": False,
"only_country": [],
"repo_arch": conf.REPO_ARCH,
"status_file": conf.STATUS_FILE,
"url_mirrors_json": conf.URL_MIRROR_JSON,
"url_status_json": conf.URL_STATUS_JSON
app.command_line_parse()
assert app.interactive is True
@patch("os.getuid")
@patch.object(configfn, "build_config")
def test_arg_max_wait_time(self, mock_build_config, mock_os_getuid):
"""TEST: max_wait_time is 5 from arg -t 5"""
mock_os_getuid.return_value = 0
mock_build_config.return_value = {
"branch": "stable",
"method": "rank",
"mirror_dir": conf.MIRROR_DIR,
"mirror_file": conf.MIRROR_FILE,
"mirror_list": conf.MIRROR_LIST,
"no_update": False,
"only_country": [],
"repo_arch": conf.REPO_ARCH,
"status_file": conf.STATUS_FILE,
"url_mirrors_json": conf.URL_MIRROR_JSON,
"url_status_json": conf.URL_STATUS_JSON
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-t 5"]):
app = PacmanMirrors()
app.command_line_parse()
assert app.max_wait_time == 5
@patch("os.getuid")
@patch.object(configfn, "build_config")
def test_arg_quiet(self, mock_build_config, mock_os_getuid):
"""TEST: quiet is True from arg -q"""
mock_os_getuid.return_value = 0
mock_build_config.return_value = {
"branch": "stable",
"method": "rank",
"mirror_dir": conf.MIRROR_DIR,
"mirror_file": conf.MIRROR_FILE,
"mirror_list": conf.MIRROR_LIST,
"no_update": False,
"only_country": [],
"repo_arch": conf.REPO_ARCH,
"status_file": conf.STATUS_FILE,
"url_mirrors_json": conf.URL_MIRROR_JSON,
"url_status_json": conf.URL_STATUS_JSON
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-q"]):
app = PacmanMirrors()