Add test for try_ipv6_socket

This commit is contained in:
Thomas Adamcik 2011-06-07 15:23:33 +02:00
parent d664c11e22
commit ea9159a9ba

View File

@ -1,3 +1,4 @@
import mock
import unittest
from mopidy.utils import network
@ -17,3 +18,20 @@ class FormatHostnameTest(unittest.TestCase):
def test_format_hostname_does_nothing_when_only_ipv4_available(self):
network.has_ipv6 = False
self.assertEquals(network.format_hostname('0.0.0.0'), '0.0.0.0')
class TryIPv6SocketTest(unittest.TestCase):
@mock.patch('socket.has_ipv6', False)
def test_system_that_claims_no_ipv6_support(self):
self.assertFalse(network._try_ipv6_socket())
@mock.patch('socket.has_ipv6', True)
@mock.patch('socket.socket')
def test_system_with_broken_ipv6(self, socket_mock):
socket_mock.side_effect = IOError()
self.assertFalse(network._try_ipv6_socket())
@mock.patch('socket.has_ipv6', True)
@mock.patch('socket.socket')
def test_with_working_ipv6(self, socket_mock):
socket_mock.return_value = mock.Mock()
self.assertTrue(network._try_ipv6_socket())