diff options
Diffstat (limited to 'designate/tests/unit/mdns/test_notify.py')
-rw-r--r-- | designate/tests/unit/mdns/test_notify.py | 76 |
1 files changed, 28 insertions, 48 deletions
diff --git a/designate/tests/unit/mdns/test_notify.py b/designate/tests/unit/mdns/test_notify.py index 68b47467..45c82338 100644 --- a/designate/tests/unit/mdns/test_notify.py +++ b/designate/tests/unit/mdns/test_notify.py @@ -20,6 +20,7 @@ import dns import dns.rdataclass import dns.rdatatype +from designate import dnsutils import designate.mdns.notify as notify import designate.tests from designate.tests.unit import RoObject @@ -130,12 +131,11 @@ class MdnsNotifyTest(designate.tests.TestCase): self.assertEqual(('ERROR', 310, 0), out) @mock.patch('time.sleep') - def test_make_and_send_dns_message_timeout(self, mock_sleep): + @mock.patch.object(dnsutils, 'send_dns_message') + def test_make_and_send_dns_message_timeout(self, mock_send_dns_message, + mock_sleep): zone = RoObject(name='zn') - self.notify._make_dns_message = mock.Mock(return_value='') - self.notify._send_dns_message = mock.Mock( - side_effect=dns.exception.Timeout - ) + mock_send_dns_message.side_effect = dns.exception.Timeout out = self.notify._make_and_send_dns_message( zone, 'host', 123, 1, 2, 3 @@ -143,12 +143,12 @@ class MdnsNotifyTest(designate.tests.TestCase): self.assertEqual((None, 3), out) - def test_make_and_send_dns_message_bad_response(self): + @mock.patch.object(dnsutils, 'send_dns_message') + def test_make_and_send_dns_message_bad_response(self, + mock_send_dns_message): zone = RoObject(name='zn') self.notify._make_dns_message = mock.Mock(return_value='') - self.notify._send_dns_message = mock.Mock( - side_effect=notify.dns_query.BadResponse - ) + mock_send_dns_message.side_effect = notify.dns_query.BadResponse out = self.notify._make_and_send_dns_message( zone, 'host', 123, 1, 2, 3 @@ -157,15 +157,14 @@ class MdnsNotifyTest(designate.tests.TestCase): self.assertEqual((None, 1), out) @mock.patch('time.sleep') - def test_make_and_send_dns_message_eagain(self, mock_sleep): + @mock.patch.object(dnsutils, 'send_dns_message') + def test_make_and_send_dns_message_eagain(self, mock_send_dns_message, + mock_sleep): # bug #1558096 zone = RoObject(name='zn') - self.notify._make_dns_message = mock.Mock(return_value='') socket_error = socket.error() socket_error.errno = socket.errno.EAGAIN - self.notify._send_dns_message = mock.Mock( - side_effect=socket_error - ) + mock_send_dns_message.side_effect = socket_error out = self.notify._make_and_send_dns_message( zone, 'host', 123, 1, 2, 3 @@ -173,15 +172,15 @@ class MdnsNotifyTest(designate.tests.TestCase): self.assertEqual((None, 3), out) - def test_make_and_send_dns_message_econnrefused(self): + @mock.patch.object(dnsutils, 'send_dns_message') + def test_make_and_send_dns_message_econnrefused(self, + mock_send_dns_message): # bug #1558096 zone = RoObject(name='zn') - self.notify._make_dns_message = mock.Mock(return_value='') socket_error = socket.error() socket_error.errno = socket.errno.ECONNREFUSED # socket errors other than EAGAIN should raise - self.notify._send_dns_message = mock.Mock( - side_effect=socket_error) + mock_send_dns_message.side_effect = socket_error self.assertRaises( socket.error, @@ -189,11 +188,11 @@ class MdnsNotifyTest(designate.tests.TestCase): zone, 'host', 123, 1, 2, 3 ) - def test_make_and_send_dns_message_nxdomain(self): + @mock.patch.object(dnsutils, 'send_dns_message') + def test_make_and_send_dns_message_nxdomain(self, mock_send_dns_message): zone = RoObject(name='zn') - self.notify._make_dns_message = mock.Mock(return_value='') response = RoObject(rcode=mock.Mock(return_value=dns.rcode.NXDOMAIN)) - self.notify._send_dns_message = mock.Mock(return_value=response) + mock_send_dns_message.return_value = response out = self.notify._make_and_send_dns_message( zone, 'host', 123, 1, 2, 3 @@ -201,17 +200,17 @@ class MdnsNotifyTest(designate.tests.TestCase): self.assertEqual((response, 1), out) - def test_make_and_send_dns_message_missing_AA_flags(self): + @mock.patch.object(dnsutils, 'send_dns_message') + def test_make_and_send_dns_message_missing_AA_flags(self, + mock_send_dns_message): zone = RoObject(name='zn') - self.notify._make_dns_message = mock.Mock(return_value='') - response = RoObject( rcode=mock.Mock(return_value=dns.rcode.NOERROR), # rcode is NOERROR but (flags & dns.flags.AA) gives 0 flags=0, answer=['answer'], ) - self.notify._send_dns_message = mock.Mock(return_value=response) + mock_send_dns_message.return_value = response out = self.notify._make_and_send_dns_message( zone, 'host', 123, 1, 2, 3 @@ -219,9 +218,10 @@ class MdnsNotifyTest(designate.tests.TestCase): self.assertEqual((None, 1), out) - def test_make_and_send_dns_message_error_flags(self): + @mock.patch.object(dnsutils, 'send_dns_message') + def test_make_and_send_dns_message_error_flags(self, + mock_send_dns_message): zone = RoObject(name='zn') - self.notify._make_dns_message = mock.Mock(return_value='') response = RoObject( rcode=mock.Mock(return_value=dns.rcode.NOERROR), # rcode is NOERROR but flags are not NOERROR @@ -229,7 +229,7 @@ class MdnsNotifyTest(designate.tests.TestCase): ednsflags=321, answer=['answer'], ) - self.notify._send_dns_message = mock.Mock(return_value=response) + mock_send_dns_message.return_value = response out = self.notify._make_and_send_dns_message( zone, 'host', 123, 1, 2, 3 @@ -266,23 +266,3 @@ class MdnsNotifyTest(designate.tests.TestCase): ';AUTHORITY', ';ADDITIONAL', ], txt) - - @mock.patch.object(notify.dns_query, 'udp') - def test_send_udp_dns_message(self, mock_udp): - self.CONF.set_override('all_tcp', False, 'service:mdns') - - self.notify._send_dns_message('msg', '192.0.2.1', 1234, 1) - - mock_udp.assert_called_with( - 'msg', '192.0.2.1', port=1234, timeout=1 - ) - - @mock.patch.object(notify.dns_query, 'tcp') - def test_send_tcp_dns_message(self, mock_tcp): - self.CONF.set_override('all_tcp', True, 'service:mdns') - - self.notify._send_dns_message('msg', '192.0.2.1', 1234, 1) - - mock_tcp.assert_called_with( - 'msg', '192.0.2.1', port=1234, timeout=1 - ) |