mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-15 09:07:02 +02:00
Mocked sockets
This commit is contained in:
parent
d50de8516e
commit
d943b69b3d
3 changed files with 37 additions and 23 deletions
|
@ -190,8 +190,8 @@ class EPPLibWrapper:
|
||||||
# one socket, and if successful, then we know we can connect.
|
# one socket, and if successful, then we know we can connect.
|
||||||
if (
|
if (
|
||||||
not try_start_if_invalid
|
not try_start_if_invalid
|
||||||
and settings.DEBUG
|
and (settings.DEBUG
|
||||||
or not self._test_registry_connection_success()
|
or not self._test_registry_connection_success())
|
||||||
):
|
):
|
||||||
logger.warning("Cannot contact the Registry")
|
logger.warning("Cannot contact the Registry")
|
||||||
self.pool_status.connection_success = False
|
self.pool_status.connection_success = False
|
||||||
|
|
|
@ -4,6 +4,7 @@ from django.conf import settings
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from epplibwrapper.client import EPPLibWrapper
|
from epplibwrapper.client import EPPLibWrapper
|
||||||
|
from epplibwrapper.socket import Socket
|
||||||
from epplibwrapper.utility.pool import EPPConnectionPool
|
from epplibwrapper.utility.pool import EPPConnectionPool
|
||||||
from registrar.models.domain import Domain
|
from registrar.models.domain import Domain
|
||||||
from registrar.models.domain import registry
|
from registrar.models.domain import registry
|
||||||
|
@ -122,23 +123,36 @@ class TestConnectionPool(TestCase):
|
||||||
# Fake data for the _pool object
|
# Fake data for the _pool object
|
||||||
domain, _ = Domain.objects.get_or_create(name="freeman.gov")
|
domain, _ = Domain.objects.get_or_create(name="freeman.gov")
|
||||||
|
|
||||||
def start_fake_connection(self):
|
def fake_send(self):
|
||||||
registry.pool_status.pool_running = True
|
return MagicMock(
|
||||||
registry.pool_status.connection_success = True
|
code=1000,
|
||||||
registry._pool = registry.get_pool()
|
msg="Command completed successfully",
|
||||||
|
res_data=None,
|
||||||
|
cl_tr_id="xkw1uo#2023-10-17T15:29:09.559376",
|
||||||
|
sv_tr_id="5CcH4gxISuGkq8eqvr1UyQ==-35a",
|
||||||
|
extensions=[],
|
||||||
|
msg_q=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
with ExitStack() as stack:
|
||||||
|
stack.enter_context(patch.object(Socket, "connect", None))
|
||||||
|
stack.enter_context(patch.object(Socket, "send", fake_send))
|
||||||
|
stack.enter_context(patch.object(Socket, "_create_socket", Socket()))
|
||||||
|
#stack.enter_context(patch.object(EPPLibWrapper, "get_pool", self.fake_pool))
|
||||||
|
pool = EPPLibWrapper(False)
|
||||||
# The connection pool will fail to start, start it manually
|
# The connection pool will fail to start, start it manually
|
||||||
# so that our mocks can take over
|
# so that our mocks can take over
|
||||||
with ExitStack() as stack:
|
pool.start_connection_pool(try_start_if_invalid=True)
|
||||||
stack.enter_context(patch.object(EPPLibWrapper, "get_pool", self.fake_pool))
|
print(f"this is pool {pool._pool.__dict__}")
|
||||||
stack.enter_context(patch.object(EPPLibWrapper, "start_connection_pool", start_fake_connection))
|
# Pool should be running, and be the right size
|
||||||
expected_contact = domain.security_contact
|
self.assertEqual(pool.pool_status.pool_running, True)
|
||||||
|
self.assertEqual(pool.pool_status.connection_success, True)
|
||||||
|
pool.send(commands.InfoDomain(name="test.gov"), cleaned=True)
|
||||||
|
self.assertEqual(len(pool._pool.conn), self.pool_options["size"])
|
||||||
|
|
||||||
# Pretend that we've connected
|
#pool.send()
|
||||||
registry.pool_status.pool_running = True
|
|
||||||
registry.pool_status.connection_success = True
|
|
||||||
|
|
||||||
# Trigger the getter - should succeed
|
# Trigger the getter - should succeed
|
||||||
self.assertEqual(registry.pool_status.pool_running, True)
|
#expected_contact = domain.security_contact
|
||||||
self.assertEqual(registry.pool_status.connection_success, True)
|
|
||||||
self.assertEqual(len(registry.get_pool().conn), self.pool_options["size"])
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
from auditlog.registry import auditlog # type: ignore
|
from auditlog.registry import auditlog # type: ignore
|
||||||
from .contact import Contact
|
from .contact import Contact
|
||||||
from .domain import Domain
|
|
||||||
from .domain_application import DomainApplication
|
from .domain_application import DomainApplication
|
||||||
from .domain_information import DomainInformation
|
from .domain_information import DomainInformation
|
||||||
|
from .domain import Domain
|
||||||
from .draft_domain import DraftDomain
|
from .draft_domain import DraftDomain
|
||||||
from .host_ip import HostIP
|
from .host_ip import HostIP
|
||||||
from .host import Host
|
from .host import Host
|
||||||
|
@ -17,9 +17,9 @@ from .transition_domain import TransitionDomain
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Contact",
|
"Contact",
|
||||||
"Domain",
|
|
||||||
"DomainApplication",
|
"DomainApplication",
|
||||||
"DomainInformation",
|
"DomainInformation",
|
||||||
|
"Domain",
|
||||||
"DraftDomain",
|
"DraftDomain",
|
||||||
"DomainInvitation",
|
"DomainInvitation",
|
||||||
"HostIP",
|
"HostIP",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue