Fix tests for diff scenarios

This commit is contained in:
Rebecca Hsieh 2024-02-21 08:57:26 -08:00
parent a14a32159c
commit 51411f4e3e
No known key found for this signature in database
2 changed files with 9 additions and 26 deletions

View file

@ -1679,8 +1679,6 @@ class Domain(TimeStampedModel, DomainHelper):
try: try:
data_response = self._get_or_create_domain() data_response = self._get_or_create_domain()
cache = self._extract_data_from_response(data_response) cache = self._extract_data_from_response(data_response)
# print("!!! cache is")
# print(cache)
cleaned = self._clean_cache(cache, data_response) cleaned = self._clean_cache(cache, data_response)
self._update_hosts_and_contacts(cleaned, fetch_hosts, fetch_contacts) self._update_hosts_and_contacts(cleaned, fetch_hosts, fetch_contacts)
if fetch_hosts: if fetch_hosts:

View file

@ -1625,15 +1625,10 @@ class TestRegistrantNameservers(MockEppLib):
self.assertEqual(nameservers[0][1], ["1.1.1.1"]) self.assertEqual(nameservers[0][1], ["1.1.1.1"])
patcher.stop() patcher.stop()
# 1 - is it a subdomain and it has an ip address -- COVERED?
# 2 - is it a subdomain and it doesn't have an ip address
# 3 - no subdomain, it has an ip address -- COVERED
# 4 - no subomdina, doens't have ip address
def test_nameservers_stored_on_fetch_cache_a_subdomain_with_ip(self): def test_nameservers_stored_on_fetch_cache_a_subdomain_with_ip(self):
""" """
#1: It is a subdomain, and has an IP address -- referenced by mockDataInfoDomainSubdomainAndIPAddress #1: Nameserver is a subdomain, and has an IP address
fake.meow.com is not a subdomain of fake.gov referenced by mockDataInfoDomainSubdomainAndIPAddress
""" """
with less_console_noise(): with less_console_noise():
# make the domain # make the domain
@ -1649,7 +1644,6 @@ class TestRegistrantNameservers(MockEppLib):
# force fetch_cache to be called, which will return above documented mocked hosts # force fetch_cache to be called, which will return above documented mocked hosts
domain.nameservers domain.nameservers
# This is never called?
mock_host_get_or_create.assert_called_once_with(domain=domain, name="fake.meow.gov") mock_host_get_or_create.assert_called_once_with(domain=domain, name="fake.meow.gov")
# Retrieve the mocked_host from the return value of the mock # Retrieve the mocked_host from the return value of the mock
actual_mocked_host, _ = mock_host_get_or_create.return_value actual_mocked_host, _ = mock_host_get_or_create.return_value
@ -1658,14 +1652,14 @@ class TestRegistrantNameservers(MockEppLib):
def test_nameservers_stored_on_fetch_cache_a_subdomain_without_ip(self): def test_nameservers_stored_on_fetch_cache_a_subdomain_without_ip(self):
""" """
#2: It is a subdomain, but doesn't has an IP address #2: Nameserver is a subdomain, but doesn't have an IP address associated
referenced by mockDataInfoDomainSubdomainNoIP
""" """
with less_console_noise(): with less_console_noise():
# make the domain # make the domain
domain, _ = Domain.objects.get_or_create(name="subdomainwoip.gov", state=Domain.State.READY) domain, _ = Domain.objects.get_or_create(name="subdomainwoip.gov", state=Domain.State.READY)
# mock the get_or_create methods for Host and HostIP # mock the get_or_create methods for Host and HostIP
# below should do it for mock_host_get_or_create and mock_host_ip_get_or_create right?
with patch.object(Host.objects, "get_or_create") as mock_host_get_or_create, patch.object( with patch.object(Host.objects, "get_or_create") as mock_host_get_or_create, patch.object(
HostIP.objects, "get_or_create" HostIP.objects, "get_or_create"
) as mock_host_ip_get_or_create: ) as mock_host_ip_get_or_create:
@ -1675,13 +1669,9 @@ class TestRegistrantNameservers(MockEppLib):
# force fetch_cache to be called, which will return above documented mocked hosts # force fetch_cache to be called, which will return above documented mocked hosts
domain.nameservers domain.nameservers
# This is never called?
mock_host_get_or_create.assert_called_once_with(domain=domain, name="fake.subdomainwoip.gov") mock_host_get_or_create.assert_called_once_with(domain=domain, name="fake.subdomainwoip.gov")
# Retrieve the mocked_host from the return value of the mock mock_host_ip_get_or_create.assert_not_called()
actual_mocked_host, _ = mock_host_get_or_create.return_value self.assertEqual(mock_host_ip_get_or_create.call_count, 0)
mock_host_ip_get_or_create.assert_called_with(address="", host=actual_mocked_host)
self.assertEqual(mock_host_ip_get_or_create.call_count, 1)
def test_nameservers_stored_on_fetch_cache_not_subdomain_with_ip(self): def test_nameservers_stored_on_fetch_cache_not_subdomain_with_ip(self):
""" """
@ -1690,11 +1680,9 @@ class TestRegistrantNameservers(MockEppLib):
The mocked data for the EPP calls returns a host name The mocked data for the EPP calls returns a host name
of 'fake.host.com' from InfoDomain and an array of 2 IPs: 1.2.3.4 and 2.3.4.5 of 'fake.host.com' from InfoDomain and an array of 2 IPs: 1.2.3.4 and 2.3.4.5
from InfoHost from InfoHost
"""
""" #3: Nameserver is not a subdomain, but it does have an IP address returned
#3: Not a subdomain, but it has an IP address returned due to how we return our defaults due to how we set up our defaults
fake.host.com is not a subdomain of fake.gov
""" """
with less_console_noise(): with less_console_noise():
domain, _ = Domain.objects.get_or_create(name="fake.gov", state=Domain.State.READY) domain, _ = Domain.objects.get_or_create(name="fake.gov", state=Domain.State.READY)
@ -1707,16 +1695,14 @@ class TestRegistrantNameservers(MockEppLib):
# force fetch_cache to be called, which will return above documented mocked hosts # force fetch_cache to be called, which will return above documented mocked hosts
domain.nameservers domain.nameservers
# # assert that the mocks are called
mock_host_get_or_create.assert_called_once_with(domain=domain, name="fake.host.com") mock_host_get_or_create.assert_called_once_with(domain=domain, name="fake.host.com")
# Retrieve the mocked_host from the return value of the mock
mock_host_ip_get_or_create.assert_not_called() mock_host_ip_get_or_create.assert_not_called()
self.assertEqual(mock_host_ip_get_or_create.call_count, 0) self.assertEqual(mock_host_ip_get_or_create.call_count, 0)
def test_nameservers_stored_on_fetch_cache_not_subdomain_without_ip(self): def test_nameservers_stored_on_fetch_cache_not_subdomain_without_ip(self):
""" """
#4: Not a subdomain and doesn't has an IP address (not pointing to default) #4: Nameserver is not a subdomain and doesn't have an associated IP address
referenced by self.mockDataInfoDomainNotSubdomainNoIP referenced by self.mockDataInfoDomainNotSubdomainNoIP
""" """
with less_console_noise(): with less_console_noise():
@ -1730,7 +1716,6 @@ class TestRegistrantNameservers(MockEppLib):
# force fetch_cache to be called, which will return above documented mocked hosts # force fetch_cache to be called, which will return above documented mocked hosts
domain.nameservers domain.nameservers
# # assert that the mocks are called
mock_host_get_or_create.assert_called_once_with(domain=domain, name="fake.meow.com") mock_host_get_or_create.assert_called_once_with(domain=domain, name="fake.meow.com")
mock_host_ip_get_or_create.assert_not_called() mock_host_ip_get_or_create.assert_not_called()
self.assertEqual(mock_host_ip_get_or_create.call_count, 0) self.assertEqual(mock_host_ip_get_or_create.call_count, 0)