mirror of
https://github.com/StevenBlack/hosts.git
synced 2026-07-01 02:36:52 +00:00
Better name for is_valid_user_provided_domain_format.
This commit is contained in:
@@ -30,7 +30,7 @@ from updateHostsFile import (
|
|||||||
gather_custom_exclusions,
|
gather_custom_exclusions,
|
||||||
get_defaults,
|
get_defaults,
|
||||||
get_file_by_url,
|
get_file_by_url,
|
||||||
is_valid_domain_format,
|
is_valid_user_provided_domain_format,
|
||||||
matches_exclusions,
|
matches_exclusions,
|
||||||
move_hosts_file_into_place,
|
move_hosts_file_into_place,
|
||||||
normalize_rule,
|
normalize_rule,
|
||||||
@@ -125,7 +125,7 @@ class TestGetDefaults(Base):
|
|||||||
"readmedata": {},
|
"readmedata": {},
|
||||||
"readmedatafilename": ("foo" + self.sep + "readmeData.json"),
|
"readmedatafilename": ("foo" + self.sep + "readmeData.json"),
|
||||||
"exclusionpattern": r"([a-zA-Z\d-]+\.){0,}",
|
"exclusionpattern": r"([a-zA-Z\d-]+\.){0,}",
|
||||||
"exclusionregexs": [],
|
"exclusionregexes": [],
|
||||||
"exclusions": [],
|
"exclusions": [],
|
||||||
"commonexclusions": ["hulu.com"],
|
"commonexclusions": ["hulu.com"],
|
||||||
"blacklistfile": "foo" + self.sep + "blacklist",
|
"blacklistfile": "foo" + self.sep + "blacklist",
|
||||||
@@ -543,7 +543,7 @@ class TestGatherCustomExclusions(BaseStdout):
|
|||||||
# Can only test in the invalid domain case
|
# Can only test in the invalid domain case
|
||||||
# because of the settings global variable.
|
# because of the settings global variable.
|
||||||
@mock.patch("updateHostsFile.input", side_effect=["foo", "no"])
|
@mock.patch("updateHostsFile.input", side_effect=["foo", "no"])
|
||||||
@mock.patch("updateHostsFile.is_valid_domain_format", return_value=False)
|
@mock.patch("updateHostsFile.is_valid_user_provided_domain_format", return_value=False)
|
||||||
def test_basic(self, *_):
|
def test_basic(self, *_):
|
||||||
gather_custom_exclusions("foo", [])
|
gather_custom_exclusions("foo", [])
|
||||||
|
|
||||||
@@ -552,7 +552,7 @@ class TestGatherCustomExclusions(BaseStdout):
|
|||||||
self.assertIn(expected, output)
|
self.assertIn(expected, output)
|
||||||
|
|
||||||
@mock.patch("updateHostsFile.input", side_effect=["foo", "yes", "bar", "no"])
|
@mock.patch("updateHostsFile.input", side_effect=["foo", "yes", "bar", "no"])
|
||||||
@mock.patch("updateHostsFile.is_valid_domain_format", return_value=False)
|
@mock.patch("updateHostsFile.is_valid_user_provided_domain_format", return_value=False)
|
||||||
def test_multiple(self, *_):
|
def test_multiple(self, *_):
|
||||||
gather_custom_exclusions("foo", [])
|
gather_custom_exclusions("foo", [])
|
||||||
|
|
||||||
@@ -1753,9 +1753,9 @@ class TestQueryYesOrNo(BaseStdout):
|
|||||||
self.assertIn(expected, output)
|
self.assertIn(expected, output)
|
||||||
|
|
||||||
|
|
||||||
class TestIsValidDomainFormat(BaseStdout):
|
class TestIsValidUserProvidedDomainFormat(BaseStdout):
|
||||||
def test_empty_domain(self):
|
def test_empty_domain(self):
|
||||||
self.assertFalse(is_valid_domain_format(""))
|
self.assertFalse(is_valid_user_provided_domain_format(""))
|
||||||
|
|
||||||
output = sys.stdout.getvalue()
|
output = sys.stdout.getvalue()
|
||||||
expected = "You didn't enter a domain. Try again."
|
expected = "You didn't enter a domain. Try again."
|
||||||
@@ -1770,7 +1770,7 @@ class TestIsValidDomainFormat(BaseStdout):
|
|||||||
"https://github.com",
|
"https://github.com",
|
||||||
"http://www.google.com",
|
"http://www.google.com",
|
||||||
]:
|
]:
|
||||||
self.assertFalse(is_valid_domain_format(invalid_domain))
|
self.assertFalse(is_valid_user_provided_domain_format(invalid_domain))
|
||||||
|
|
||||||
output = sys.stdout.getvalue()
|
output = sys.stdout.getvalue()
|
||||||
sys.stdout = StringIO()
|
sys.stdout = StringIO()
|
||||||
@@ -1779,7 +1779,7 @@ class TestIsValidDomainFormat(BaseStdout):
|
|||||||
|
|
||||||
def test_valid_domain(self):
|
def test_valid_domain(self):
|
||||||
for valid_domain in ["github.com", "travis.org", "twitter.com"]:
|
for valid_domain in ["github.com", "travis.org", "twitter.com"]:
|
||||||
self.assertTrue(is_valid_domain_format(valid_domain))
|
self.assertTrue(is_valid_user_provided_domain_format(valid_domain))
|
||||||
|
|
||||||
output = sys.stdout.getvalue()
|
output = sys.stdout.getvalue()
|
||||||
sys.stdout = StringIO()
|
sys.stdout = StringIO()
|
||||||
|
|||||||
@@ -571,7 +571,7 @@ def gather_custom_exclusions(exclusion_pattern, exclusion_regexes):
|
|||||||
domain_prompt = "Enter the domain you want to exclude (e.g. facebook.com): "
|
domain_prompt = "Enter the domain you want to exclude (e.g. facebook.com): "
|
||||||
user_domain = input(domain_prompt)
|
user_domain = input(domain_prompt)
|
||||||
|
|
||||||
if is_valid_domain_format(user_domain):
|
if is_valid_user_provided_domain_format(user_domain):
|
||||||
exclusion_regexes = exclude_domain(
|
exclusion_regexes = exclude_domain(
|
||||||
user_domain, exclusion_pattern, exclusion_regexes
|
user_domain, exclusion_pattern, exclusion_regexes
|
||||||
)
|
)
|
||||||
@@ -1612,7 +1612,7 @@ def query_yes_no(question, default="yes"):
|
|||||||
return reply == "yes"
|
return reply == "yes"
|
||||||
|
|
||||||
|
|
||||||
def is_valid_domain_format(domain):
|
def is_valid_user_provided_domain_format(domain):
|
||||||
"""
|
"""
|
||||||
Check whether a provided domain is valid.
|
Check whether a provided domain is valid.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user