Commit c9bde4d5 authored by FH's avatar FH

Merge branch 'adding-function-tests' into 3.2-unstable

parents 34c96d50 5d71b8f5
......@@ -80,8 +80,8 @@ class PacmanMirrors:
self.default_mirror_list = "/etc/pacman.d/mirrorlist"
self.custom_mirror_dir = "/var/lib/pacman-mirrors"
self.custom_mirror_file = "/var/lib/pacman-mirrors/Custom"
# Get config from file
self.config = self.config_init()
# Define config
self.config = {}
def append_to_server_list(self, mirror, last_sync):
"""
......@@ -647,7 +647,7 @@ class PacmanMirrors:
except HTTPException:
if not quiet:
print(txt.NEWLINE + txt.ERROR + txt.SEP +
txt.ERR_SERVER_HTTP_EXCEPTION + txt.SEP + txt.HTTP_EXCEPTION)
txt.ERR_SERVER_HTTP_EXCEPTION + txt.SEP + txt.HTTP_EXCEPTION)
return content
@staticmethod
......@@ -745,6 +745,8 @@ class PacmanMirrors:
def run(self):
"""Run"""
# Get config from file
self.config = self.config_init()
self.command_line_parse()
self.load_server_lists()
if self.interactive:
......@@ -754,5 +756,5 @@ class PacmanMirrors:
if __name__ == "__main__":
pm = PacmanMirrors()
pm.run()
pmapp = PacmanMirrors()
pmapp.run()
......@@ -28,6 +28,8 @@ class TestPacmanMirrors(unittest.TestCase):
"-m", "random",
"-d", "data/mirrors"]):
app = pacman_mirrors.PacmanMirrors()
app.config_file = "conf/pacman-mirrors.conf"
app.config = app.config_init()
app.command_line_parse()
app.load_server_lists()
......@@ -42,6 +44,8 @@ class TestPacmanMirrors(unittest.TestCase):
"-m", "random",
"-d", "data/mirrors"]):
app = pacman_mirrors.PacmanMirrors()
app.config_file = "conf/pacman-mirrors.conf"
app.config = app.config_init()
app.command_line_parse()
app.load_server_lists()
assert app.config["only_country"] == ["Germany"]
......@@ -59,6 +63,8 @@ class TestPacmanMirrors(unittest.TestCase):
"-m", "random",
"-d", "data/mirrors"]):
app = pacman_mirrors.PacmanMirrors()
app.config_file = "conf/pacman-mirrors.conf"
app.config = app.config_init()
app.command_line_parse()
app.load_server_lists()
assert app.config["only_country"] == ["France"]
......@@ -76,11 +82,69 @@ class TestPacmanMirrors(unittest.TestCase):
"-m", "random",
"-d", "data/mirrors"]):
app = pacman_mirrors.PacmanMirrors()
app.config_file = "conf/pacman-mirrors.conf"
app.config = app.config_init()
app.config["only_country"] = []
app.command_line_parse()
app.load_server_lists()
assert app.config["only_country"] == app.available_countries
@patch.object(pacman_mirrors.PacmanMirrors, "get_mirror_response_time")
def test_resp_time_calc(self, mock_calc):
"""Calculate mirror response time"""
app = pacman_mirrors.PacmanMirrors()
mock_calc.return_value = "0.067"
assert app.get_mirror_response_time(
"1486371026.6549892", "1486371026.7216527") == "0.067"
mock_calc.return_value = "0.047"
assert app.get_mirror_response_time(
"1486371026.7686312", "1486371026.8155131") == "0.047"
mock_calc.return_value = "0.156"
assert app.get_mirror_response_time(
"1486371026.815664", "1486371026.9718077") == "0.156"
@patch.object(pacman_mirrors.PacmanMirrors, "get_mirror_branch_last_sync")
def test_last_sync_calc(self, mock_calc):
"""Calculate mirror last_sync offset"""
app = pacman_mirrors.PacmanMirrors()
mock_calc.return_value = "2189:29"
assert app.get_mirror_branch_last_sync(
"2017-02-06 11:39:14.610344", "2016-11-07 06:09:51") == "2189:29"
mock_calc.return_value = "22:08"
assert app.get_mirror_branch_last_sync(
"2017-02-06 11:39:14.866841", "2017-02-05 13:31:09") == "22:08"
mock_calc.return_value = "04:20"
assert app.get_mirror_branch_last_sync(
"2017-02-06 11:39:23.523478", "2017-02-06 07:18:43") == "04:20"
@patch.object(pacman_mirrors.PacmanMirrors, "get_mirror_url")
def test_get_mirror_url(self, mock_url):
"""Extract mirror url from input"""
mock_url.return_value = "http://mirror.domain.tld"
app = pacman_mirrors.PacmanMirrors()
mock_data = "Server = http://mirror.domain.tld"
assert app.get_mirror_url(mock_data) == "http://mirror.domain.tld"
@patch.object(pacman_mirrors.PacmanMirrors, "get_mirror_country")
def test_get_mirror_country(self, mock_country):
"""Extract mirror country from input"""
mock_country.return_value = "France"
app = pacman_mirrors.PacmanMirrors()
mock_data = "## Country : France"
assert app.get_mirror_country(mock_data) == "France"
mock_data = "## Location : France"
assert app.get_mirror_country(mock_data) == "France"
mock_data = "[France]"
assert app.get_mirror_country(mock_data) == "France"
@patch.object(pacman_mirrors.PacmanMirrors, "get_mirror_branch_timestamp")
def test_get_mirror_timestamp(self, mock_timestamp):
"""Extract timestamp from input"""
mock_timestamp.return_value = "2017-02-06T07:18:43Z"
app = pacman_mirrors.PacmanMirrors()
mock_data = "date=2017-02-06T07:18:43Z"
assert app.get_mirror_branch_timestamp(mock_data) == "2017-02-06T07:18:43Z"
def tearDown(self):
pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment