link and flake cleanup
This commit is contained in:
+29
-6
@@ -47,7 +47,13 @@ class TestDNS(unittest.TestCase):
|
||||
proc.communicate.return_value = (b"some error", None)
|
||||
mock_popen.return_value = proc
|
||||
|
||||
err = dns.nsupdate("host", "1.2.3.4", "example", nsupdate_bin="/usr/bin/nsupdate", rndc_key="/etc/rndc.key")
|
||||
err = dns.nsupdate(
|
||||
"host",
|
||||
"1.2.3.4",
|
||||
"example",
|
||||
nsupdate_bin="/usr/bin/nsupdate",
|
||||
rndc_key="/etc/rndc.key",
|
||||
)
|
||||
self.assertIsNotNone(err)
|
||||
self.assertIn("some error", err)
|
||||
|
||||
@@ -71,7 +77,9 @@ class TestDNS(unittest.TestCase):
|
||||
Host = FakeHost
|
||||
|
||||
# start the thread (daemon) that processes the queue
|
||||
t = dns.start_dns_thread(FakeHbd, {"dyndomains": ["example"]}, log=log, email=email)
|
||||
t = dns.start_dns_thread(
|
||||
FakeHbd, {"dyndomains": ["example"]}, log=log, email=email
|
||||
)
|
||||
self.assertTrue(t.is_alive())
|
||||
|
||||
# enqueue one item and wait for it to be processed (polling with timeout)
|
||||
@@ -83,7 +91,9 @@ class TestDNS(unittest.TestCase):
|
||||
time.sleep(0.1)
|
||||
|
||||
self.assertTrue(logs, "dnsupdatethread did not call log")
|
||||
self.assertTrue(any("changed address" in m or "DNS updated" in m for (_h, m) in logs))
|
||||
self.assertTrue(
|
||||
any("changed address" in m or "DNS updated" in m for (_h, m) in logs)
|
||||
)
|
||||
|
||||
def test_dnsupdatethread_calls_email_on_failure(self):
|
||||
# patch nsupdate to fail with an error message
|
||||
@@ -104,7 +114,9 @@ class TestDNS(unittest.TestCase):
|
||||
class FakeHbd:
|
||||
Host = FakeHost
|
||||
|
||||
t = dns.start_dns_thread(FakeHbd, {"dyndomains": ["example"]}, log=log, email=email)
|
||||
dns.start_dns_thread(
|
||||
FakeHbd, {"dyndomains": ["example"]}, log=log, email=email
|
||||
)
|
||||
# enqueue and wait for the email to be sent
|
||||
FakeHbd.Host.dnsQ.put(("testhost", "1.2.3.4"))
|
||||
|
||||
@@ -114,12 +126,23 @@ class TestDNS(unittest.TestCase):
|
||||
time.sleep(0.1)
|
||||
|
||||
self.assertTrue(emails, "dnsupdatethread did not call email on failure")
|
||||
self.assertTrue(any("nsupdate failed" in s or "nsupdate failed" in m or "error" in m for (s, m) in emails))
|
||||
self.assertTrue(
|
||||
any(
|
||||
"nsupdate failed" in s or "nsupdate failed" in m or "error" in m
|
||||
for (s, m) in emails
|
||||
)
|
||||
)
|
||||
|
||||
@patch("hbd.dns.Popen")
|
||||
def test_nsupdate_raises_oserror(self, mock_popen):
|
||||
mock_popen.side_effect = OSError("noexec")
|
||||
err = dns.nsupdate("h", "1.2.3.4", "example", nsupdate_bin="/usr/bin/nsupdate", rndc_key="/etc/rndc.key")
|
||||
err = dns.nsupdate(
|
||||
"h",
|
||||
"1.2.3.4",
|
||||
"example",
|
||||
nsupdate_bin="/usr/bin/nsupdate",
|
||||
rndc_key="/etc/rndc.key",
|
||||
)
|
||||
self.assertIsNotNone(err)
|
||||
self.assertIn("execution failed", err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user