Пример #1
0
 def test_getlocalhost_error(self, mocker):
     mock_makesock: mocker.Mock = mocker.patch(
         "aiosmtpd.controller.makesock",
         side_effect=OSError(errno.EFAULT, "Mock Error"),
     )
     with pytest.raises(OSError, match="Mock Error") as exc:
         get_localhost()
     assert exc.value.errno == errno.EFAULT
     mock_makesock.assert_called_with(socket.AF_INET6, socket.SOCK_STREAM)
Пример #2
0
 def test_getlocalhost_6inuse(self, mocker):
     mock_makesock: mocker.Mock = mocker.patch(
         "aiosmtpd.controller.makesock",
         side_effect=OSError(errno.EADDRINUSE, "Mock IP6 used"),
     )
     assert get_localhost() == "::1"
     mock_makesock.assert_called_with(socket.AF_INET6, socket.SOCK_STREAM)
Пример #3
0
 def test_getlocalhost_6no(self, mocker, err):
     mock_makesock: mocker.Mock = mocker.patch(
         "aiosmtpd.controller.makesock",
         side_effect=OSError(errno.EADDRNOTAVAIL, "Mock IP4-only"),
     )
     assert get_localhost() == "127.0.0.1"
     mock_makesock.assert_called_with(socket.AF_INET6, socket.SOCK_STREAM)
Пример #4
0
 def _trigger_server(self) -> None:
     hostname = self.hostname or get_localhost()
     with ExitStack() as stk:
         conn = create_connection((hostname, self.port), 1.0)
         s = stk.enter_context(conn)
         # connecting using the ssl_context removed as this fails under
         # python 3.10 when using opportunistic SSL
         _ = s.recv(1024)
Пример #5
0
 def test_getlocalhost_6yes(self, mocker: MockFixture):
     mock_sock = mocker.Mock()
     mock_makesock: mocker.Mock = mocker.patch(
         "aiosmtpd.controller.makesock")
     mock_makesock.return_value.__enter__.return_value = mock_sock
     assert get_localhost() == "::1"
     mock_makesock.assert_called_with(socket.AF_INET6, socket.SOCK_STREAM)
     assert mock_sock.bind.called
Пример #6
0
 def test_getlocalhost_noipv6(self, mocker):
     mock_hasip6 = mocker.patch("aiosmtpd.controller._has_ipv6",
                                return_value=False)
     assert get_localhost() == "127.0.0.1"
     assert mock_hasip6.called
Пример #7
0
 def test_getlocalhost(self):
     assert get_localhost() in ("127.0.0.1", "::1")