From fabd99e895a2f7d536b082bf9bdf4a915e048688 Mon Sep 17 00:00:00 2001 From: fhdk <fh@uex.dk> Date: Mon, 17 Apr 2017 17:52:16 +0200 Subject: [PATCH] updated tests --- tests/test_command_line_parse.py | 261 ++++--------------------------- tests/test_default_config.py | 161 ++++--------------- tests/test_httpfn.py | 61 +++----- tests/test_pacman_mirrors.py | 81 +++------- 4 files changed, 108 insertions(+), 456 deletions(-) diff --git a/tests/test_command_line_parse.py b/tests/test_command_line_parse.py index 1644ca15..fb1796de 100644 --- a/tests/test_command_line_parse.py +++ b/tests/test_command_line_parse.py @@ -14,6 +14,27 @@ from pacman_mirrors.pacman_mirrors import PacmanMirrors from pacman_mirrors import configfn from . import mock_configuration as conf +test_conf = { + "branch": "stable", + "branches": conf.BRANCHES, + "config_file": conf.CONFIG_FILE, + "custom_file": conf.CUSTOM_FILE, + "fallback_file": conf.FALLBACK, + "method": "rank", + "mirror_dir": conf.MIRROR_DIR, + "mirror_file": conf.MIRROR_FILE, + "mirror_list": conf.MIRROR_LIST, + "no_update": False, + "only_country": [], + "protocols": [], + "repo_arch": conf.REPO_ARCH, + "status_file": conf.STATUS_FILE, + "ssl": False, + "ssl_verify": True, + "url_mirrors_json": conf.URL_MIRROR_JSON, + "url_status_json": conf.URL_STATUS_JSON +} + class TestCommandLineParse(unittest.TestCase): """Pacman Mirrors Test suite""" @@ -26,25 +47,7 @@ class TestCommandLineParse(unittest.TestCase): def test_arg_branch_unstable(self, mock_build_config, mock_os_getuid): """TEST: CLI config[branch] from ARG '-b unstable'""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-b", "unstable"]): @@ -59,25 +62,7 @@ class TestCommandLineParse(unittest.TestCase): def test_arg_branch_testing(self, mock_build_config, mock_os_getuid): """TEST: CLI config[branch] from ARG '-b testing'""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-b", "testing"]): @@ -92,25 +77,7 @@ class TestCommandLineParse(unittest.TestCase): 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 = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-m", "random"]): @@ -125,25 +92,7 @@ class TestCommandLineParse(unittest.TestCase): def test_arg_mirrordir(self, mock_build_config, mock_os_getuid): """TEST: CLI config[mirror_dir] from ARG '-d /another/dir'""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-d", "/another/dir/"]): @@ -158,25 +107,7 @@ class TestCommandLineParse(unittest.TestCase): def test_arg_mirrorlist(self, mock_build_config, mock_os_getuid): """TEST: CLI config[mirror_list] from ARG '-o /another/list'""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-o", "/another/list"]): @@ -191,25 +122,7 @@ class TestCommandLineParse(unittest.TestCase): 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 = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-c", "France,Germany"]): @@ -224,25 +137,7 @@ class TestCommandLineParse(unittest.TestCase): def test_arg_custom_country(self, mock_build_config, mock_os_getuid): """TEST: CLI custom is True from ARG '-c Denmark'""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-c Denmark"]): @@ -257,25 +152,7 @@ class TestCommandLineParse(unittest.TestCase): def test_arg_geoip(self, mock_build_config, mock_os_getuid): """TEST: CLI geoip is True from ARG '--geoip'""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "--geoip"]): @@ -290,25 +167,7 @@ class TestCommandLineParse(unittest.TestCase): def test_arg_fasttrack(self, mock_build_config, mock_os_getuid): """TEST: CLI fasttrack is 5 from ARG '-f 5'""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-f 5"]): @@ -323,25 +182,7 @@ class TestCommandLineParse(unittest.TestCase): def test_arg_interactive(self, mock_build_config, mock_os_getuid): """TEST: CLI interactive is true from ARG '-i'""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-i"]): @@ -356,25 +197,7 @@ class TestCommandLineParse(unittest.TestCase): 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 = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-t 5"]): @@ -389,25 +212,7 @@ class TestCommandLineParse(unittest.TestCase): 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 = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-q"]): diff --git a/tests/test_default_config.py b/tests/test_default_config.py index 0e5e0997..9528e26c 100644 --- a/tests/test_default_config.py +++ b/tests/test_default_config.py @@ -14,6 +14,27 @@ from pacman_mirrors.pacman_mirrors import PacmanMirrors from pacman_mirrors import configfn from . import mock_configuration as conf +test_conf = { + "branch": "stable", + "branches": conf.BRANCHES, + "config_file": conf.CONFIG_FILE, + "custom_file": conf.CUSTOM_FILE, + "fallback_file": conf.FALLBACK, + "method": "rank", + "mirror_dir": conf.MIRROR_DIR, + "mirror_file": conf.MIRROR_FILE, + "mirror_list": conf.MIRROR_LIST, + "no_update": False, + "only_country": [], + "protocols": [], + "repo_arch": conf.REPO_ARCH, + "status_file": conf.STATUS_FILE, + "ssl": False, + "ssl_verify": True, + "url_mirrors_json": conf.URL_MIRROR_JSON, + "url_status_json": conf.URL_STATUS_JSON +} + class TestDefaultConfig(unittest.TestCase): """Pacman Mirrors Test suite""" @@ -26,25 +47,7 @@ class TestDefaultConfig(unittest.TestCase): def test_default_branch(self, mock_build_config, mock_os_getuid): """TEST: config[branch] = stable""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-g"]): @@ -58,25 +61,7 @@ class TestDefaultConfig(unittest.TestCase): def test_default_method(self, mock_build_config, mock_os_getuid): """TEST: config[method] = rank""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-g"]): @@ -90,25 +75,7 @@ class TestDefaultConfig(unittest.TestCase): def test_default_mirrordir(self, mock_build_config, mock_os_getuid): """TEST: config[mirror_dir] = tests/mock/var/""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-g"]): @@ -121,25 +88,7 @@ class TestDefaultConfig(unittest.TestCase): def test_default_mirrorfile(self, mock_build_config, mock_os_getuid): """TEST: config[mirror_file] = tests/mock/var/mirrors.json""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-g"]): @@ -152,25 +101,7 @@ class TestDefaultConfig(unittest.TestCase): def test_default_mirrorlist(self, mock_build_config, mock_os_getuid): """TEST: config[mirror_list] = tests/mock/etc/mirrorlist""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-g"]): @@ -183,25 +114,7 @@ class TestDefaultConfig(unittest.TestCase): def test_default_noupdate(self, mock_build_config, mock_os_getuid): """TEST: config[no_update] = False""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-g"]): @@ -214,25 +127,7 @@ class TestDefaultConfig(unittest.TestCase): def test_default_onlycountry(self, mock_build_config, mock_os_getuid): """TEST: config[only_country] = []""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-g"]): diff --git a/tests/test_httpfn.py b/tests/test_httpfn.py index 7e2c875c..69c53d55 100644 --- a/tests/test_httpfn.py +++ b/tests/test_httpfn.py @@ -15,6 +15,27 @@ from pacman_mirrors.pacman_mirrors import PacmanMirrors from pacman_mirrors import configfn from . import mock_configuration as conf +test_conf = { + "branch": "stable", + "branches": conf.BRANCHES, + "config_file": conf.CONFIG_FILE, + "custom_file": conf.CUSTOM_FILE, + "fallback_file": conf.FALLBACK, + "method": "rank", + "mirror_dir": conf.MIRROR_DIR, + "mirror_file": conf.MIRROR_FILE, + "mirror_list": conf.MIRROR_LIST, + "no_update": False, + "only_country": [], + "protocols": [], + "repo_arch": conf.REPO_ARCH, + "status_file": conf.STATUS_FILE, + "ssl": False, + "ssl_verify": True, + "url_mirrors_json": conf.URL_MIRROR_JSON, + "url_status_json": conf.URL_STATUS_JSON +} + class TestHttpFn(unittest.TestCase): """Pacman Mirrors Test suite""" @@ -29,25 +50,7 @@ class TestHttpFn(unittest.TestCase): """TEST: Geoip country IS avaiable""" mock_os_getuid.return_value = 0 mock_get_geoip_country.return_value = "France" - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "--geoip"]): @@ -64,25 +67,7 @@ class TestHttpFn(unittest.TestCase): """TEST: Geoip country IS NOT available""" mock_os_getuid.return_value = 0 mock_get_geoip_country.return_value = "Antarctica" - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "status_file": conf.STATUS_FILE, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-g", diff --git a/tests/test_pacman_mirrors.py b/tests/test_pacman_mirrors.py index c6ff0d02..73d52ab9 100644 --- a/tests/test_pacman_mirrors.py +++ b/tests/test_pacman_mirrors.py @@ -16,6 +16,27 @@ from pacman_mirrors import httpfn from pacman_mirrors.pacman_mirrors import PacmanMirrors from . import mock_configuration as conf +test_conf = { + "branch": "stable", + "branches": conf.BRANCHES, + "config_file": conf.CONFIG_FILE, + "custom_file": conf.CUSTOM_FILE, + "fallback_file": conf.FALLBACK, + "method": "rank", + "mirror_dir": conf.MIRROR_DIR, + "mirror_file": conf.MIRROR_FILE, + "mirror_list": conf.MIRROR_LIST, + "no_update": False, + "only_country": [], + "protocols": [], + "repo_arch": conf.REPO_ARCH, + "status_file": conf.STATUS_FILE, + "ssl": False, + "ssl_verify": True, + "url_mirrors_json": conf.URL_MIRROR_JSON, + "url_status_json": conf.URL_STATUS_JSON +} + class TestPacmanMirrors(unittest.TestCase): """Pacman Mirrors Test suite""" @@ -28,25 +49,7 @@ class TestPacmanMirrors(unittest.TestCase): def test_full_run_random(self, mock_build_config, mock_os_getuid): """TEST: pacman-mirrors -c all -m random""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-c", "all", @@ -75,25 +78,7 @@ class TestPacmanMirrors(unittest.TestCase): def test_full_run_fasttrack(self, mock_build_config, mock_os_getuid): """TEST: pacman-mirrors -f 5""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-f", "5"]): @@ -122,25 +107,7 @@ class TestPacmanMirrors(unittest.TestCase): def test_full_run_rank(self, mock_build_config, mock_os_getuid): """TEST: pacman-mirrors -c all -m random""" mock_os_getuid.return_value = 0 - mock_build_config.return_value = { - "branch": "stable", - "branches": conf.BRANCHES, - "config_file": conf.CONFIG_FILE, - "custom_file": conf.CUSTOM_FILE, - "fallback_file": conf.FALLBACK, - "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, - "ssl": False, - "ssl_verify": True, - "url_mirrors_json": conf.URL_MIRROR_JSON, - "url_status_json": conf.URL_STATUS_JSON - } + mock_build_config.return_value = test_conf with unittest.mock.patch("sys.argv", ["pacman-mirrors", "-c", "all"]): -- GitLab