Commit 7d7fdb77 authored by FH's avatar FH

added tests

parent 82586dcd
......@@ -81,6 +81,52 @@ class TestPacmanMirrors(unittest.TestCase):
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"""
mock_calc.return_value = "0.067"
app = pacman_mirrors.PacmanMirrors()
assert app.get_mirror_response_time(
"1486371026.6549892", "1486371026.7216527") == "0.067"
@patch.object(pacman_mirrors.PacmanMirrors, "get_mirror_response_time")
def test_last_sync_calc(self, mock_calc):
"""Calculate mirror last_sync offset"""
mock_calc.return_value = "20:19"
app = pacman_mirrors.PacmanMirrors()
assert app.get_mirror_response_time(
"2017-02-06 09:50:26.544456", "2017-02-05 13:31:09") == "20:19"
@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()
assert app.get_mirror_url(
"Server = http://mirror.domain.tld") == "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()
assert app.get_mirror_country(
"## Country : France") == "France"
assert app.get_mirror_country(
"## Location : France") == "France"
assert app.get_mirror_country(
"[France]") == "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"
mock_data = "###\n### BoxIt branch state file\n###\n\n# Unique hash code representing current branch state.\n# This hash code changes as soon as anything changes in this branch.\nstate=9a255e4d625f6d3ad2643a3ff1421ad02e731938\n\n# Date and time of the last branch change.\ndate=2017-02-06T07:18:43Z"
app = pacman_mirrors.PacmanMirrors()
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