Take Mock out of `allmydata.test.test_connections.TCP`

This commit is contained in:
Jean-Paul Calderone 2020-12-16 09:15:37 -05:00
parent c4e8262a99
commit eeebd15c42
2 changed files with 45 additions and 9 deletions

View File

@ -669,8 +669,8 @@ def create_connection_handlers(config, i2p_provider, tor_provider):
# create that handler, so hints which want it will be ignored. # create that handler, so hints which want it will be ignored.
handlers = { handlers = {
"tcp": _make_tcp_handler(), "tcp": _make_tcp_handler(),
"tor": tor_provider.get_tor_handler(), "tor": tor_provider.get_client_endpoint(),
"i2p": i2p_provider.get_i2p_handler(), "i2p": i2p_provider.get_client_endpoint(),
} }
log.msg( log.msg(
format="built Foolscap connection handlers for: %(known_handlers)s", format="built Foolscap connection handlers for: %(known_handlers)s",

View File

@ -1,31 +1,67 @@
import os import os
import mock import mock
from twisted.trial import unittest from twisted.trial import unittest
from twisted.internet import reactor, endpoints, defer from twisted.internet import reactor, endpoints, defer
from twisted.internet.interfaces import IStreamClientEndpoint from twisted.internet.interfaces import IStreamClientEndpoint
from foolscap.connections import tcp from foolscap.connections import tcp
from testtools.matchers import (
MatchesDict,
IsInstance,
Equals,
)
from ..node import PrivacyError, config_from_string from ..node import PrivacyError, config_from_string
from ..node import create_connection_handlers from ..node import create_connection_handlers
from ..node import create_main_tub from ..node import create_main_tub
from ..util.i2p_provider import create as create_i2p_provider from ..util.i2p_provider import create as create_i2p_provider
from ..util.tor_provider import create as create_tor_provider from ..util.tor_provider import create as create_tor_provider
from .common import (
SyncTestCase,
ConstantAddresses,
)
BASECONFIG = "" BASECONFIG = ""
class TCP(unittest.TestCase): class CreateConnectionHandlersTests(SyncTestCase):
"""
def test_default(self): Tests for the Foolscap connection handlers return by
``create_connection_handlers``.
"""
def test_foolscap_handlers(self):
"""
``create_connection_handlers`` returns a Foolscap connection handlers
dictionary mapping ``"tcp"`` to
``foolscap.connections.tcp.DefaultTCP``, ``"tor"`` to the supplied Tor
provider's handler, and ``"i2p"`` to the supplied I2P provider's
handler.
"""
config = config_from_string( config = config_from_string(
"fake.port", "fake.port",
"no-basedir", "no-basedir",
BASECONFIG, BASECONFIG,
) )
_, foolscap_handlers = create_connection_handlers(config, mock.Mock(), mock.Mock()) tor_endpoint = object()
self.assertIsInstance( tor = ConstantAddresses(handler=tor_endpoint)
foolscap_handlers['tcp'], i2p_endpoint = object()
tcp.DefaultTCP, i2p = ConstantAddresses(handler=i2p_endpoint)
_, foolscap_handlers = create_connection_handlers(
config,
i2p,
tor,
)
self.assertThat(
foolscap_handlers,
MatchesDict({
"tcp": IsInstance(tcp.DefaultTCP),
"i2p": Equals(i2p_endpoint),
"tor": Equals(tor_endpoint),
}),
) )