mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-01 02:03:56 +02:00
Merge branch 'main' into za/1411-make-statuses-more-meaningful
This commit is contained in:
commit
7c05762293
24 changed files with 6682 additions and 6776 deletions
|
@ -145,7 +145,7 @@ You can change the logging verbosity, if needed. Do a web search for "django log
|
|||
|
||||
## Mock data
|
||||
|
||||
There is a `post_migrate` signal in [signals.py](../../src/registrar/signals.py) that will load the fixtures from [fixtures_user.py](../../src/registrar/fixtures_users.py) and [fixtures_applications.py](../../src/registrar/fixtures_applications.py), giving you some test data to play with while developing.
|
||||
[load.py](../../src/registrar/management/commands/load.py) called from docker-compose (locally) and reset-db.yml (upper) loads the fixtures from [fixtures_user.py](../../src/registrar/fixtures_users.py) and [fixtures_applications.py](../../src/registrar/fixtures_applications.py), giving you some test data to play with while developing.
|
||||
|
||||
See the [database-access README](./database-access.md) for information on how to pull data to update these fixtures.
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ class ViewsTest(TestCase):
|
|||
pass
|
||||
|
||||
def test_openid_sets_next(self, mock_client):
|
||||
with less_console_noise():
|
||||
# setup
|
||||
callback_url = reverse("openid_login_callback")
|
||||
# mock
|
||||
|
@ -49,10 +50,10 @@ class ViewsTest(TestCase):
|
|||
self.assertContains(response, "Hi")
|
||||
|
||||
def test_openid_raises(self, mock_client):
|
||||
with less_console_noise():
|
||||
# mock
|
||||
mock_client.create_authn_request.side_effect = Exception("Test")
|
||||
# test
|
||||
with less_console_noise():
|
||||
response = self.client.get(reverse("login"))
|
||||
# assert
|
||||
self.assertEqual(response.status_code, 500)
|
||||
|
@ -62,17 +63,18 @@ class ViewsTest(TestCase):
|
|||
def test_callback_with_no_session_state(self, mock_client):
|
||||
"""If the local session is None (ie the server restarted while user was logged out),
|
||||
we do not throw an exception. Rather, we attempt to login again."""
|
||||
with less_console_noise():
|
||||
# mock
|
||||
mock_client.get_default_acr_value.side_effect = self.create_acr
|
||||
mock_client.callback.side_effect = NoStateDefined()
|
||||
# test
|
||||
with less_console_noise():
|
||||
response = self.client.get(reverse("openid_login_callback"))
|
||||
# assert
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertEqual(response.url, "/")
|
||||
|
||||
def test_login_callback_reads_next(self, mock_client):
|
||||
with less_console_noise():
|
||||
# setup
|
||||
session = self.client.session
|
||||
session["next"] = reverse("logout")
|
||||
|
@ -89,6 +91,7 @@ class ViewsTest(TestCase):
|
|||
def test_login_callback_no_step_up_auth(self, mock_client):
|
||||
"""Walk through login_callback when requires_step_up_auth returns False
|
||||
and assert that we have a redirect to /"""
|
||||
with less_console_noise():
|
||||
# setup
|
||||
session = self.client.session
|
||||
session.save()
|
||||
|
@ -104,23 +107,20 @@ class ViewsTest(TestCase):
|
|||
def test_requires_step_up_auth(self, mock_client):
|
||||
"""Invoke login_callback passing it a request when requires_step_up_auth returns True
|
||||
and assert that session is updated and create_authn_request (mock) is called."""
|
||||
with less_console_noise():
|
||||
# Configure the mock to return an expected value for get_step_up_acr_value
|
||||
mock_client.return_value.get_step_up_acr_value.return_value = "step_up_acr_value"
|
||||
|
||||
# Create a mock request
|
||||
request = self.factory.get("/some-url")
|
||||
request.session = {"acr_value": ""}
|
||||
|
||||
# Ensure that the CLIENT instance used in login_callback is the mock
|
||||
# patch requires_step_up_auth to return True
|
||||
with patch("djangooidc.views.requires_step_up_auth", return_value=True), patch(
|
||||
"djangooidc.views.CLIENT.create_authn_request", return_value=MagicMock()
|
||||
) as mock_create_authn_request:
|
||||
login_callback(request)
|
||||
|
||||
# create_authn_request only gets called when requires_step_up_auth is True
|
||||
# and it changes this acr_value in request.session
|
||||
|
||||
# Assert that acr_value is no longer empty string
|
||||
self.assertNotEqual(request.session["acr_value"], "")
|
||||
# And create_authn_request was called again
|
||||
|
@ -131,20 +131,18 @@ class ViewsTest(TestCase):
|
|||
and assert that session is not updated and create_authn_request (mock) is not called.
|
||||
|
||||
Possibly redundant with test_login_callback_requires_step_up_auth"""
|
||||
with less_console_noise():
|
||||
# Create a mock request
|
||||
request = self.factory.get("/some-url")
|
||||
request.session = {"acr_value": ""}
|
||||
|
||||
# Ensure that the CLIENT instance used in login_callback is the mock
|
||||
# patch requires_step_up_auth to return False
|
||||
with patch("djangooidc.views.requires_step_up_auth", return_value=False), patch(
|
||||
"djangooidc.views.CLIENT.create_authn_request", return_value=MagicMock()
|
||||
) as mock_create_authn_request:
|
||||
login_callback(request)
|
||||
|
||||
# create_authn_request only gets called when requires_step_up_auth is True
|
||||
# and it changes this acr_value in request.session
|
||||
|
||||
# Assert that acr_value is NOT updated by testing that it is still an empty string
|
||||
self.assertEqual(request.session["acr_value"], "")
|
||||
# Assert create_authn_request was not called
|
||||
|
@ -152,6 +150,7 @@ class ViewsTest(TestCase):
|
|||
|
||||
@patch("djangooidc.views.authenticate")
|
||||
def test_login_callback_raises(self, mock_auth, mock_client):
|
||||
with less_console_noise():
|
||||
# mock
|
||||
mock_client.callback.side_effect = self.user_info
|
||||
mock_auth.return_value = None
|
||||
|
@ -164,6 +163,7 @@ class ViewsTest(TestCase):
|
|||
self.assertIn("Unauthorized", response.content.decode("utf-8"))
|
||||
|
||||
def test_logout_redirect_url(self, mock_client):
|
||||
with less_console_noise():
|
||||
# setup
|
||||
session = self.client.session
|
||||
session["state"] = "TEST" # nosec B105
|
||||
|
@ -194,6 +194,7 @@ class ViewsTest(TestCase):
|
|||
self.assertTrue(mock_logout.called)
|
||||
|
||||
def test_logout_callback_redirects(self, _):
|
||||
with less_console_noise():
|
||||
# setup
|
||||
session = self.client.session
|
||||
session["next"] = reverse("logout")
|
||||
|
|
51
src/epplibwrapper/tests/common.py
Normal file
51
src/epplibwrapper/tests/common.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
import os
|
||||
import logging
|
||||
|
||||
from contextlib import contextmanager
|
||||
|
||||
|
||||
def get_handlers():
|
||||
"""Obtain pointers to all StreamHandlers."""
|
||||
handlers = {}
|
||||
|
||||
rootlogger = logging.getLogger()
|
||||
for h in rootlogger.handlers:
|
||||
if isinstance(h, logging.StreamHandler):
|
||||
handlers[h.name] = h
|
||||
|
||||
for logger in logging.Logger.manager.loggerDict.values():
|
||||
if not isinstance(logger, logging.PlaceHolder):
|
||||
for h in logger.handlers:
|
||||
if isinstance(h, logging.StreamHandler):
|
||||
handlers[h.name] = h
|
||||
|
||||
return handlers
|
||||
|
||||
|
||||
@contextmanager
|
||||
def less_console_noise():
|
||||
"""
|
||||
Context manager to use in tests to silence console logging.
|
||||
|
||||
This is helpful on tests which trigger console messages
|
||||
(such as errors) which are normal and expected.
|
||||
|
||||
It can easily be removed to debug a failing test.
|
||||
"""
|
||||
restore = {}
|
||||
handlers = get_handlers()
|
||||
devnull = open(os.devnull, "w")
|
||||
|
||||
# redirect all the streams
|
||||
for handler in handlers.values():
|
||||
prior = handler.setStream(devnull)
|
||||
restore[handler.name] = prior
|
||||
try:
|
||||
# run the test
|
||||
yield
|
||||
finally:
|
||||
# restore the streams
|
||||
for handler in handlers.values():
|
||||
handler.setStream(restore[handler.name])
|
||||
# close the file we opened
|
||||
devnull.close()
|
|
@ -9,7 +9,7 @@ from epplibwrapper.socket import Socket
|
|||
from epplibwrapper.utility.pool import EPPConnectionPool
|
||||
from registrar.models.domain import registry
|
||||
from contextlib import ExitStack
|
||||
|
||||
from .common import less_console_noise
|
||||
import logging
|
||||
|
||||
try:
|
||||
|
@ -135,6 +135,7 @@ class TestConnectionPool(TestCase):
|
|||
stack.enter_context(patch.object(EPPConnectionPool, "kill_all_connections", do_nothing))
|
||||
stack.enter_context(patch.object(SocketTransport, "send", self.fake_send))
|
||||
stack.enter_context(patch.object(SocketTransport, "receive", fake_receive))
|
||||
with less_console_noise():
|
||||
# Restart the connection pool
|
||||
registry.start_connection_pool()
|
||||
# Pool should be running, and be the right size
|
||||
|
@ -152,6 +153,8 @@ class TestConnectionPool(TestCase):
|
|||
# The number of open pools should match the number of requested ones.
|
||||
# If it is 0, then they failed to open
|
||||
self.assertEqual(len(registry._pool.conn), self.pool_options["size"])
|
||||
# Kill the connection pool
|
||||
registry.kill_pool()
|
||||
|
||||
@patch.object(EPPLibWrapper, "_test_registry_connection_success", patch_success)
|
||||
def test_pool_restarts_on_send(self):
|
||||
|
@ -198,16 +201,22 @@ class TestConnectionPool(TestCase):
|
|||
xml = (location).read_bytes()
|
||||
return xml
|
||||
|
||||
def do_nothing(command):
|
||||
pass
|
||||
|
||||
# Mock what happens inside the "with"
|
||||
with ExitStack() as stack:
|
||||
stack.enter_context(patch.object(EPPConnectionPool, "_create_socket", self.fake_socket))
|
||||
stack.enter_context(patch.object(Socket, "connect", self.fake_client))
|
||||
stack.enter_context(patch.object(EPPConnectionPool, "kill_all_connections", do_nothing))
|
||||
stack.enter_context(patch.object(SocketTransport, "send", self.fake_send))
|
||||
stack.enter_context(patch.object(SocketTransport, "receive", fake_receive))
|
||||
with less_console_noise():
|
||||
# Start the connection pool
|
||||
registry.start_connection_pool()
|
||||
# Kill the connection pool
|
||||
registry.kill_pool()
|
||||
|
||||
self.assertEqual(registry.pool_status.connection_success, False)
|
||||
self.assertEqual(registry.pool_status.pool_running, False)
|
||||
|
||||
# An exception should be raised as end user will be informed
|
||||
|
@ -227,6 +236,8 @@ class TestConnectionPool(TestCase):
|
|||
# The number of open pools should match the number of requested ones.
|
||||
# If it is 0, then they failed to open
|
||||
self.assertEqual(len(registry._pool.conn), self.pool_options["size"])
|
||||
# Kill the connection pool
|
||||
registry.kill_pool()
|
||||
|
||||
@patch.object(EPPLibWrapper, "_test_registry_connection_success", patch_success)
|
||||
def test_raises_connection_error(self):
|
||||
|
@ -236,6 +247,9 @@ class TestConnectionPool(TestCase):
|
|||
with ExitStack() as stack:
|
||||
stack.enter_context(patch.object(EPPConnectionPool, "_create_socket", self.fake_socket))
|
||||
stack.enter_context(patch.object(Socket, "connect", self.fake_client))
|
||||
with less_console_noise():
|
||||
# Start the connection pool
|
||||
registry.start_connection_pool()
|
||||
|
||||
# Pool should be running
|
||||
self.assertEqual(registry.pool_status.connection_success, True)
|
||||
|
|
|
@ -85,6 +85,21 @@ class EPPConnectionPool(ConnectionPool):
|
|||
logger.error(message, exc_info=True)
|
||||
raise PoolError(code=PoolErrorCodes.KEEP_ALIVE_FAILED) from err
|
||||
|
||||
def _keepalive_periodic(self):
|
||||
"""Overriding _keepalive_periodic from geventconnpool so that PoolErrors
|
||||
are properly handled, as opposed to printing to stdout"""
|
||||
delay = float(self.keepalive) / self.size
|
||||
while 1:
|
||||
try:
|
||||
with self.get() as c:
|
||||
self._keepalive(c)
|
||||
except PoolError as err:
|
||||
logger.error(err.message, exc_info=True)
|
||||
except self.exc_classes:
|
||||
# Nothing to do, the pool will generate a new connection later
|
||||
pass
|
||||
gevent.sleep(delay)
|
||||
|
||||
def _create_socket(self, client, login) -> Socket:
|
||||
"""Creates and returns a socket instance"""
|
||||
socket = Socket(client, login)
|
||||
|
|
|
@ -677,6 +677,7 @@ class DomainInformationAdmin(ListHeaderAdmin):
|
|||
"type_of_work",
|
||||
"more_organization_information",
|
||||
"domain",
|
||||
"domain_application",
|
||||
"submitter",
|
||||
"no_other_contacts_rationale",
|
||||
"anything_else",
|
||||
|
@ -845,6 +846,7 @@ class DomainApplicationAdmin(ListHeaderAdmin):
|
|||
"creator",
|
||||
"about_your_organization",
|
||||
"requested_domain",
|
||||
"approved_domain",
|
||||
"alternative_domains",
|
||||
"purpose",
|
||||
"submitter",
|
||||
|
|
|
@ -12,6 +12,7 @@ from django.utils import timezone
|
|||
from typing import Any
|
||||
from registrar.models.host import Host
|
||||
from registrar.models.host_ip import HostIP
|
||||
from registrar.utility.enums import DefaultEmail
|
||||
|
||||
from registrar.utility.errors import (
|
||||
ActionNotAllowed,
|
||||
|
@ -1437,7 +1438,9 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
is_security = contact.contact_type == contact.ContactTypeChoices.SECURITY
|
||||
DF = epp.DiscloseField
|
||||
fields = {DF.EMAIL}
|
||||
disclose = is_security and contact.email != PublicContact.get_default_security().email
|
||||
|
||||
hidden_security_emails = [DefaultEmail.PUBLIC_CONTACT_DEFAULT.value, DefaultEmail.LEGACY_DEFAULT.value]
|
||||
disclose = is_security and contact.email not in hidden_security_emails
|
||||
# Delete after testing on other devices
|
||||
logger.info("Updated domain contact %s to disclose: %s", contact.email, disclose)
|
||||
# Will only disclose DF.EMAIL if its not the default
|
||||
|
|
|
@ -4,6 +4,8 @@ from string import ascii_uppercase, ascii_lowercase, digits
|
|||
|
||||
from django.db import models
|
||||
|
||||
from registrar.utility.enums import DefaultEmail
|
||||
|
||||
from .utility.time_stamped_model import TimeStampedModel
|
||||
|
||||
|
||||
|
@ -87,7 +89,7 @@ class PublicContact(TimeStampedModel):
|
|||
sp="VA",
|
||||
pc="20598-0645",
|
||||
cc="US",
|
||||
email="dotgov@cisa.dhs.gov",
|
||||
email=DefaultEmail.PUBLIC_CONTACT_DEFAULT.value,
|
||||
voice="+1.8882820870",
|
||||
pw="thisisnotapassword",
|
||||
)
|
||||
|
@ -104,7 +106,7 @@ class PublicContact(TimeStampedModel):
|
|||
sp="VA",
|
||||
pc="22201",
|
||||
cc="US",
|
||||
email="dotgov@cisa.dhs.gov",
|
||||
email=DefaultEmail.PUBLIC_CONTACT_DEFAULT.value,
|
||||
voice="+1.8882820870",
|
||||
pw="thisisnotapassword",
|
||||
)
|
||||
|
@ -121,7 +123,7 @@ class PublicContact(TimeStampedModel):
|
|||
sp="VA",
|
||||
pc="22201",
|
||||
cc="US",
|
||||
email="dotgov@cisa.dhs.gov",
|
||||
email=DefaultEmail.PUBLIC_CONTACT_DEFAULT.value,
|
||||
voice="+1.8882820870",
|
||||
pw="thisisnotapassword",
|
||||
)
|
||||
|
@ -138,7 +140,7 @@ class PublicContact(TimeStampedModel):
|
|||
sp="VA",
|
||||
pc="22201",
|
||||
cc="US",
|
||||
email="dotgov@cisa.dhs.gov",
|
||||
email=DefaultEmail.PUBLIC_CONTACT_DEFAULT.value,
|
||||
voice="+1.8882820870",
|
||||
pw="thisisnotapassword",
|
||||
)
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
</ul>
|
||||
</p>
|
||||
|
||||
<p>Names that <em>uniquely apply to your organization</em> are likely to be approved over names that could also apply to other organizations. In most instances, this requires including your state’s two-letter abbreviation.</p>
|
||||
<p>Names that <em>uniquely apply to your organization</em> are likely to be approved over names that could also apply to other organizations.
|
||||
{% if not is_federal %}In most instances, this requires including your state’s two-letter abbreviation.{% endif %}</p>
|
||||
|
||||
<p>Requests for your organization’s initials or an abbreviated name might not be approved, but we encourage you to request the name you want.</p>
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load static form_helpers url_helpers %}
|
||||
|
||||
{% block title %}Request a .gov domain | {{form_titles|get_item:steps.current}} | {% endblock %}
|
||||
{% block title %}{{form_titles|get_item:steps.current}} | Request a .gov | {% endblock %}
|
||||
{% block content %}
|
||||
<div class="grid-container">
|
||||
<div class="grid-row grid-gap">
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
{% include "includes/summary_item.html" with title='Your contact information' value=request.user.contact contact='true' edit_link=url editable=domain.is_editable %}
|
||||
|
||||
{% url 'domain-security-email' pk=domain.id as url %}
|
||||
{% if security_email is not None and security_email != default_security_email%}
|
||||
{% if security_email is not None and security_email not in hidden_security_emails%}
|
||||
{% include "includes/summary_item.html" with title='Security email' value=security_email edit_link=url editable=domain.is_editable %}
|
||||
{% else %}
|
||||
{% include "includes/summary_item.html" with title='Security email' value='None provided' edit_link=url editable=domain.is_editable %}
|
||||
|
|
|
@ -12,6 +12,7 @@ from typing import List, Dict
|
|||
from django.contrib.sessions.middleware import SessionMiddleware
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model, login
|
||||
from django.utils.timezone import make_aware
|
||||
|
||||
from registrar.models import (
|
||||
Contact,
|
||||
|
@ -643,7 +644,7 @@ class MockEppLib(TestCase):
|
|||
self,
|
||||
id,
|
||||
email,
|
||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
cr_date=make_aware(datetime.datetime(2023, 5, 25, 19, 45, 35)),
|
||||
pw="thisisnotapassword",
|
||||
):
|
||||
fake = info.InfoContactResultData(
|
||||
|
@ -681,7 +682,7 @@ class MockEppLib(TestCase):
|
|||
|
||||
mockDataInfoDomain = fakedEppObject(
|
||||
"fakePw",
|
||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
cr_date=make_aware(datetime.datetime(2023, 5, 25, 19, 45, 35)),
|
||||
contacts=[common.DomainContact(contact="123", type=PublicContact.ContactTypeChoices.SECURITY)],
|
||||
hosts=["fake.host.com"],
|
||||
statuses=[
|
||||
|
@ -692,7 +693,7 @@ class MockEppLib(TestCase):
|
|||
)
|
||||
mockDataExtensionDomain = fakedEppObject(
|
||||
"fakePw",
|
||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
cr_date=make_aware(datetime.datetime(2023, 5, 25, 19, 45, 35)),
|
||||
contacts=[common.DomainContact(contact="123", type=PublicContact.ContactTypeChoices.SECURITY)],
|
||||
hosts=["fake.host.com"],
|
||||
statuses=[
|
||||
|
@ -706,7 +707,7 @@ class MockEppLib(TestCase):
|
|||
)
|
||||
InfoDomainWithContacts = fakedEppObject(
|
||||
"fakepw",
|
||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
cr_date=make_aware(datetime.datetime(2023, 5, 25, 19, 45, 35)),
|
||||
contacts=[
|
||||
common.DomainContact(
|
||||
contact="securityContact",
|
||||
|
@ -731,7 +732,7 @@ class MockEppLib(TestCase):
|
|||
|
||||
InfoDomainWithDefaultSecurityContact = fakedEppObject(
|
||||
"fakepw",
|
||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
cr_date=make_aware(datetime.datetime(2023, 5, 25, 19, 45, 35)),
|
||||
contacts=[
|
||||
common.DomainContact(
|
||||
contact="defaultSec",
|
||||
|
@ -750,7 +751,7 @@ class MockEppLib(TestCase):
|
|||
)
|
||||
InfoDomainWithVerisignSecurityContact = fakedEppObject(
|
||||
"fakepw",
|
||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
cr_date=make_aware(datetime.datetime(2023, 5, 25, 19, 45, 35)),
|
||||
contacts=[
|
||||
common.DomainContact(
|
||||
contact="defaultVeri",
|
||||
|
@ -766,7 +767,7 @@ class MockEppLib(TestCase):
|
|||
|
||||
InfoDomainWithDefaultTechnicalContact = fakedEppObject(
|
||||
"fakepw",
|
||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
cr_date=make_aware(datetime.datetime(2023, 5, 25, 19, 45, 35)),
|
||||
contacts=[
|
||||
common.DomainContact(
|
||||
contact="defaultTech",
|
||||
|
@ -791,14 +792,14 @@ class MockEppLib(TestCase):
|
|||
|
||||
infoDomainNoContact = fakedEppObject(
|
||||
"security",
|
||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
cr_date=make_aware(datetime.datetime(2023, 5, 25, 19, 45, 35)),
|
||||
contacts=[],
|
||||
hosts=["fake.host.com"],
|
||||
)
|
||||
|
||||
infoDomainThreeHosts = fakedEppObject(
|
||||
"my-nameserver.gov",
|
||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
cr_date=make_aware(datetime.datetime(2023, 5, 25, 19, 45, 35)),
|
||||
contacts=[],
|
||||
hosts=[
|
||||
"ns1.my-nameserver-1.com",
|
||||
|
@ -809,25 +810,25 @@ class MockEppLib(TestCase):
|
|||
|
||||
infoDomainNoHost = fakedEppObject(
|
||||
"my-nameserver.gov",
|
||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
cr_date=make_aware(datetime.datetime(2023, 5, 25, 19, 45, 35)),
|
||||
contacts=[],
|
||||
hosts=[],
|
||||
)
|
||||
|
||||
infoDomainTwoHosts = fakedEppObject(
|
||||
"my-nameserver.gov",
|
||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
cr_date=make_aware(datetime.datetime(2023, 5, 25, 19, 45, 35)),
|
||||
contacts=[],
|
||||
hosts=["ns1.my-nameserver-1.com", "ns1.my-nameserver-2.com"],
|
||||
)
|
||||
|
||||
mockDataInfoHosts = fakedEppObject(
|
||||
"lastPw",
|
||||
cr_date=datetime.datetime(2023, 8, 25, 19, 45, 35),
|
||||
cr_date=make_aware(datetime.datetime(2023, 8, 25, 19, 45, 35)),
|
||||
addrs=[common.Ip(addr="1.2.3.4"), common.Ip(addr="2.3.4.5")],
|
||||
)
|
||||
|
||||
mockDataHostChange = fakedEppObject("lastPw", cr_date=datetime.datetime(2023, 8, 25, 19, 45, 35))
|
||||
mockDataHostChange = fakedEppObject("lastPw", cr_date=make_aware(datetime.datetime(2023, 8, 25, 19, 45, 35)))
|
||||
addDsData1 = {
|
||||
"keyTag": 1234,
|
||||
"alg": 3,
|
||||
|
@ -859,7 +860,7 @@ class MockEppLib(TestCase):
|
|||
|
||||
infoDomainHasIP = fakedEppObject(
|
||||
"nameserverwithip.gov",
|
||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
cr_date=make_aware(datetime.datetime(2023, 5, 25, 19, 45, 35)),
|
||||
contacts=[
|
||||
common.DomainContact(
|
||||
contact="securityContact",
|
||||
|
@ -884,7 +885,7 @@ class MockEppLib(TestCase):
|
|||
|
||||
justNameserver = fakedEppObject(
|
||||
"justnameserver.com",
|
||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
cr_date=make_aware(datetime.datetime(2023, 5, 25, 19, 45, 35)),
|
||||
contacts=[
|
||||
common.DomainContact(
|
||||
contact="securityContact",
|
||||
|
@ -907,7 +908,7 @@ class MockEppLib(TestCase):
|
|||
|
||||
infoDomainCheckHostIPCombo = fakedEppObject(
|
||||
"nameserversubdomain.gov",
|
||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||
cr_date=make_aware(datetime.datetime(2023, 5, 25, 19, 45, 35)),
|
||||
contacts=[],
|
||||
hosts=[
|
||||
"ns1.nameserversubdomain.gov",
|
||||
|
|
|
@ -59,11 +59,11 @@ class TestDomainAdmin(MockEppLib):
|
|||
"""
|
||||
Make sure the short name is displaying in admin on the list page
|
||||
"""
|
||||
with less_console_noise():
|
||||
self.client.force_login(self.superuser)
|
||||
application = completed_application(status=DomainApplication.ApplicationStatus.IN_REVIEW)
|
||||
mock_client = MockSESClient()
|
||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||
with less_console_noise():
|
||||
application.approve()
|
||||
|
||||
response = self.client.get("/admin/registrar/domain/")
|
||||
|
@ -120,12 +120,12 @@ class TestDomainAdmin(MockEppLib):
|
|||
Then a user-friendly success message is returned for displaying on the web
|
||||
And `state` is et to `DELETED`
|
||||
"""
|
||||
with less_console_noise():
|
||||
domain = create_ready_domain()
|
||||
# Put in client hold
|
||||
domain.place_client_hold()
|
||||
p = "userpass"
|
||||
self.client.login(username="staffuser", password=p)
|
||||
|
||||
# Ensure everything is displaying correctly
|
||||
response = self.client.get(
|
||||
"/admin/registrar/domain/{}/change/".format(domain.pk),
|
||||
|
@ -134,7 +134,6 @@ class TestDomainAdmin(MockEppLib):
|
|||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, domain.name)
|
||||
self.assertContains(response, "Remove from registry")
|
||||
|
||||
# Test the info dialog
|
||||
request = self.factory.post(
|
||||
"/admin/registrar/domain/{}/change/".format(domain.pk),
|
||||
|
@ -142,7 +141,6 @@ class TestDomainAdmin(MockEppLib):
|
|||
follow=True,
|
||||
)
|
||||
request.user = self.client
|
||||
|
||||
with patch("django.contrib.messages.add_message") as mock_add_message:
|
||||
self.admin.do_delete_domain(request, domain)
|
||||
mock_add_message.assert_called_once_with(
|
||||
|
@ -152,7 +150,6 @@ class TestDomainAdmin(MockEppLib):
|
|||
extra_tags="",
|
||||
fail_silently=False,
|
||||
)
|
||||
|
||||
self.assertEqual(domain.state, Domain.State.DELETED)
|
||||
|
||||
def test_deletion_ready_fsm_failure(self):
|
||||
|
@ -162,10 +159,10 @@ class TestDomainAdmin(MockEppLib):
|
|||
Then a user-friendly error message is returned for displaying on the web
|
||||
And `state` is not set to `DELETED`
|
||||
"""
|
||||
with less_console_noise():
|
||||
domain = create_ready_domain()
|
||||
p = "userpass"
|
||||
self.client.login(username="staffuser", password=p)
|
||||
|
||||
# Ensure everything is displaying correctly
|
||||
response = self.client.get(
|
||||
"/admin/registrar/domain/{}/change/".format(domain.pk),
|
||||
|
@ -174,7 +171,6 @@ class TestDomainAdmin(MockEppLib):
|
|||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, domain.name)
|
||||
self.assertContains(response, "Remove from registry")
|
||||
|
||||
# Test the error
|
||||
request = self.factory.post(
|
||||
"/admin/registrar/domain/{}/change/".format(domain.pk),
|
||||
|
@ -182,7 +178,6 @@ class TestDomainAdmin(MockEppLib):
|
|||
follow=True,
|
||||
)
|
||||
request.user = self.client
|
||||
|
||||
with patch("django.contrib.messages.add_message") as mock_add_message:
|
||||
self.admin.do_delete_domain(request, domain)
|
||||
mock_add_message.assert_called_once_with(
|
||||
|
@ -205,12 +200,12 @@ class TestDomainAdmin(MockEppLib):
|
|||
Then `commands.DeleteDomain` is sent to the registry
|
||||
And Domain returns normally without an error dialog
|
||||
"""
|
||||
with less_console_noise():
|
||||
domain = create_ready_domain()
|
||||
# Put in client hold
|
||||
domain.place_client_hold()
|
||||
p = "userpass"
|
||||
self.client.login(username="staffuser", password=p)
|
||||
|
||||
# Ensure everything is displaying correctly
|
||||
response = self.client.get(
|
||||
"/admin/registrar/domain/{}/change/".format(domain.pk),
|
||||
|
@ -219,7 +214,6 @@ class TestDomainAdmin(MockEppLib):
|
|||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, domain.name)
|
||||
self.assertContains(response, "Remove from registry")
|
||||
|
||||
# Test the info dialog
|
||||
request = self.factory.post(
|
||||
"/admin/registrar/domain/{}/change/".format(domain.pk),
|
||||
|
@ -227,7 +221,6 @@ class TestDomainAdmin(MockEppLib):
|
|||
follow=True,
|
||||
)
|
||||
request.user = self.client
|
||||
|
||||
# Delete it once
|
||||
with patch("django.contrib.messages.add_message") as mock_add_message:
|
||||
self.admin.do_delete_domain(request, domain)
|
||||
|
@ -240,7 +233,6 @@ class TestDomainAdmin(MockEppLib):
|
|||
)
|
||||
|
||||
self.assertEqual(domain.state, Domain.State.DELETED)
|
||||
|
||||
# Try to delete it again
|
||||
# Test the info dialog
|
||||
request = self.factory.post(
|
||||
|
@ -249,7 +241,6 @@ class TestDomainAdmin(MockEppLib):
|
|||
follow=True,
|
||||
)
|
||||
request.user = self.client
|
||||
|
||||
with patch("django.contrib.messages.add_message") as mock_add_message:
|
||||
self.admin.do_delete_domain(request, domain)
|
||||
mock_add_message.assert_called_once_with(
|
||||
|
@ -259,7 +250,6 @@ class TestDomainAdmin(MockEppLib):
|
|||
extra_tags="",
|
||||
fail_silently=False,
|
||||
)
|
||||
|
||||
self.assertEqual(domain.state, Domain.State.DELETED)
|
||||
|
||||
@skip("Waiting on epp lib to implement")
|
||||
|
@ -642,6 +632,7 @@ class TestDomainApplicationAdmin(MockEppLib):
|
|||
"creator",
|
||||
"about_your_organization",
|
||||
"requested_domain",
|
||||
"approved_domain",
|
||||
"alternative_domains",
|
||||
"purpose",
|
||||
"submitter",
|
||||
|
@ -1067,7 +1058,7 @@ class DomainInvitationAdminTest(TestCase):
|
|||
self.assertContains(response, retrieved_html, count=1)
|
||||
|
||||
|
||||
class DomainInformationAdminTest(TestCase):
|
||||
class TestDomainInformationAdmin(TestCase):
|
||||
def setUp(self):
|
||||
"""Setup environment for a mock admin user"""
|
||||
self.site = AdminSite()
|
||||
|
@ -1075,6 +1066,7 @@ class DomainInformationAdminTest(TestCase):
|
|||
self.admin = DomainInformationAdmin(model=DomainInformation, admin_site=self.site)
|
||||
self.client = Client(HTTP_HOST="localhost:8080")
|
||||
self.superuser = create_superuser()
|
||||
self.staffuser = create_user()
|
||||
self.mock_data_generator = AuditedAdminMockData()
|
||||
|
||||
self.test_helper = GenericTestHelper(
|
||||
|
@ -1118,6 +1110,27 @@ class DomainInformationAdminTest(TestCase):
|
|||
Contact.objects.all().delete()
|
||||
User.objects.all().delete()
|
||||
|
||||
def test_readonly_fields_for_analyst(self):
|
||||
"""Ensures that analysts have their permissions setup correctly"""
|
||||
request = self.factory.get("/")
|
||||
request.user = self.staffuser
|
||||
|
||||
readonly_fields = self.admin.get_readonly_fields(request)
|
||||
|
||||
expected_fields = [
|
||||
"creator",
|
||||
"type_of_work",
|
||||
"more_organization_information",
|
||||
"domain",
|
||||
"domain_application",
|
||||
"submitter",
|
||||
"no_other_contacts_rationale",
|
||||
"anything_else",
|
||||
"is_policy_acknowledged",
|
||||
]
|
||||
|
||||
self.assertEqual(readonly_fields, expected_fields)
|
||||
|
||||
def test_domain_sortable(self):
|
||||
"""Tests if DomainInformation sorts by domain correctly"""
|
||||
p = "adminpass"
|
||||
|
@ -1282,13 +1295,12 @@ class ListHeaderAdminTest(TestCase):
|
|||
self.superuser = create_superuser()
|
||||
|
||||
def test_changelist_view(self):
|
||||
with less_console_noise():
|
||||
# Have to get creative to get past linter
|
||||
p = "adminpass"
|
||||
self.client.login(username="superuser", password=p)
|
||||
|
||||
# Mock a user
|
||||
user = mock_user()
|
||||
|
||||
# Make the request using the Client class
|
||||
# which handles CSRF
|
||||
# Follow=True handles the redirect
|
||||
|
@ -1301,7 +1313,6 @@ class ListHeaderAdminTest(TestCase):
|
|||
},
|
||||
follow=True,
|
||||
)
|
||||
|
||||
# Assert that the filters and search_query are added to the extra_context
|
||||
self.assertIn("filters", response.context)
|
||||
self.assertIn("search_query", response.context)
|
||||
|
@ -1321,6 +1332,7 @@ class ListHeaderAdminTest(TestCase):
|
|||
)
|
||||
|
||||
def test_get_filters(self):
|
||||
with less_console_noise():
|
||||
# Create a mock request object
|
||||
request = self.factory.get("/admin/yourmodel/")
|
||||
# Set the GET parameters for testing
|
||||
|
@ -1331,7 +1343,6 @@ class ListHeaderAdminTest(TestCase):
|
|||
}
|
||||
# Call the get_filters method
|
||||
filters = self.admin.get_filters(request)
|
||||
|
||||
# Assert the filters extracted from the request GET
|
||||
self.assertEqual(
|
||||
filters,
|
||||
|
@ -1778,9 +1789,8 @@ class ContactAdminTest(TestCase):
|
|||
def test_change_view_for_joined_contact_five_or_more(self):
|
||||
"""Create a contact, join it to 5 domain requests. The 6th join will be a user.
|
||||
Assert that the warning on the contact form lists 5 joins and a '1 more' ellispsis."""
|
||||
|
||||
with less_console_noise():
|
||||
self.client.force_login(self.superuser)
|
||||
|
||||
# Create an instance of the model
|
||||
# join it to 5 domain requests. The 6th join will be a user.
|
||||
contact, _ = Contact.objects.get_or_create(user=self.staffuser)
|
||||
|
@ -1789,13 +1799,10 @@ class ContactAdminTest(TestCase):
|
|||
application3 = completed_application(submitter=contact, name="city3.gov")
|
||||
application4 = completed_application(submitter=contact, name="city4.gov")
|
||||
application5 = completed_application(submitter=contact, name="city5.gov")
|
||||
|
||||
with patch("django.contrib.messages.warning") as mock_warning:
|
||||
# Use the test client to simulate the request
|
||||
response = self.client.get(reverse("admin:registrar_contact_change", args=[contact.pk]))
|
||||
|
||||
logger.info(mock_warning)
|
||||
|
||||
logger.debug(mock_warning)
|
||||
# Assert that the error message was called with the correct argument
|
||||
# Note: The 6th join will be a user.
|
||||
mock_warning.assert_called_once_with(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import copy
|
||||
import datetime
|
||||
from datetime import date, datetime, time
|
||||
from django.utils import timezone
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
|
@ -17,7 +18,7 @@ from django.core.management import call_command
|
|||
from unittest.mock import patch, call
|
||||
from epplibwrapper import commands, common
|
||||
|
||||
from .common import MockEppLib
|
||||
from .common import MockEppLib, less_console_noise
|
||||
|
||||
|
||||
class TestPopulateFirstReady(TestCase):
|
||||
|
@ -33,7 +34,9 @@ class TestPopulateFirstReady(TestCase):
|
|||
self.unknown_domain, _ = Domain.objects.get_or_create(name="fakeunknown.gov", state=Domain.State.UNKNOWN)
|
||||
|
||||
# Set a ready_at date for testing purposes
|
||||
self.ready_at_date = datetime.date(2022, 12, 31)
|
||||
self.ready_at_date = date(2022, 12, 31)
|
||||
_ready_at_datetime = datetime.combine(self.ready_at_date, time.min)
|
||||
self.ready_at_date_tz_aware = timezone.make_aware(_ready_at_datetime, timezone=timezone.utc)
|
||||
|
||||
def tearDown(self):
|
||||
"""Deletes all DB objects related to migrations"""
|
||||
|
@ -49,6 +52,7 @@ class TestPopulateFirstReady(TestCase):
|
|||
The 'call_command' function from Django's management framework is then used to
|
||||
execute the populate_first_ready command with the specified arguments.
|
||||
"""
|
||||
with less_console_noise():
|
||||
with patch(
|
||||
"registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa
|
||||
return_value=True,
|
||||
|
@ -59,19 +63,15 @@ class TestPopulateFirstReady(TestCase):
|
|||
"""
|
||||
Tests that the populate_first_ready works as expected for the state 'ready'
|
||||
"""
|
||||
with less_console_noise():
|
||||
# Set the created at date
|
||||
self.ready_domain.created_at = self.ready_at_date
|
||||
self.ready_domain.created_at = self.ready_at_date_tz_aware
|
||||
self.ready_domain.save()
|
||||
|
||||
desired_domain = copy.deepcopy(self.ready_domain)
|
||||
|
||||
desired_domain.first_ready = self.ready_at_date
|
||||
|
||||
# Run the expiration date script
|
||||
self.run_populate_first_ready()
|
||||
|
||||
self.assertEqual(desired_domain, self.ready_domain)
|
||||
|
||||
# Explicitly test the first_ready date
|
||||
first_ready = Domain.objects.filter(name="fakeready.gov").get().first_ready
|
||||
self.assertEqual(first_ready, self.ready_at_date)
|
||||
|
@ -80,19 +80,15 @@ class TestPopulateFirstReady(TestCase):
|
|||
"""
|
||||
Tests that the populate_first_ready works as expected for the state 'deleted'
|
||||
"""
|
||||
with less_console_noise():
|
||||
# Set the created at date
|
||||
self.deleted_domain.created_at = self.ready_at_date
|
||||
self.deleted_domain.created_at = self.ready_at_date_tz_aware
|
||||
self.deleted_domain.save()
|
||||
|
||||
desired_domain = copy.deepcopy(self.deleted_domain)
|
||||
|
||||
desired_domain.first_ready = self.ready_at_date
|
||||
|
||||
# Run the expiration date script
|
||||
self.run_populate_first_ready()
|
||||
|
||||
self.assertEqual(desired_domain, self.deleted_domain)
|
||||
|
||||
# Explicitly test the first_ready date
|
||||
first_ready = Domain.objects.filter(name="fakedeleted.gov").get().first_ready
|
||||
self.assertEqual(first_ready, self.ready_at_date)
|
||||
|
@ -101,23 +97,18 @@ class TestPopulateFirstReady(TestCase):
|
|||
"""
|
||||
Tests that the populate_first_ready doesn't make changes when a domain's state is 'dns_needed'
|
||||
"""
|
||||
with less_console_noise():
|
||||
# Set the created at date
|
||||
self.dns_needed_domain.created_at = self.ready_at_date
|
||||
self.dns_needed_domain.created_at = self.ready_at_date_tz_aware
|
||||
self.dns_needed_domain.save()
|
||||
|
||||
desired_domain = copy.deepcopy(self.dns_needed_domain)
|
||||
|
||||
desired_domain.first_ready = None
|
||||
|
||||
# Run the expiration date script
|
||||
self.run_populate_first_ready()
|
||||
|
||||
current_domain = self.dns_needed_domain
|
||||
# The object should largely be unaltered (does not test first_ready)
|
||||
self.assertEqual(desired_domain, current_domain)
|
||||
|
||||
first_ready = Domain.objects.filter(name="fakedns.gov").get().first_ready
|
||||
|
||||
# Explicitly test the first_ready date
|
||||
self.assertNotEqual(first_ready, self.ready_at_date)
|
||||
self.assertEqual(first_ready, None)
|
||||
|
@ -126,18 +117,15 @@ class TestPopulateFirstReady(TestCase):
|
|||
"""
|
||||
Tests that the populate_first_ready works as expected for the state 'on_hold'
|
||||
"""
|
||||
self.hold_domain.created_at = self.ready_at_date
|
||||
with less_console_noise():
|
||||
self.hold_domain.created_at = self.ready_at_date_tz_aware
|
||||
self.hold_domain.save()
|
||||
|
||||
desired_domain = copy.deepcopy(self.hold_domain)
|
||||
desired_domain.first_ready = self.ready_at_date
|
||||
|
||||
# Run the update first ready_at script
|
||||
self.run_populate_first_ready()
|
||||
|
||||
current_domain = self.hold_domain
|
||||
self.assertEqual(desired_domain, current_domain)
|
||||
|
||||
# Explicitly test the first_ready date
|
||||
first_ready = Domain.objects.filter(name="fakehold.gov").get().first_ready
|
||||
self.assertEqual(first_ready, self.ready_at_date)
|
||||
|
@ -146,21 +134,17 @@ class TestPopulateFirstReady(TestCase):
|
|||
"""
|
||||
Tests that the populate_first_ready works as expected for the state 'unknown'
|
||||
"""
|
||||
with less_console_noise():
|
||||
# Set the created at date
|
||||
self.unknown_domain.created_at = self.ready_at_date
|
||||
self.unknown_domain.created_at = self.ready_at_date_tz_aware
|
||||
self.unknown_domain.save()
|
||||
|
||||
desired_domain = copy.deepcopy(self.unknown_domain)
|
||||
desired_domain.first_ready = None
|
||||
|
||||
# Run the expiration date script
|
||||
self.run_populate_first_ready()
|
||||
|
||||
current_domain = self.unknown_domain
|
||||
|
||||
# The object should largely be unaltered (does not test first_ready)
|
||||
self.assertEqual(desired_domain, current_domain)
|
||||
|
||||
# Explicitly test the first_ready date
|
||||
first_ready = Domain.objects.filter(name="fakeunknown.gov").get().first_ready
|
||||
self.assertNotEqual(first_ready, self.ready_at_date)
|
||||
|
@ -185,6 +169,7 @@ class TestPatchAgencyInfo(TestCase):
|
|||
@patch("registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", return_value=True)
|
||||
def call_patch_federal_agency_info(self, mock_prompt):
|
||||
"""Calls the patch_federal_agency_info command and mimics a keypress"""
|
||||
with less_console_noise():
|
||||
call_command("patch_federal_agency_info", "registrar/tests/data/fake_current_full.csv", debug=True)
|
||||
|
||||
def test_patch_agency_info(self):
|
||||
|
@ -194,15 +179,12 @@ class TestPatchAgencyInfo(TestCase):
|
|||
of a `DomainInformation` object when the corresponding
|
||||
`TransitionDomain` object has a valid `federal_agency`.
|
||||
"""
|
||||
|
||||
with less_console_noise():
|
||||
# Ensure that the federal_agency is None
|
||||
self.assertEqual(self.domain_info.federal_agency, None)
|
||||
|
||||
self.call_patch_federal_agency_info()
|
||||
|
||||
# Reload the domain_info object from the database
|
||||
self.domain_info.refresh_from_db()
|
||||
|
||||
# Check that the federal_agency field was updated
|
||||
self.assertEqual(self.domain_info.federal_agency, "test agency")
|
||||
|
||||
|
@ -213,19 +195,16 @@ class TestPatchAgencyInfo(TestCase):
|
|||
of a `DomainInformation` object when the corresponding
|
||||
`TransitionDomain` object does not exist.
|
||||
"""
|
||||
with less_console_noise():
|
||||
# Set federal_agency to None to simulate a skip
|
||||
self.transition_domain.federal_agency = None
|
||||
self.transition_domain.save()
|
||||
|
||||
with self.assertLogs("registrar.management.commands.patch_federal_agency_info", level="WARNING") as context:
|
||||
self.call_patch_federal_agency_info()
|
||||
|
||||
# Check that the correct log message was output
|
||||
self.assertIn("SOME AGENCY DATA WAS NONE", context.output[0])
|
||||
|
||||
# Reload the domain_info object from the database
|
||||
self.domain_info.refresh_from_db()
|
||||
|
||||
# Check that the federal_agency field was not updated
|
||||
self.assertIsNone(self.domain_info.federal_agency)
|
||||
|
||||
|
@ -235,23 +214,19 @@ class TestPatchAgencyInfo(TestCase):
|
|||
updates the DomainInformation object, because a record exists in the
|
||||
provided current-full.csv file.
|
||||
"""
|
||||
with less_console_noise():
|
||||
# Set federal_agency to None to simulate a skip
|
||||
self.transition_domain.federal_agency = None
|
||||
self.transition_domain.save()
|
||||
|
||||
# Change the domain name to something parsable in the .csv
|
||||
self.domain.name = "cdomain1.gov"
|
||||
self.domain.save()
|
||||
|
||||
with self.assertLogs("registrar.management.commands.patch_federal_agency_info", level="WARNING") as context:
|
||||
self.call_patch_federal_agency_info()
|
||||
|
||||
# Check that the correct log message was output
|
||||
self.assertIn("SOME AGENCY DATA WAS NONE", context.output[0])
|
||||
|
||||
# Reload the domain_info object from the database
|
||||
self.domain_info.refresh_from_db()
|
||||
|
||||
# Check that the federal_agency field was not updated
|
||||
self.assertEqual(self.domain_info.federal_agency, "World War I Centennial Commission")
|
||||
|
||||
|
@ -261,18 +236,15 @@ class TestPatchAgencyInfo(TestCase):
|
|||
does not update the `federal_agency` field
|
||||
of a `DomainInformation` object
|
||||
"""
|
||||
with less_console_noise():
|
||||
self.domain_info.federal_agency = "unchanged"
|
||||
self.domain_info.save()
|
||||
|
||||
with self.assertLogs("registrar.management.commands.patch_federal_agency_info", level="INFO") as context:
|
||||
self.call_patch_federal_agency_info()
|
||||
|
||||
# Check that the correct log message was output
|
||||
self.assertIn("FINISHED", context.output[1])
|
||||
|
||||
# Reload the domain_info object from the database
|
||||
self.domain_info.refresh_from_db()
|
||||
|
||||
# Check that the federal_agency field was not updated
|
||||
self.assertEqual(self.domain_info.federal_agency, "unchanged")
|
||||
|
||||
|
@ -283,39 +255,37 @@ class TestExtendExpirationDates(MockEppLib):
|
|||
super().setUp()
|
||||
# Create a valid domain that is updatable
|
||||
Domain.objects.get_or_create(
|
||||
name="waterbutpurple.gov", state=Domain.State.READY, expiration_date=datetime.date(2023, 11, 15)
|
||||
name="waterbutpurple.gov", state=Domain.State.READY, expiration_date=date(2023, 11, 15)
|
||||
)
|
||||
TransitionDomain.objects.get_or_create(
|
||||
username="testytester@mail.com",
|
||||
domain_name="waterbutpurple.gov",
|
||||
epp_expiration_date=datetime.date(2023, 11, 15),
|
||||
epp_expiration_date=date(2023, 11, 15),
|
||||
)
|
||||
# Create a domain with an invalid expiration date
|
||||
Domain.objects.get_or_create(
|
||||
name="fake.gov", state=Domain.State.READY, expiration_date=datetime.date(2022, 5, 25)
|
||||
)
|
||||
Domain.objects.get_or_create(name="fake.gov", state=Domain.State.READY, expiration_date=date(2022, 5, 25))
|
||||
TransitionDomain.objects.get_or_create(
|
||||
username="themoonisactuallycheese@mail.com",
|
||||
domain_name="fake.gov",
|
||||
epp_expiration_date=datetime.date(2022, 5, 25),
|
||||
epp_expiration_date=date(2022, 5, 25),
|
||||
)
|
||||
# Create a domain with an invalid state
|
||||
Domain.objects.get_or_create(
|
||||
name="fakeneeded.gov", state=Domain.State.DNS_NEEDED, expiration_date=datetime.date(2023, 11, 15)
|
||||
name="fakeneeded.gov", state=Domain.State.DNS_NEEDED, expiration_date=date(2023, 11, 15)
|
||||
)
|
||||
TransitionDomain.objects.get_or_create(
|
||||
username="fakeneeded@mail.com",
|
||||
domain_name="fakeneeded.gov",
|
||||
epp_expiration_date=datetime.date(2023, 11, 15),
|
||||
epp_expiration_date=date(2023, 11, 15),
|
||||
)
|
||||
# Create a domain with a date greater than the maximum
|
||||
Domain.objects.get_or_create(
|
||||
name="fakemaximum.gov", state=Domain.State.READY, expiration_date=datetime.date(2024, 12, 31)
|
||||
name="fakemaximum.gov", state=Domain.State.READY, expiration_date=date(2024, 12, 31)
|
||||
)
|
||||
TransitionDomain.objects.get_or_create(
|
||||
username="fakemaximum@mail.com",
|
||||
domain_name="fakemaximum.gov",
|
||||
epp_expiration_date=datetime.date(2024, 12, 31),
|
||||
epp_expiration_date=date(2024, 12, 31),
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
|
@ -338,6 +308,7 @@ class TestExtendExpirationDates(MockEppLib):
|
|||
The 'call_command' function from Django's management framework is then used to
|
||||
execute the extend_expiration_dates command with the specified arguments.
|
||||
"""
|
||||
with less_console_noise():
|
||||
with patch(
|
||||
"registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa
|
||||
return_value=True,
|
||||
|
@ -348,44 +319,41 @@ class TestExtendExpirationDates(MockEppLib):
|
|||
"""
|
||||
Tests that the extend_expiration_dates method extends dates as expected
|
||||
"""
|
||||
with less_console_noise():
|
||||
desired_domain = Domain.objects.filter(name="waterbutpurple.gov").get()
|
||||
desired_domain.expiration_date = datetime.date(2024, 11, 15)
|
||||
|
||||
desired_domain.expiration_date = date(2024, 11, 15)
|
||||
# Run the expiration date script
|
||||
self.run_extend_expiration_dates()
|
||||
|
||||
current_domain = Domain.objects.filter(name="waterbutpurple.gov").get()
|
||||
|
||||
self.assertEqual(desired_domain, current_domain)
|
||||
# Explicitly test the expiration date
|
||||
self.assertEqual(current_domain.expiration_date, datetime.date(2024, 11, 15))
|
||||
self.assertEqual(current_domain.expiration_date, date(2024, 11, 15))
|
||||
|
||||
def test_extends_expiration_date_skips_non_current(self):
|
||||
"""
|
||||
Tests that the extend_expiration_dates method correctly skips domains
|
||||
with an expiration date less than a certain threshold.
|
||||
"""
|
||||
with less_console_noise():
|
||||
desired_domain = Domain.objects.filter(name="fake.gov").get()
|
||||
desired_domain.expiration_date = datetime.date(2022, 5, 25)
|
||||
|
||||
desired_domain.expiration_date = date(2022, 5, 25)
|
||||
# Run the expiration date script
|
||||
self.run_extend_expiration_dates()
|
||||
|
||||
current_domain = Domain.objects.filter(name="fake.gov").get()
|
||||
self.assertEqual(desired_domain, current_domain)
|
||||
|
||||
# Explicitly test the expiration date. The extend_expiration_dates script
|
||||
# will skip all dates less than date(2023, 11, 15), meaning that this domain
|
||||
# should not be affected by the change.
|
||||
self.assertEqual(current_domain.expiration_date, datetime.date(2022, 5, 25))
|
||||
self.assertEqual(current_domain.expiration_date, date(2022, 5, 25))
|
||||
|
||||
def test_extends_expiration_date_skips_maximum_date(self):
|
||||
"""
|
||||
Tests that the extend_expiration_dates method correctly skips domains
|
||||
with an expiration date more than a certain threshold.
|
||||
"""
|
||||
with less_console_noise():
|
||||
desired_domain = Domain.objects.filter(name="fakemaximum.gov").get()
|
||||
desired_domain.expiration_date = datetime.date(2024, 12, 31)
|
||||
desired_domain.expiration_date = date(2024, 12, 31)
|
||||
|
||||
# Run the expiration date script
|
||||
self.run_extend_expiration_dates()
|
||||
|
@ -396,14 +364,15 @@ class TestExtendExpirationDates(MockEppLib):
|
|||
# Explicitly test the expiration date. The extend_expiration_dates script
|
||||
# will skip all dates less than date(2023, 11, 15), meaning that this domain
|
||||
# should not be affected by the change.
|
||||
self.assertEqual(current_domain.expiration_date, datetime.date(2024, 12, 31))
|
||||
self.assertEqual(current_domain.expiration_date, date(2024, 12, 31))
|
||||
|
||||
def test_extends_expiration_date_skips_non_ready(self):
|
||||
"""
|
||||
Tests that the extend_expiration_dates method correctly skips domains not in the state "ready"
|
||||
"""
|
||||
with less_console_noise():
|
||||
desired_domain = Domain.objects.filter(name="fakeneeded.gov").get()
|
||||
desired_domain.expiration_date = datetime.date(2023, 11, 15)
|
||||
desired_domain.expiration_date = date(2023, 11, 15)
|
||||
|
||||
# Run the expiration date script
|
||||
self.run_extend_expiration_dates()
|
||||
|
@ -414,7 +383,7 @@ class TestExtendExpirationDates(MockEppLib):
|
|||
# Explicitly test the expiration date. The extend_expiration_dates script
|
||||
# will skip all dates less than date(2023, 11, 15), meaning that this domain
|
||||
# should not be affected by the change.
|
||||
self.assertEqual(current_domain.expiration_date, datetime.date(2023, 11, 15))
|
||||
self.assertEqual(current_domain.expiration_date, date(2023, 11, 15))
|
||||
|
||||
def test_extends_expiration_date_idempotent(self):
|
||||
"""
|
||||
|
@ -423,26 +392,21 @@ class TestExtendExpirationDates(MockEppLib):
|
|||
Verifies that running the method multiple times does not change the expiration date
|
||||
of a domain beyond the initial extension.
|
||||
"""
|
||||
with less_console_noise():
|
||||
desired_domain = Domain.objects.filter(name="waterbutpurple.gov").get()
|
||||
desired_domain.expiration_date = datetime.date(2024, 11, 15)
|
||||
|
||||
desired_domain.expiration_date = date(2024, 11, 15)
|
||||
# Run the expiration date script
|
||||
self.run_extend_expiration_dates()
|
||||
|
||||
current_domain = Domain.objects.filter(name="waterbutpurple.gov").get()
|
||||
self.assertEqual(desired_domain, current_domain)
|
||||
|
||||
# Explicitly test the expiration date
|
||||
self.assertEqual(desired_domain.expiration_date, datetime.date(2024, 11, 15))
|
||||
|
||||
self.assertEqual(desired_domain.expiration_date, date(2024, 11, 15))
|
||||
# Run the expiration date script again
|
||||
self.run_extend_expiration_dates()
|
||||
|
||||
# The old domain shouldn't have changed
|
||||
self.assertEqual(desired_domain, current_domain)
|
||||
|
||||
# Explicitly test the expiration date - should be the same
|
||||
self.assertEqual(desired_domain.expiration_date, datetime.date(2024, 11, 15))
|
||||
self.assertEqual(desired_domain.expiration_date, date(2024, 11, 15))
|
||||
|
||||
|
||||
class TestDiscloseEmails(MockEppLib):
|
||||
|
@ -461,6 +425,7 @@ class TestDiscloseEmails(MockEppLib):
|
|||
The 'call_command' function from Django's management framework is then used to
|
||||
execute the disclose_security_emails command.
|
||||
"""
|
||||
with less_console_noise():
|
||||
with patch(
|
||||
"registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa
|
||||
return_value=True,
|
||||
|
@ -472,6 +437,7 @@ class TestDiscloseEmails(MockEppLib):
|
|||
Tests that command disclose_security_emails runs successfully with
|
||||
appropriate EPP calll to UpdateContact.
|
||||
"""
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="testdisclose.gov", state=Domain.State.READY)
|
||||
expectedSecContact = PublicContact.get_default_security()
|
||||
expectedSecContact.domain = domain
|
||||
|
|
|
@ -60,23 +60,27 @@ class TestDomainApplication(TestCase):
|
|||
|
||||
def assertNotRaises(self, exception_type):
|
||||
"""Helper method for testing allowed transitions."""
|
||||
with less_console_noise():
|
||||
return self.assertRaises(Exception, None, exception_type)
|
||||
|
||||
def test_empty_create_fails(self):
|
||||
"""Can't create a completely empty domain application.
|
||||
NOTE: something about theexception this test raises messes up with the
|
||||
atomic block in a custom tearDown method for the parent test class."""
|
||||
with less_console_noise():
|
||||
with self.assertRaisesRegex(IntegrityError, "creator"):
|
||||
DomainApplication.objects.create()
|
||||
|
||||
def test_minimal_create(self):
|
||||
"""Can create with just a creator."""
|
||||
with less_console_noise():
|
||||
user, _ = User.objects.get_or_create(username="testy")
|
||||
application = DomainApplication.objects.create(creator=user)
|
||||
self.assertEqual(application.status, DomainApplication.ApplicationStatus.STARTED)
|
||||
|
||||
def test_full_create(self):
|
||||
"""Can create with all fields."""
|
||||
with less_console_noise():
|
||||
user, _ = User.objects.get_or_create(username="testy")
|
||||
contact = Contact.objects.create()
|
||||
com_website, _ = Website.objects.get_or_create(website="igorville.com")
|
||||
|
@ -107,6 +111,7 @@ class TestDomainApplication(TestCase):
|
|||
|
||||
def test_domain_info(self):
|
||||
"""Can create domain info with all fields."""
|
||||
with less_console_noise():
|
||||
user, _ = User.objects.get_or_create(username="testy")
|
||||
contact = Contact.objects.create()
|
||||
domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
||||
|
@ -133,6 +138,7 @@ class TestDomainApplication(TestCase):
|
|||
self.assertEqual(information.id, domain.domain_info.id)
|
||||
|
||||
def test_status_fsm_submit_fail(self):
|
||||
with less_console_noise():
|
||||
user, _ = User.objects.get_or_create(username="testy")
|
||||
application = DomainApplication.objects.create(creator=user)
|
||||
|
||||
|
@ -143,6 +149,7 @@ class TestDomainApplication(TestCase):
|
|||
application.submit()
|
||||
|
||||
def test_status_fsm_submit_succeed(self):
|
||||
with less_console_noise():
|
||||
user, _ = User.objects.get_or_create(username="testy")
|
||||
site = DraftDomain.objects.create(name="igorville.gov")
|
||||
application = DomainApplication.objects.create(creator=user, requested_domain=site)
|
||||
|
@ -156,6 +163,7 @@ class TestDomainApplication(TestCase):
|
|||
|
||||
def test_submit_sends_email(self):
|
||||
"""Create an application and submit it and see if email was sent."""
|
||||
with less_console_noise():
|
||||
user, _ = User.objects.get_or_create(username="testy")
|
||||
contact = Contact.objects.create(email="test@test.gov")
|
||||
domain, _ = DraftDomain.objects.get_or_create(name="igorville.gov")
|
||||
|
@ -167,7 +175,6 @@ class TestDomainApplication(TestCase):
|
|||
application.save()
|
||||
|
||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
|
||||
with less_console_noise():
|
||||
application.submit()
|
||||
|
||||
# check to see if an email was sent
|
||||
|
@ -268,7 +275,7 @@ class TestDomainApplication(TestCase):
|
|||
(self.rejected_application, TransitionNotAllowed),
|
||||
(self.ineligible_application, TransitionNotAllowed),
|
||||
]
|
||||
|
||||
with less_console_noise():
|
||||
for application, exception_type in test_cases:
|
||||
with self.subTest(application=application, exception_type=exception_type):
|
||||
try:
|
||||
|
@ -286,7 +293,7 @@ class TestDomainApplication(TestCase):
|
|||
(self.action_needed_application, TransitionNotAllowed),
|
||||
(self.withdrawn_application, TransitionNotAllowed),
|
||||
]
|
||||
|
||||
with less_console_noise():
|
||||
for application, exception_type in test_cases:
|
||||
with self.subTest(application=application, exception_type=exception_type):
|
||||
with self.assertRaises(exception_type):
|
||||
|
@ -499,21 +506,25 @@ class TestDomainApplication(TestCase):
|
|||
|
||||
def test_has_rationale_returns_true(self):
|
||||
"""has_rationale() returns true when an application has no_other_contacts_rationale"""
|
||||
with less_console_noise():
|
||||
self.started_application.no_other_contacts_rationale = "You talkin' to me?"
|
||||
self.started_application.save()
|
||||
self.assertEquals(self.started_application.has_rationale(), True)
|
||||
|
||||
def test_has_rationale_returns_false(self):
|
||||
"""has_rationale() returns false when an application has no no_other_contacts_rationale"""
|
||||
with less_console_noise():
|
||||
self.assertEquals(self.started_application.has_rationale(), False)
|
||||
|
||||
def test_has_other_contacts_returns_true(self):
|
||||
"""has_other_contacts() returns true when an application has other_contacts"""
|
||||
with less_console_noise():
|
||||
# completed_application has other contacts by default
|
||||
self.assertEquals(self.started_application.has_other_contacts(), True)
|
||||
|
||||
def test_has_other_contacts_returns_false(self):
|
||||
"""has_other_contacts() returns false when an application has no other_contacts"""
|
||||
with less_console_noise():
|
||||
application = completed_application(
|
||||
status=DomainApplication.ApplicationStatus.STARTED, name="no-others.gov", has_other_contacts=False
|
||||
)
|
||||
|
|
|
@ -7,6 +7,7 @@ from django.test import TestCase
|
|||
from django.db.utils import IntegrityError
|
||||
from unittest.mock import MagicMock, patch, call
|
||||
import datetime
|
||||
from django.utils.timezone import make_aware
|
||||
from registrar.models import Domain, Host, HostIP
|
||||
|
||||
from unittest import skip
|
||||
|
@ -46,6 +47,7 @@ class TestDomainCache(MockEppLib):
|
|||
|
||||
def test_cache_sets_resets(self):
|
||||
"""Cache should be set on getter and reset on setter calls"""
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
||||
# trigger getter
|
||||
_ = domain.creation_date
|
||||
|
@ -75,6 +77,7 @@ class TestDomainCache(MockEppLib):
|
|||
|
||||
def test_cache_used_when_avail(self):
|
||||
"""Cache is pulled from if the object has already been accessed"""
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
||||
cr_date = domain.creation_date
|
||||
|
||||
|
@ -94,6 +97,7 @@ class TestDomainCache(MockEppLib):
|
|||
|
||||
def test_cache_nested_elements(self):
|
||||
"""Cache works correctly with the nested objects cache and hosts"""
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
||||
# The contact list will initially contain objects of type 'DomainContact'
|
||||
# this is then transformed into PublicContact, and cache should NOT
|
||||
|
@ -144,6 +148,7 @@ class TestDomainCache(MockEppLib):
|
|||
|
||||
def test_map_epp_contact_to_public_contact(self):
|
||||
# Tests that the mapper is working how we expect
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="registry.gov")
|
||||
security = PublicContact.ContactTypeChoices.SECURITY
|
||||
mapped = domain.map_epp_contact_to_public_contact(
|
||||
|
@ -206,6 +211,7 @@ class TestDomainCache(MockEppLib):
|
|||
gets invalid data from EPPLib
|
||||
Then the function throws the expected ContactErrors
|
||||
"""
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="registry.gov")
|
||||
fakedEpp = self.fakedEppObject()
|
||||
invalid_length = fakedEpp.dummyInfoContactResultData(
|
||||
|
@ -346,6 +352,7 @@ class TestDomainStatuses(MockEppLib):
|
|||
|
||||
def test_get_status(self):
|
||||
"""Domain 'statuses' getter returns statuses by calling epp"""
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="chicken-liver.gov")
|
||||
# trigger getter
|
||||
_ = domain.statuses
|
||||
|
@ -365,6 +372,7 @@ class TestDomainStatuses(MockEppLib):
|
|||
def test_get_status_returns_empty_list_when_value_error(self):
|
||||
"""Domain 'statuses' getter returns an empty list
|
||||
when value error"""
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="pig-knuckles.gov")
|
||||
|
||||
def side_effect(self):
|
||||
|
@ -398,26 +406,21 @@ class TestDomainStatuses(MockEppLib):
|
|||
first_ready is set when a domain is first transitioned to READY. It does not get overwritten
|
||||
in case the domain gets out of and back into READY.
|
||||
"""
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="pig-knuckles.gov", state=Domain.State.DNS_NEEDED)
|
||||
self.assertEqual(domain.first_ready, None)
|
||||
|
||||
domain.ready()
|
||||
|
||||
# check that status is READY
|
||||
self.assertTrue(domain.is_active())
|
||||
self.assertNotEqual(domain.first_ready, None)
|
||||
|
||||
# Capture the value of first_ready
|
||||
first_ready = domain.first_ready
|
||||
|
||||
# change domain status
|
||||
domain.dns_needed()
|
||||
self.assertFalse(domain.is_active())
|
||||
|
||||
# change back to READY
|
||||
domain.ready()
|
||||
self.assertTrue(domain.is_active())
|
||||
|
||||
# assert that the value of first_ready has not changed
|
||||
self.assertEqual(domain.first_ready, first_ready)
|
||||
|
||||
|
@ -557,13 +560,11 @@ class TestRegistrantContacts(MockEppLib):
|
|||
Then the domain has a valid security contact with CISA defaults
|
||||
And disclose flags are set to keep the email address hidden
|
||||
"""
|
||||
|
||||
with less_console_noise():
|
||||
# making a domain should make it domain
|
||||
expectedSecContact = PublicContact.get_default_security()
|
||||
expectedSecContact.domain = self.domain
|
||||
|
||||
self.domain.dns_needed_from_unknown()
|
||||
|
||||
self.assertEqual(self.mockedSendFunction.call_count, 8)
|
||||
self.assertEqual(PublicContact.objects.filter(domain=self.domain).count(), 4)
|
||||
self.assertEqual(
|
||||
|
@ -573,19 +574,16 @@ class TestRegistrantContacts(MockEppLib):
|
|||
).email,
|
||||
expectedSecContact.email,
|
||||
)
|
||||
|
||||
id = PublicContact.objects.get(
|
||||
domain=self.domain,
|
||||
contact_type=PublicContact.ContactTypeChoices.SECURITY,
|
||||
).registry_id
|
||||
|
||||
expectedSecContact.registry_id = id
|
||||
expectedCreateCommand = self._convertPublicContactToEpp(expectedSecContact, disclose_email=False)
|
||||
expectedUpdateDomain = commands.UpdateDomain(
|
||||
name=self.domain.name,
|
||||
add=[common.DomainContact(contact=expectedSecContact.registry_id, type="security")],
|
||||
)
|
||||
|
||||
self.mockedSendFunction.assert_any_call(expectedCreateCommand, cleaned=True)
|
||||
self.mockedSendFunction.assert_any_call(expectedUpdateDomain, cleaned=True)
|
||||
|
||||
|
@ -598,6 +596,7 @@ class TestRegistrantContacts(MockEppLib):
|
|||
And Domain sends `commands.UpdateDomain` to the registry with the newly
|
||||
created contact of type 'security'
|
||||
"""
|
||||
with less_console_noise():
|
||||
# make a security contact that is a PublicContact
|
||||
# make sure a security email already exists
|
||||
self.domain.dns_needed_from_unknown()
|
||||
|
@ -606,24 +605,19 @@ class TestRegistrantContacts(MockEppLib):
|
|||
expectedSecContact.email = "newEmail@fake.com"
|
||||
expectedSecContact.registry_id = "456"
|
||||
expectedSecContact.name = "Fakey McFakerson"
|
||||
|
||||
# calls the security contact setter as if you did
|
||||
# self.domain.security_contact=expectedSecContact
|
||||
expectedSecContact.save()
|
||||
|
||||
# no longer the default email it should be disclosed
|
||||
expectedCreateCommand = self._convertPublicContactToEpp(expectedSecContact, disclose_email=True)
|
||||
|
||||
expectedUpdateDomain = commands.UpdateDomain(
|
||||
name=self.domain.name,
|
||||
add=[common.DomainContact(contact=expectedSecContact.registry_id, type="security")],
|
||||
)
|
||||
|
||||
# check that send has triggered the create command for the contact
|
||||
receivedSecurityContact = PublicContact.objects.get(
|
||||
domain=self.domain, contact_type=PublicContact.ContactTypeChoices.SECURITY
|
||||
)
|
||||
|
||||
self.assertEqual(receivedSecurityContact, expectedSecContact)
|
||||
self.mockedSendFunction.assert_any_call(expectedCreateCommand, cleaned=True)
|
||||
self.mockedSendFunction.assert_any_call(expectedUpdateDomain, cleaned=True)
|
||||
|
@ -635,15 +629,12 @@ class TestRegistrantContacts(MockEppLib):
|
|||
to the registry twice with identical data
|
||||
Then no errors are raised in Domain
|
||||
"""
|
||||
|
||||
with less_console_noise():
|
||||
security_contact = self.domain.get_default_security_contact()
|
||||
security_contact.registry_id = "fail"
|
||||
security_contact.save()
|
||||
|
||||
self.domain.security_contact = security_contact
|
||||
|
||||
expectedCreateCommand = self._convertPublicContactToEpp(security_contact, disclose_email=False)
|
||||
|
||||
expectedUpdateDomain = commands.UpdateDomain(
|
||||
name=self.domain.name,
|
||||
add=[common.DomainContact(contact=security_contact.registry_id, type="security")],
|
||||
|
@ -667,8 +658,8 @@ class TestRegistrantContacts(MockEppLib):
|
|||
And the domain has a valid security contact with CISA defaults
|
||||
And disclose flags are set to keep the email address hidden
|
||||
"""
|
||||
with less_console_noise():
|
||||
old_contact = self.domain.get_default_security_contact()
|
||||
|
||||
old_contact.registry_id = "fail"
|
||||
old_contact.email = "user.entered@email.com"
|
||||
old_contact.save()
|
||||
|
@ -676,7 +667,6 @@ class TestRegistrantContacts(MockEppLib):
|
|||
new_contact.registry_id = "fail"
|
||||
new_contact.email = ""
|
||||
self.domain.security_contact = new_contact
|
||||
|
||||
firstCreateContactCall = self._convertPublicContactToEpp(old_contact, disclose_email=True)
|
||||
updateDomainAddCall = commands.UpdateDomain(
|
||||
name=self.domain.name,
|
||||
|
@ -692,7 +682,6 @@ class TestRegistrantContacts(MockEppLib):
|
|||
name=self.domain.name,
|
||||
rem=[common.DomainContact(contact=old_contact.registry_id, type="security")],
|
||||
)
|
||||
|
||||
defaultSecID = PublicContact.objects.filter(domain=self.domain).get().registry_id
|
||||
default_security = PublicContact.get_default_security()
|
||||
default_security.registry_id = defaultSecID
|
||||
|
@ -701,7 +690,6 @@ class TestRegistrantContacts(MockEppLib):
|
|||
name=self.domain.name,
|
||||
add=[common.DomainContact(contact=defaultSecID, type="security")],
|
||||
)
|
||||
|
||||
expected_calls = [
|
||||
call(firstCreateContactCall, cleaned=True),
|
||||
call(updateDomainAddCall, cleaned=True),
|
||||
|
@ -710,7 +698,6 @@ class TestRegistrantContacts(MockEppLib):
|
|||
call(createDefaultContact, cleaned=True),
|
||||
call(updateDomainWDefault, cleaned=True),
|
||||
]
|
||||
|
||||
self.mockedSendFunction.assert_has_calls(expected_calls, any_order=True)
|
||||
|
||||
def test_updates_security_email(self):
|
||||
|
@ -721,12 +708,12 @@ class TestRegistrantContacts(MockEppLib):
|
|||
security contact email
|
||||
Then Domain sends `commands.UpdateContact` to the registry
|
||||
"""
|
||||
with less_console_noise():
|
||||
security_contact = self.domain.get_default_security_contact()
|
||||
security_contact.email = "originalUserEmail@gmail.com"
|
||||
security_contact.registry_id = "fail"
|
||||
security_contact.save()
|
||||
expectedCreateCommand = self._convertPublicContactToEpp(security_contact, disclose_email=True)
|
||||
|
||||
expectedUpdateDomain = commands.UpdateDomain(
|
||||
name=self.domain.name,
|
||||
add=[common.DomainContact(contact=security_contact.registry_id, type="security")],
|
||||
|
@ -735,7 +722,6 @@ class TestRegistrantContacts(MockEppLib):
|
|||
security_contact.save()
|
||||
expectedSecondCreateCommand = self._convertPublicContactToEpp(security_contact, disclose_email=True)
|
||||
updateContact = self._convertPublicContactToEpp(security_contact, disclose_email=True, createContact=False)
|
||||
|
||||
expected_calls = [
|
||||
call(expectedCreateCommand, cleaned=True),
|
||||
call(expectedUpdateDomain, cleaned=True),
|
||||
|
@ -751,8 +737,8 @@ class TestRegistrantContacts(MockEppLib):
|
|||
Registry is unavailable and throws exception when attempting to build cache from
|
||||
registry. Security email retrieved from database.
|
||||
"""
|
||||
with less_console_noise():
|
||||
# Use self.domain_contact which has been initialized with existing contacts, including securityContact
|
||||
|
||||
# call get_security_email to initially set the security_contact_registry_id in the domain model
|
||||
self.domain_contact.get_security_email()
|
||||
# invalidate the cache so the next time get_security_email is called, it has to attempt to populate cache
|
||||
|
@ -765,11 +751,9 @@ class TestRegistrantContacts(MockEppLib):
|
|||
patcher = patch("registrar.models.domain.registry.send")
|
||||
mocked_send = patcher.start()
|
||||
mocked_send.side_effect = side_effect
|
||||
|
||||
# when get_security_email is called, the registry error will force the security contact
|
||||
# to be retrieved using the security_contact_registry_id in the domain model
|
||||
security_email = self.domain_contact.get_security_email()
|
||||
|
||||
# assert that the proper security contact was retrieved by testing the email matches expected value
|
||||
self.assertEqual(security_email, "security@mail.gov")
|
||||
patcher.stop()
|
||||
|
@ -781,6 +765,7 @@ class TestRegistrantContacts(MockEppLib):
|
|||
The mocked data for the EPP calls for the freeman.gov domain returns a security
|
||||
contact with registry id of securityContact when InfoContact is called
|
||||
"""
|
||||
with less_console_noise():
|
||||
# Use self.domain_contact which has been initialized with existing contacts, including securityContact
|
||||
|
||||
# force fetch_cache to be called, which will return above documented mocked hosts
|
||||
|
@ -798,54 +783,45 @@ class TestRegistrantContacts(MockEppLib):
|
|||
And the field `disclose` is set to false for DF.EMAIL
|
||||
on all fields except security
|
||||
"""
|
||||
with less_console_noise():
|
||||
# Generates a domain with four existing contacts
|
||||
domain, _ = Domain.objects.get_or_create(name="freeman.gov")
|
||||
|
||||
# Contact setup
|
||||
expected_admin = domain.get_default_administrative_contact()
|
||||
expected_admin.email = self.mockAdministrativeContact.email
|
||||
|
||||
expected_registrant = domain.get_default_registrant_contact()
|
||||
expected_registrant.email = self.mockRegistrantContact.email
|
||||
|
||||
expected_security = domain.get_default_security_contact()
|
||||
expected_security.email = self.mockSecurityContact.email
|
||||
|
||||
expected_tech = domain.get_default_technical_contact()
|
||||
expected_tech.email = self.mockTechnicalContact.email
|
||||
|
||||
domain.administrative_contact = expected_admin
|
||||
domain.registrant_contact = expected_registrant
|
||||
domain.security_contact = expected_security
|
||||
domain.technical_contact = expected_tech
|
||||
|
||||
contacts = [
|
||||
(expected_admin, domain.administrative_contact),
|
||||
(expected_registrant, domain.registrant_contact),
|
||||
(expected_security, domain.security_contact),
|
||||
(expected_tech, domain.technical_contact),
|
||||
]
|
||||
|
||||
# Test for each contact
|
||||
for contact in contacts:
|
||||
expected_contact = contact[0]
|
||||
actual_contact = contact[1]
|
||||
is_security = expected_contact.contact_type == "security"
|
||||
|
||||
expectedCreateCommand = self._convertPublicContactToEpp(expected_contact, disclose_email=is_security)
|
||||
|
||||
# Should only be disclosed if the type is security, as the email is valid
|
||||
self.mockedSendFunction.assert_any_call(expectedCreateCommand, cleaned=True)
|
||||
|
||||
# The emails should match on both items
|
||||
self.assertEqual(expected_contact.email, actual_contact.email)
|
||||
|
||||
def test_convert_public_contact_to_epp(self):
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="freeman.gov")
|
||||
dummy_contact = domain.get_default_security_contact()
|
||||
test_disclose = self._convertPublicContactToEpp(dummy_contact, disclose_email=True).__dict__
|
||||
test_not_disclose = self._convertPublicContactToEpp(dummy_contact, disclose_email=False).__dict__
|
||||
|
||||
# Separated for linter
|
||||
disclose_email_field = {common.DiscloseField.EMAIL}
|
||||
expected_disclose = {
|
||||
|
@ -872,7 +848,6 @@ class TestRegistrantContacts(MockEppLib):
|
|||
"vat": None,
|
||||
"voice": "+1.8882820870",
|
||||
}
|
||||
|
||||
# Separated for linter
|
||||
expected_not_disclose = {
|
||||
"auth_info": common.ContactAuthInfo(pw="2fooBAR123fooBaz"),
|
||||
|
@ -898,11 +873,9 @@ class TestRegistrantContacts(MockEppLib):
|
|||
"vat": None,
|
||||
"voice": "+1.8882820870",
|
||||
}
|
||||
|
||||
# Set the ids equal, since this value changes
|
||||
test_disclose["id"] = expected_disclose["id"]
|
||||
test_not_disclose["id"] = expected_not_disclose["id"]
|
||||
|
||||
self.assertEqual(test_disclose, expected_disclose)
|
||||
self.assertEqual(test_not_disclose, expected_not_disclose)
|
||||
|
||||
|
@ -913,14 +886,13 @@ class TestRegistrantContacts(MockEppLib):
|
|||
Then Domain sends `commands.CreateContact` to the registry
|
||||
And the field `disclose` is set to false for DF.EMAIL
|
||||
"""
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="defaultsecurity.gov")
|
||||
expectedSecContact = PublicContact.get_default_security()
|
||||
expectedSecContact.domain = domain
|
||||
expectedSecContact.registry_id = "defaultSec"
|
||||
domain.security_contact = expectedSecContact
|
||||
|
||||
expectedCreateCommand = self._convertPublicContactToEpp(expectedSecContact, disclose_email=False)
|
||||
|
||||
self.mockedSendFunction.assert_any_call(expectedCreateCommand, cleaned=True)
|
||||
# Confirm that we are getting a default email
|
||||
self.assertEqual(domain.security_contact.email, expectedSecContact.email)
|
||||
|
@ -932,14 +904,13 @@ class TestRegistrantContacts(MockEppLib):
|
|||
Then Domain sends `commands.CreateContact` to the registry
|
||||
And the field `disclose` is set to false for DF.EMAIL
|
||||
"""
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="defaulttechnical.gov")
|
||||
expectedTechContact = PublicContact.get_default_technical()
|
||||
expectedTechContact.domain = domain
|
||||
expectedTechContact.registry_id = "defaultTech"
|
||||
domain.technical_contact = expectedTechContact
|
||||
|
||||
expectedCreateCommand = self._convertPublicContactToEpp(expectedTechContact, disclose_email=False)
|
||||
|
||||
self.mockedSendFunction.assert_any_call(expectedCreateCommand, cleaned=True)
|
||||
# Confirm that we are getting a default email
|
||||
self.assertEqual(domain.technical_contact.email, expectedTechContact.email)
|
||||
|
@ -952,14 +923,13 @@ class TestRegistrantContacts(MockEppLib):
|
|||
Then Domain sends `commands.CreateContact` to the registry
|
||||
And the field `disclose` is set to true for DF.EMAIL
|
||||
"""
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
||||
expectedSecContact = PublicContact.get_default_security()
|
||||
expectedSecContact.domain = domain
|
||||
expectedSecContact.email = "123@mail.gov"
|
||||
domain.security_contact = expectedSecContact
|
||||
|
||||
expectedCreateCommand = self._convertPublicContactToEpp(expectedSecContact, disclose_email=True)
|
||||
|
||||
self.mockedSendFunction.assert_any_call(expectedCreateCommand, cleaned=True)
|
||||
# Confirm that we are getting the desired email
|
||||
self.assertEqual(domain.security_contact.email, expectedSecContact.email)
|
||||
|
@ -974,6 +944,7 @@ class TestRegistrantContacts(MockEppLib):
|
|||
raise
|
||||
|
||||
def test_contact_getter_security(self):
|
||||
with less_console_noise():
|
||||
security = PublicContact.ContactTypeChoices.SECURITY
|
||||
# Create prexisting object
|
||||
expected_contact = self.domain.map_epp_contact_to_public_contact(
|
||||
|
@ -981,17 +952,13 @@ class TestRegistrantContacts(MockEppLib):
|
|||
contact_id="securityContact",
|
||||
contact_type=security,
|
||||
)
|
||||
|
||||
# Checks if we grabbed the correct PublicContact
|
||||
self.assertEqual(self.domain_contact.security_contact.email, expected_contact.email)
|
||||
|
||||
expected_contact_db = PublicContact.objects.filter(
|
||||
registry_id=self.domain_contact.security_contact.registry_id,
|
||||
contact_type=security,
|
||||
).get()
|
||||
|
||||
self.assertEqual(self.domain_contact.security_contact, expected_contact_db)
|
||||
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
[
|
||||
call(
|
||||
|
@ -1005,21 +972,19 @@ class TestRegistrantContacts(MockEppLib):
|
|||
self.assertEqual(cache.get(security), "securityContact")
|
||||
|
||||
def test_contact_getter_technical(self):
|
||||
with less_console_noise():
|
||||
technical = PublicContact.ContactTypeChoices.TECHNICAL
|
||||
expected_contact = self.domain.map_epp_contact_to_public_contact(
|
||||
self.mockTechnicalContact,
|
||||
contact_id="technicalContact",
|
||||
contact_type=technical,
|
||||
)
|
||||
|
||||
self.assertEqual(self.domain_contact.technical_contact.email, expected_contact.email)
|
||||
|
||||
# Checks if we grab the correct PublicContact
|
||||
expected_contact_db = PublicContact.objects.filter(
|
||||
registry_id=self.domain_contact.technical_contact.registry_id,
|
||||
contact_type=technical,
|
||||
).get()
|
||||
|
||||
# Checks if we grab the correct PublicContact
|
||||
self.assertEqual(self.domain_contact.technical_contact, expected_contact_db)
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
|
@ -1035,20 +1000,18 @@ class TestRegistrantContacts(MockEppLib):
|
|||
self.assertEqual(cache.get(technical), "technicalContact")
|
||||
|
||||
def test_contact_getter_administrative(self):
|
||||
with less_console_noise():
|
||||
administrative = PublicContact.ContactTypeChoices.ADMINISTRATIVE
|
||||
expected_contact = self.domain.map_epp_contact_to_public_contact(
|
||||
self.mockAdministrativeContact,
|
||||
contact_id="adminContact",
|
||||
contact_type=administrative,
|
||||
)
|
||||
|
||||
self.assertEqual(self.domain_contact.administrative_contact.email, expected_contact.email)
|
||||
|
||||
expected_contact_db = PublicContact.objects.filter(
|
||||
registry_id=self.domain_contact.administrative_contact.registry_id,
|
||||
contact_type=administrative,
|
||||
).get()
|
||||
|
||||
# Checks if we grab the correct PublicContact
|
||||
self.assertEqual(self.domain_contact.administrative_contact, expected_contact_db)
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
|
@ -1064,19 +1027,17 @@ class TestRegistrantContacts(MockEppLib):
|
|||
self.assertEqual(cache.get(administrative), "adminContact")
|
||||
|
||||
def test_contact_getter_registrant(self):
|
||||
with less_console_noise():
|
||||
expected_contact = self.domain.map_epp_contact_to_public_contact(
|
||||
self.mockRegistrantContact,
|
||||
contact_id="regContact",
|
||||
contact_type=PublicContact.ContactTypeChoices.REGISTRANT,
|
||||
)
|
||||
|
||||
self.assertEqual(self.domain_contact.registrant_contact.email, expected_contact.email)
|
||||
|
||||
expected_contact_db = PublicContact.objects.filter(
|
||||
registry_id=self.domain_contact.registrant_contact.registry_id,
|
||||
contact_type=PublicContact.ContactTypeChoices.REGISTRANT,
|
||||
).get()
|
||||
|
||||
# Checks if we grab the correct PublicContact
|
||||
self.assertEqual(self.domain_contact.registrant_contact, expected_contact_db)
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
|
@ -1112,6 +1073,7 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
|
||||
def test_get_nameserver_changes_success_deleted_vals(self):
|
||||
"""Testing only deleting and no other changes"""
|
||||
with less_console_noise():
|
||||
self.domain._cache["hosts"] = [
|
||||
{"name": "ns1.example.com", "addrs": None},
|
||||
{"name": "ns2.example.com", "addrs": ["1.2.3.4"]},
|
||||
|
@ -1136,6 +1098,7 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
|
||||
def test_get_nameserver_changes_success_updated_vals(self):
|
||||
"""Testing only updating no other changes"""
|
||||
with less_console_noise():
|
||||
self.domain._cache["hosts"] = [
|
||||
{"name": "ns3.my-nameserver.gov", "addrs": ["1.2.3.4"]},
|
||||
]
|
||||
|
@ -1148,7 +1111,6 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
new_values,
|
||||
oldNameservers,
|
||||
) = self.domain.getNameserverChanges(newChanges)
|
||||
|
||||
self.assertEqual(deleted_values, [])
|
||||
self.assertEqual(updated_values, [("ns3.my-nameserver.gov", ["1.2.4.5"])])
|
||||
self.assertEqual(new_values, {})
|
||||
|
@ -1158,6 +1120,7 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
)
|
||||
|
||||
def test_get_nameserver_changes_success_new_vals(self):
|
||||
with less_console_noise():
|
||||
# Testing only creating no other changes
|
||||
self.domain._cache["hosts"] = [
|
||||
{"name": "ns1.example.com", "addrs": None},
|
||||
|
@ -1193,11 +1156,10 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
And `domain.is_active` returns False
|
||||
And domain.first_ready is null
|
||||
"""
|
||||
|
||||
with less_console_noise():
|
||||
# set 1 nameserver
|
||||
nameserver = "ns1.my-nameserver.com"
|
||||
self.domain.nameservers = [(nameserver,)]
|
||||
|
||||
# when we create a host, we should've updated at the same time
|
||||
created_host = commands.CreateHost(nameserver)
|
||||
update_domain_with_created = commands.UpdateDomain(
|
||||
|
@ -1205,19 +1167,15 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
add=[common.HostObjSet([created_host.name])],
|
||||
rem=[],
|
||||
)
|
||||
|
||||
# checking if commands were sent (commands have to be sent in order)
|
||||
expectedCalls = [
|
||||
call(created_host, cleaned=True),
|
||||
call(update_domain_with_created, cleaned=True),
|
||||
]
|
||||
|
||||
self.mockedSendFunction.assert_has_calls(expectedCalls)
|
||||
|
||||
# check that status is still NOT READY
|
||||
# as you have less than 2 nameservers
|
||||
self.assertFalse(self.domain.is_active())
|
||||
|
||||
self.assertEqual(self.domain.first_ready, None)
|
||||
|
||||
def test_user_adds_two_nameservers(self):
|
||||
|
@ -1230,14 +1188,12 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
And `domain.is_active` returns True
|
||||
And domain.first_ready is not null
|
||||
"""
|
||||
|
||||
with less_console_noise():
|
||||
# set 2 nameservers
|
||||
self.domain.nameservers = [(self.nameserver1,), (self.nameserver2,)]
|
||||
|
||||
# when you create a host, you also have to update at same time
|
||||
created_host1 = commands.CreateHost(self.nameserver1)
|
||||
created_host2 = commands.CreateHost(self.nameserver2)
|
||||
|
||||
update_domain_with_created = commands.UpdateDomain(
|
||||
name=self.domain.name,
|
||||
add=[
|
||||
|
@ -1245,7 +1201,6 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
],
|
||||
rem=[],
|
||||
)
|
||||
|
||||
infoDomain = commands.InfoDomain(name="my-nameserver.gov", auth_info=None)
|
||||
# checking if commands were sent (commands have to be sent in order)
|
||||
expectedCalls = [
|
||||
|
@ -1254,7 +1209,6 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
call(created_host2, cleaned=True),
|
||||
call(update_domain_with_created, cleaned=True),
|
||||
]
|
||||
|
||||
self.mockedSendFunction.assert_has_calls(expectedCalls, any_order=True)
|
||||
self.assertEqual(4, self.mockedSendFunction.call_count)
|
||||
# check that status is READY
|
||||
|
@ -1268,7 +1222,7 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
When `domain.nameservers` is set to an array of length 14
|
||||
Then Domain raises a user-friendly error
|
||||
"""
|
||||
|
||||
with less_console_noise():
|
||||
# set 13+ nameservers
|
||||
nameserver1 = "ns1.cats-are-superior1.com"
|
||||
nameserver2 = "ns1.cats-are-superior2.com"
|
||||
|
@ -1315,7 +1269,7 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
to the registry
|
||||
And `domain.is_active` returns True
|
||||
"""
|
||||
|
||||
with less_console_noise():
|
||||
# Mock is set to return 3 nameservers on infodomain
|
||||
self.domainWithThreeNS.nameservers = [(self.nameserver1,), (self.nameserver2,)]
|
||||
expectedCalls = [
|
||||
|
@ -1343,7 +1297,6 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
),
|
||||
call(commands.DeleteHost(name="ns1.cats-are-superior3.com"), cleaned=True),
|
||||
]
|
||||
|
||||
self.mockedSendFunction.assert_has_calls(expectedCalls, any_order=True)
|
||||
self.assertTrue(self.domainWithThreeNS.is_active())
|
||||
|
||||
|
@ -1357,7 +1310,7 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
And `domain.is_active` returns False
|
||||
|
||||
"""
|
||||
|
||||
with less_console_noise():
|
||||
self.domainWithThreeNS.nameservers = [(self.nameserver1,)]
|
||||
expectedCalls = [
|
||||
call(
|
||||
|
@ -1389,7 +1342,6 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
),
|
||||
call(commands.DeleteHost(name="ns1.cats-are-superior3.com"), cleaned=True),
|
||||
]
|
||||
|
||||
self.mockedSendFunction.assert_has_calls(expectedCalls, any_order=True)
|
||||
self.assertFalse(self.domainWithThreeNS.is_active())
|
||||
|
||||
|
@ -1403,12 +1355,12 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
And `commands.UpdateDomain` is sent to add #4 and #5 plus remove #2 and #3
|
||||
And `commands.DeleteHost` is sent to delete #2 and #3
|
||||
"""
|
||||
with less_console_noise():
|
||||
self.domainWithThreeNS.nameservers = [
|
||||
(self.nameserver1,),
|
||||
("ns1.cats-are-superior1.com",),
|
||||
("ns1.cats-are-superior2.com",),
|
||||
]
|
||||
|
||||
expectedCalls = [
|
||||
call(
|
||||
commands.InfoDomain(name=self.domainWithThreeNS.name, auth_info=None),
|
||||
|
@ -1453,7 +1405,6 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
cleaned=True,
|
||||
),
|
||||
]
|
||||
|
||||
self.mockedSendFunction.assert_has_calls(expectedCalls, any_order=True)
|
||||
self.assertTrue(self.domainWithThreeNS.is_active())
|
||||
|
||||
|
@ -1465,9 +1416,8 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
with a subdomain of the domain and no IP addresses
|
||||
Then Domain raises a user-friendly error
|
||||
"""
|
||||
|
||||
with less_console_noise():
|
||||
dotgovnameserver = "my-nameserver.gov"
|
||||
|
||||
with self.assertRaises(NameserverError):
|
||||
self.domain.nameservers = [(dotgovnameserver,)]
|
||||
|
||||
|
@ -1480,6 +1430,7 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
with a different IP address(es)
|
||||
Then `commands.UpdateHost` is sent to the registry
|
||||
"""
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="nameserverwithip.gov", state=Domain.State.READY)
|
||||
domain.nameservers = [
|
||||
("ns1.nameserverwithip.gov", ["2.3.4.5", "1.2.3.4"]),
|
||||
|
@ -1489,7 +1440,6 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
),
|
||||
("ns3.nameserverwithip.gov", ["2.3.4.5"]),
|
||||
]
|
||||
|
||||
expectedCalls = [
|
||||
call(
|
||||
commands.InfoDomain(name="nameserverwithip.gov", auth_info=None),
|
||||
|
@ -1517,7 +1467,6 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
cleaned=True,
|
||||
),
|
||||
]
|
||||
|
||||
self.mockedSendFunction.assert_has_calls(expectedCalls, any_order=True)
|
||||
self.assertTrue(domain.is_active())
|
||||
|
||||
|
@ -1529,8 +1478,8 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
which is not a subdomain of the domain and has IP addresses
|
||||
Then Domain raises a user-friendly error
|
||||
"""
|
||||
with less_console_noise():
|
||||
dotgovnameserver = "mynameserverdotgov.gov"
|
||||
|
||||
with self.assertRaises(NameserverError):
|
||||
self.domain.nameservers = [(dotgovnameserver, ["1.2.3"])]
|
||||
|
||||
|
@ -1541,14 +1490,13 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
to the registry twice with identical data
|
||||
Then no errors are raised in Domain
|
||||
"""
|
||||
|
||||
with less_console_noise():
|
||||
# Checking that it doesn't create or update even if out of order
|
||||
self.domainWithThreeNS.nameservers = [
|
||||
(self.nameserver3,),
|
||||
(self.nameserver1,),
|
||||
(self.nameserver2,),
|
||||
]
|
||||
|
||||
expectedCalls = [
|
||||
call(
|
||||
commands.InfoDomain(name=self.domainWithThreeNS.name, auth_info=None),
|
||||
|
@ -1558,13 +1506,12 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
call(commands.InfoHost(name="ns1.my-nameserver-2.com"), cleaned=True),
|
||||
call(commands.InfoHost(name="ns1.cats-are-superior3.com"), cleaned=True),
|
||||
]
|
||||
|
||||
self.mockedSendFunction.assert_has_calls(expectedCalls, any_order=True)
|
||||
self.assertEqual(self.mockedSendFunction.call_count, 4)
|
||||
|
||||
def test_is_subdomain_with_no_ip(self):
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="nameserversubdomain.gov", state=Domain.State.READY)
|
||||
|
||||
with self.assertRaises(NameserverError):
|
||||
domain.nameservers = [
|
||||
("ns1.nameserversubdomain.gov",),
|
||||
|
@ -1572,8 +1519,8 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
]
|
||||
|
||||
def test_not_subdomain_but_has_ip(self):
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="nameserversubdomain.gov", state=Domain.State.READY)
|
||||
|
||||
with self.assertRaises(NameserverError):
|
||||
domain.nameservers = [
|
||||
("ns1.cats-da-best.gov", ["1.2.3.4"]),
|
||||
|
@ -1581,6 +1528,7 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
]
|
||||
|
||||
def test_is_subdomain_but_ip_addr_not_valid(self):
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="nameserversubdomain.gov", state=Domain.State.READY)
|
||||
|
||||
with self.assertRaises(NameserverError):
|
||||
|
@ -1592,6 +1540,7 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
def test_setting_not_allowed(self):
|
||||
"""Scenario: A domain state is not Ready or DNS needed
|
||||
then setting nameservers is not allowed"""
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="onholdDomain.gov", state=Domain.State.ON_HOLD)
|
||||
with self.assertRaises(ActionNotAllowed):
|
||||
domain.nameservers = [self.nameserver1, self.nameserver2]
|
||||
|
@ -1602,6 +1551,7 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
Registry is unavailable and throws exception when attempting to build cache from
|
||||
registry. Nameservers retrieved from database.
|
||||
"""
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="fake.gov", state=Domain.State.READY)
|
||||
# set the host and host_ips directly in the database; this is normally handled through
|
||||
# fetch_cache
|
||||
|
@ -1609,20 +1559,16 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
host_ip, _ = HostIP.objects.get_or_create(host=host, address="1.1.1.1")
|
||||
|
||||
# mock that registry throws an error on the InfoHost send
|
||||
|
||||
def side_effect(_request, cleaned):
|
||||
raise RegistryError(code=ErrorCode.COMMAND_FAILED)
|
||||
|
||||
patcher = patch("registrar.models.domain.registry.send")
|
||||
mocked_send = patcher.start()
|
||||
mocked_send.side_effect = side_effect
|
||||
|
||||
nameservers = domain.nameservers
|
||||
|
||||
self.assertEqual(len(nameservers), 1)
|
||||
self.assertEqual(nameservers[0][0], "ns1.fake.gov")
|
||||
self.assertEqual(nameservers[0][1], ["1.1.1.1"])
|
||||
|
||||
patcher.stop()
|
||||
|
||||
def test_nameservers_stored_on_fetch_cache(self):
|
||||
|
@ -1633,8 +1579,8 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
of 'fake.host.com' from InfoDomain and an array of 2 IPs: 1.2.3.4 and 2.3.4.5
|
||||
from InfoHost
|
||||
"""
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="fake.gov", state=Domain.State.READY)
|
||||
|
||||
# mock the get_or_create methods for Host and HostIP
|
||||
with patch.object(Host.objects, "get_or_create") as mock_host_get_or_create, patch.object(
|
||||
HostIP.objects, "get_or_create"
|
||||
|
@ -1642,7 +1588,6 @@ class TestRegistrantNameservers(MockEppLib):
|
|||
# Set the return value for the mocks
|
||||
mock_host_get_or_create.return_value = (Host(), True)
|
||||
mock_host_ip_get_or_create.return_value = (HostIP(), True)
|
||||
|
||||
# force fetch_cache to be called, which will return above documented mocked hosts
|
||||
domain.nameservers
|
||||
# assert that the mocks are called
|
||||
|
@ -1791,13 +1736,12 @@ class TestRegistrantDNSSEC(MockEppLib):
|
|||
else:
|
||||
return MagicMock(res_data=[self.mockDataInfoHosts])
|
||||
|
||||
with less_console_noise():
|
||||
patcher = patch("registrar.models.domain.registry.send")
|
||||
mocked_send = patcher.start()
|
||||
mocked_send.side_effect = side_effect
|
||||
|
||||
domain, _ = Domain.objects.get_or_create(name="dnssec-dsdata.gov")
|
||||
domain.dnssecdata = self.dnssecExtensionWithDsData
|
||||
|
||||
# get the DNS SEC extension added to the UpdateDomain command and
|
||||
# verify that it is properly sent
|
||||
# args[0] is the _request sent to registry
|
||||
|
@ -1835,9 +1779,7 @@ class TestRegistrantDNSSEC(MockEppLib):
|
|||
),
|
||||
]
|
||||
)
|
||||
|
||||
self.assertEquals(dnssecdata_get.dsData, self.dnssecExtensionWithDsData.dsData)
|
||||
|
||||
patcher.stop()
|
||||
|
||||
def test_dnssec_is_idempotent(self):
|
||||
|
@ -1872,12 +1814,11 @@ class TestRegistrantDNSSEC(MockEppLib):
|
|||
else:
|
||||
return MagicMock(res_data=[self.mockDataInfoHosts])
|
||||
|
||||
with less_console_noise():
|
||||
patcher = patch("registrar.models.domain.registry.send")
|
||||
mocked_send = patcher.start()
|
||||
mocked_send.side_effect = side_effect
|
||||
|
||||
domain, _ = Domain.objects.get_or_create(name="dnssec-dsdata.gov")
|
||||
|
||||
# set the dnssecdata once
|
||||
domain.dnssecdata = self.dnssecExtensionWithDsData
|
||||
# set the dnssecdata again
|
||||
|
@ -1916,9 +1857,7 @@ class TestRegistrantDNSSEC(MockEppLib):
|
|||
),
|
||||
]
|
||||
)
|
||||
|
||||
self.assertEquals(dnssecdata_get.dsData, self.dnssecExtensionWithDsData.dsData)
|
||||
|
||||
patcher.stop()
|
||||
|
||||
def test_user_adds_dnssec_data_multiple_dsdata(self):
|
||||
|
@ -1949,12 +1888,11 @@ class TestRegistrantDNSSEC(MockEppLib):
|
|||
else:
|
||||
return MagicMock(res_data=[self.mockDataInfoHosts])
|
||||
|
||||
with less_console_noise():
|
||||
patcher = patch("registrar.models.domain.registry.send")
|
||||
mocked_send = patcher.start()
|
||||
mocked_send.side_effect = side_effect
|
||||
|
||||
domain, _ = Domain.objects.get_or_create(name="dnssec-multdsdata.gov")
|
||||
|
||||
domain.dnssecdata = self.dnssecExtensionWithMultDsData
|
||||
# get the DNS SEC extension added to the UpdateDomain command
|
||||
# and verify that it is properly sent
|
||||
|
@ -1987,9 +1925,7 @@ class TestRegistrantDNSSEC(MockEppLib):
|
|||
),
|
||||
]
|
||||
)
|
||||
|
||||
self.assertEquals(dnssecdata_get.dsData, self.dnssecExtensionWithMultDsData.dsData)
|
||||
|
||||
patcher.stop()
|
||||
|
||||
def test_user_removes_dnssec_data(self):
|
||||
|
@ -2021,10 +1957,10 @@ class TestRegistrantDNSSEC(MockEppLib):
|
|||
else:
|
||||
return MagicMock(res_data=[self.mockDataInfoHosts])
|
||||
|
||||
with less_console_noise():
|
||||
patcher = patch("registrar.models.domain.registry.send")
|
||||
mocked_send = patcher.start()
|
||||
mocked_send.side_effect = side_effect
|
||||
|
||||
domain, _ = Domain.objects.get_or_create(name="dnssec-dsdata.gov")
|
||||
# dnssecdata_get_initial = domain.dnssecdata # call to force initial mock
|
||||
# domain._invalidate_cache()
|
||||
|
@ -2078,7 +2014,6 @@ class TestRegistrantDNSSEC(MockEppLib):
|
|||
),
|
||||
]
|
||||
)
|
||||
|
||||
patcher.stop()
|
||||
|
||||
def test_update_is_unsuccessful(self):
|
||||
|
@ -2087,9 +2022,8 @@ class TestRegistrantDNSSEC(MockEppLib):
|
|||
When an error is returned from epplibwrapper
|
||||
Then a user-friendly error message is returned for displaying on the web
|
||||
"""
|
||||
|
||||
with less_console_noise():
|
||||
domain, _ = Domain.objects.get_or_create(name="dnssec-invalid.gov")
|
||||
|
||||
with self.assertRaises(RegistryError) as err:
|
||||
domain.dnssecdata = self.dnssecExtensionWithDsData
|
||||
self.assertTrue(err.is_client_error() or err.is_session_error() or err.is_server_error())
|
||||
|
@ -2117,11 +2051,13 @@ class TestExpirationDate(MockEppLib):
|
|||
|
||||
def test_expiration_date_setter_not_implemented(self):
|
||||
"""assert that the setter for expiration date is not implemented and will raise error"""
|
||||
with less_console_noise():
|
||||
with self.assertRaises(NotImplementedError):
|
||||
self.domain.registry_expiration_date = datetime.date.today()
|
||||
|
||||
def test_renew_domain(self):
|
||||
"""assert that the renew_domain sets new expiration date in cache and saves to registrar"""
|
||||
with less_console_noise():
|
||||
self.domain.renew_domain()
|
||||
test_date = datetime.date(2023, 5, 25)
|
||||
self.assertEquals(self.domain._cache["ex_date"], test_date)
|
||||
|
@ -2129,28 +2065,31 @@ class TestExpirationDate(MockEppLib):
|
|||
|
||||
def test_renew_domain_error(self):
|
||||
"""assert that the renew_domain raises an exception when registry raises error"""
|
||||
with less_console_noise():
|
||||
with self.assertRaises(RegistryError):
|
||||
self.domain_w_error.renew_domain()
|
||||
|
||||
def test_is_expired(self):
|
||||
"""assert that is_expired returns true for expiration_date in past"""
|
||||
with less_console_noise():
|
||||
# force fetch_cache to be called
|
||||
self.domain.statuses
|
||||
self.assertTrue(self.domain.is_expired)
|
||||
|
||||
def test_is_not_expired(self):
|
||||
"""assert that is_expired returns false for expiration in future"""
|
||||
with less_console_noise():
|
||||
# to do this, need to mock value returned from timezone.now
|
||||
# set now to 2023-01-01
|
||||
mocked_datetime = datetime.datetime(2023, 1, 1, 12, 0, 0)
|
||||
# force fetch_cache which sets the expiration date to 2023-05-25
|
||||
self.domain.statuses
|
||||
|
||||
with patch("registrar.models.domain.timezone.now", return_value=mocked_datetime):
|
||||
self.assertFalse(self.domain.is_expired())
|
||||
|
||||
def test_expiration_date_updated_on_info_domain_call(self):
|
||||
"""assert that expiration date in db is updated on info domain call"""
|
||||
with less_console_noise():
|
||||
# force fetch_cache to be called
|
||||
self.domain.statuses
|
||||
test_date = datetime.date(2023, 5, 25)
|
||||
|
@ -2169,7 +2108,7 @@ class TestCreationDate(MockEppLib):
|
|||
self.domain, _ = Domain.objects.get_or_create(name="fake.gov", state=Domain.State.READY)
|
||||
# creation_date returned from mockDataInfoDomain with creation date:
|
||||
# cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35)
|
||||
self.creation_date = datetime.datetime(2023, 5, 25, 19, 45, 35)
|
||||
self.creation_date = make_aware(datetime.datetime(2023, 5, 25, 19, 45, 35))
|
||||
|
||||
def tearDown(self):
|
||||
Domain.objects.all().delete()
|
||||
|
@ -2212,6 +2151,7 @@ class TestAnalystClientHold(MockEppLib):
|
|||
When `domain.place_client_hold()` is called
|
||||
Then `CLIENT_HOLD` is added to the domain's statuses
|
||||
"""
|
||||
with less_console_noise():
|
||||
self.domain.place_client_hold()
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
[
|
||||
|
@ -2243,6 +2183,7 @@ class TestAnalystClientHold(MockEppLib):
|
|||
When `domain.place_client_hold()` is called
|
||||
Then Domain returns normally (without error)
|
||||
"""
|
||||
with less_console_noise():
|
||||
self.domain_on_hold.place_client_hold()
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
[
|
||||
|
@ -2274,6 +2215,7 @@ class TestAnalystClientHold(MockEppLib):
|
|||
When `domain.remove_client_hold()` is called
|
||||
Then `CLIENT_HOLD` is no longer in the domain's statuses
|
||||
"""
|
||||
with less_console_noise():
|
||||
self.domain_on_hold.revert_client_hold()
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
[
|
||||
|
@ -2305,6 +2247,7 @@ class TestAnalystClientHold(MockEppLib):
|
|||
When `domain.remove_client_hold()` is called
|
||||
Then Domain returns normally (without error)
|
||||
"""
|
||||
with less_console_noise():
|
||||
self.domain.revert_client_hold()
|
||||
self.mockedSendFunction.assert_has_calls(
|
||||
[
|
||||
|
@ -2339,17 +2282,16 @@ class TestAnalystClientHold(MockEppLib):
|
|||
def side_effect(_request, cleaned):
|
||||
raise RegistryError(code=ErrorCode.OBJECT_STATUS_PROHIBITS_OPERATION)
|
||||
|
||||
with less_console_noise():
|
||||
patcher = patch("registrar.models.domain.registry.send")
|
||||
mocked_send = patcher.start()
|
||||
mocked_send.side_effect = side_effect
|
||||
|
||||
# if RegistryError is raised, admin formats user-friendly
|
||||
# error message if error is_client_error, is_session_error, or
|
||||
# is_server_error; so test for those conditions
|
||||
with self.assertRaises(RegistryError) as err:
|
||||
self.domain.place_client_hold()
|
||||
self.assertTrue(err.is_client_error() or err.is_session_error() or err.is_server_error())
|
||||
|
||||
patcher.stop()
|
||||
|
||||
|
||||
|
@ -2443,6 +2385,7 @@ class TestAnalystDelete(MockEppLib):
|
|||
|
||||
The deleted date is set.
|
||||
"""
|
||||
with less_console_noise():
|
||||
# Put the domain in client hold
|
||||
self.domain.place_client_hold()
|
||||
# Delete it...
|
||||
|
@ -2456,16 +2399,12 @@ class TestAnalystDelete(MockEppLib):
|
|||
)
|
||||
]
|
||||
)
|
||||
|
||||
# Domain itself should not be deleted
|
||||
self.assertNotEqual(self.domain, None)
|
||||
|
||||
# Domain should have the right state
|
||||
self.assertEqual(self.domain.state, Domain.State.DELETED)
|
||||
|
||||
# Domain should have a deleted
|
||||
self.assertNotEqual(self.domain.deleted, None)
|
||||
|
||||
# Cache should be invalidated
|
||||
self.assertEqual(self.domain._cache, {})
|
||||
|
||||
|
@ -2476,11 +2415,11 @@ class TestAnalystDelete(MockEppLib):
|
|||
Then a client error is returned of code 2305
|
||||
And `state` is not set to `DELETED`
|
||||
"""
|
||||
with less_console_noise():
|
||||
# Desired domain
|
||||
domain, _ = Domain.objects.get_or_create(name="failDelete.gov", state=Domain.State.ON_HOLD)
|
||||
# Put the domain in client hold
|
||||
domain.place_client_hold()
|
||||
|
||||
# Delete it
|
||||
with self.assertRaises(RegistryError) as err:
|
||||
domain.deletedInEpp()
|
||||
|
@ -2494,7 +2433,6 @@ class TestAnalystDelete(MockEppLib):
|
|||
)
|
||||
]
|
||||
)
|
||||
|
||||
# Domain itself should not be deleted
|
||||
self.assertNotEqual(domain, None)
|
||||
# State should not have changed
|
||||
|
@ -2511,6 +2449,7 @@ class TestAnalystDelete(MockEppLib):
|
|||
|
||||
The deleted date is still null.
|
||||
"""
|
||||
with less_console_noise():
|
||||
self.assertEqual(self.domain.state, Domain.State.READY)
|
||||
with self.assertRaises(TransitionNotAllowed) as err:
|
||||
self.domain.deletedInEpp()
|
||||
|
@ -2520,6 +2459,5 @@ class TestAnalystDelete(MockEppLib):
|
|||
self.assertNotEqual(self.domain, None)
|
||||
# Domain should have the right state
|
||||
self.assertEqual(self.domain.state, Domain.State.READY)
|
||||
|
||||
# deleted should be null
|
||||
self.assertEqual(self.domain.deleted, None)
|
||||
|
|
|
@ -23,6 +23,7 @@ import boto3_mocking
|
|||
from registrar.utility.s3_bucket import S3ClientError, S3ClientErrorCodes # type: ignore
|
||||
from datetime import date, datetime, timedelta
|
||||
from django.utils import timezone
|
||||
from .common import less_console_noise
|
||||
|
||||
|
||||
class CsvReportsTest(TestCase):
|
||||
|
@ -80,6 +81,7 @@ class CsvReportsTest(TestCase):
|
|||
@boto3_mocking.patching
|
||||
def test_generate_federal_report(self):
|
||||
"""Ensures that we correctly generate current-federal.csv"""
|
||||
with less_console_noise():
|
||||
mock_client = MagicMock()
|
||||
fake_open = mock_open()
|
||||
expected_file_content = [
|
||||
|
@ -99,6 +101,7 @@ class CsvReportsTest(TestCase):
|
|||
@boto3_mocking.patching
|
||||
def test_generate_full_report(self):
|
||||
"""Ensures that we correctly generate current-full.csv"""
|
||||
with less_console_noise():
|
||||
mock_client = MagicMock()
|
||||
fake_open = mock_open()
|
||||
expected_file_content = [
|
||||
|
@ -123,6 +126,7 @@ class CsvReportsTest(TestCase):
|
|||
def side_effect(Bucket, Key):
|
||||
raise ClientError({"Error": {"Code": "NoSuchKey", "Message": "No such key"}}, "get_object")
|
||||
|
||||
with less_console_noise():
|
||||
mock_client = MagicMock()
|
||||
mock_client.get_object.side_effect = side_effect
|
||||
|
||||
|
@ -144,6 +148,7 @@ class CsvReportsTest(TestCase):
|
|||
def side_effect(Bucket, Key):
|
||||
raise ClientError({"Error": {"Code": "NoSuchKey", "Message": "No such key"}}, "get_object")
|
||||
|
||||
with less_console_noise():
|
||||
mock_client = MagicMock()
|
||||
mock_client.get_object.side_effect = side_effect
|
||||
|
||||
|
@ -160,6 +165,7 @@ class CsvReportsTest(TestCase):
|
|||
@boto3_mocking.patching
|
||||
def test_load_federal_report(self):
|
||||
"""Tests the get_current_federal api endpoint"""
|
||||
with less_console_noise():
|
||||
mock_client = MagicMock()
|
||||
mock_client_instance = mock_client.return_value
|
||||
|
||||
|
@ -192,6 +198,7 @@ class CsvReportsTest(TestCase):
|
|||
@boto3_mocking.patching
|
||||
def test_load_full_report(self):
|
||||
"""Tests the current-federal api link"""
|
||||
with less_console_noise():
|
||||
mock_client = MagicMock()
|
||||
mock_client_instance = mock_client.return_value
|
||||
|
||||
|
@ -339,24 +346,19 @@ class ExportDataTest(MockEppLib):
|
|||
def test_export_domains_to_writer_security_emails(self):
|
||||
"""Test that export_domains_to_writer returns the
|
||||
expected security email"""
|
||||
|
||||
with less_console_noise():
|
||||
# Add security email information
|
||||
self.domain_1.name = "defaultsecurity.gov"
|
||||
self.domain_1.save()
|
||||
|
||||
# Invoke setter
|
||||
self.domain_1.security_contact
|
||||
|
||||
# Invoke setter
|
||||
self.domain_2.security_contact
|
||||
|
||||
# Invoke setter
|
||||
self.domain_3.security_contact
|
||||
|
||||
# Create a CSV file in memory
|
||||
csv_file = StringIO()
|
||||
writer = csv.writer(csv_file)
|
||||
|
||||
# Define columns, sort fields, and filter condition
|
||||
columns = [
|
||||
"Domain name",
|
||||
|
@ -379,18 +381,14 @@ class ExportDataTest(MockEppLib):
|
|||
Domain.State.ON_HOLD,
|
||||
],
|
||||
}
|
||||
|
||||
self.maxDiff = None
|
||||
# Call the export functions
|
||||
write_header(writer, columns)
|
||||
write_body(writer, columns, sort_fields, filter_condition)
|
||||
|
||||
# Reset the CSV file's position to the beginning
|
||||
csv_file.seek(0)
|
||||
|
||||
# Read the content into a variable
|
||||
csv_content = csv_file.read()
|
||||
|
||||
# We expect READY domains,
|
||||
# sorted alphabetially by domain name
|
||||
expected_content = (
|
||||
|
@ -401,18 +399,17 @@ class ExportDataTest(MockEppLib):
|
|||
"ddomain3.gov,Federal,Armed Forces Retirement Home,123@mail.gov,On hold,2023-05-25\n"
|
||||
"defaultsecurity.gov,Federal - Executive,World War I Centennial Commission,(blank),Ready"
|
||||
)
|
||||
|
||||
# Normalize line endings and remove commas,
|
||||
# spaces and leading/trailing whitespace
|
||||
csv_content = csv_content.replace(",,", "").replace(",", "").replace(" ", "").replace("\r\n", "\n").strip()
|
||||
expected_content = expected_content.replace(",,", "").replace(",", "").replace(" ", "").strip()
|
||||
|
||||
self.assertEqual(csv_content, expected_content)
|
||||
|
||||
def test_write_body(self):
|
||||
"""Test that write_body returns the
|
||||
existing domain, test that sort by domain name works,
|
||||
test that filter works"""
|
||||
with less_console_noise():
|
||||
# Create a CSV file in memory
|
||||
csv_file = StringIO()
|
||||
writer = csv.writer(csv_file)
|
||||
|
@ -442,17 +439,13 @@ class ExportDataTest(MockEppLib):
|
|||
Domain.State.ON_HOLD,
|
||||
],
|
||||
}
|
||||
|
||||
# Call the export functions
|
||||
write_header(writer, columns)
|
||||
write_body(writer, columns, sort_fields, filter_condition)
|
||||
|
||||
# Reset the CSV file's position to the beginning
|
||||
csv_file.seek(0)
|
||||
|
||||
# Read the content into a variable
|
||||
csv_content = csv_file.read()
|
||||
|
||||
# We expect READY domains,
|
||||
# sorted alphabetially by domain name
|
||||
expected_content = (
|
||||
|
@ -464,20 +457,18 @@ class ExportDataTest(MockEppLib):
|
|||
"cdomain1.gov,Federal - Executive,World War I Centennial Commission,Ready\n"
|
||||
"ddomain3.gov,Federal,Armed Forces Retirement Home,On hold\n"
|
||||
)
|
||||
|
||||
# Normalize line endings and remove commas,
|
||||
# spaces and leading/trailing whitespace
|
||||
csv_content = csv_content.replace(",,", "").replace(",", "").replace(" ", "").replace("\r\n", "\n").strip()
|
||||
expected_content = expected_content.replace(",,", "").replace(",", "").replace(" ", "").strip()
|
||||
|
||||
self.assertEqual(csv_content, expected_content)
|
||||
|
||||
def test_write_body_additional(self):
|
||||
"""An additional test for filters and multi-column sort"""
|
||||
with less_console_noise():
|
||||
# Create a CSV file in memory
|
||||
csv_file = StringIO()
|
||||
writer = csv.writer(csv_file)
|
||||
|
||||
# Define columns, sort fields, and filter condition
|
||||
columns = [
|
||||
"Domain name",
|
||||
|
@ -497,17 +488,13 @@ class ExportDataTest(MockEppLib):
|
|||
Domain.State.ON_HOLD,
|
||||
],
|
||||
}
|
||||
|
||||
# Call the export functions
|
||||
write_header(writer, columns)
|
||||
write_body(writer, columns, sort_fields, filter_condition)
|
||||
|
||||
# Reset the CSV file's position to the beginning
|
||||
csv_file.seek(0)
|
||||
|
||||
# Read the content into a variable
|
||||
csv_content = csv_file.read()
|
||||
|
||||
# We expect READY domains,
|
||||
# federal only
|
||||
# sorted alphabetially by domain name
|
||||
|
@ -518,12 +505,10 @@ class ExportDataTest(MockEppLib):
|
|||
"cdomain1.gov,Federal - Executive,World War I Centennial Commission\n"
|
||||
"ddomain3.gov,Federal,Armed Forces Retirement Home\n"
|
||||
)
|
||||
|
||||
# Normalize line endings and remove commas,
|
||||
# spaces and leading/trailing whitespace
|
||||
csv_content = csv_content.replace(",,", "").replace(",", "").replace(" ", "").replace("\r\n", "\n").strip()
|
||||
expected_content = expected_content.replace(",,", "").replace(",", "").replace(" ", "").strip()
|
||||
|
||||
self.assertEqual(csv_content, expected_content)
|
||||
|
||||
def test_write_body_with_date_filter_pulls_domains_in_range(self):
|
||||
|
@ -538,12 +523,12 @@ class ExportDataTest(MockEppLib):
|
|||
which are hard to mock.
|
||||
|
||||
TODO: Simplify is created_at is not needed for the report."""
|
||||
|
||||
with less_console_noise():
|
||||
# Create a CSV file in memory
|
||||
csv_file = StringIO()
|
||||
writer = csv.writer(csv_file)
|
||||
# We use timezone.make_aware to sync to server time a datetime object with the current date (using date.today())
|
||||
# and a specific time (using datetime.min.time()).
|
||||
# We use timezone.make_aware to sync to server time a datetime object with the current date
|
||||
# (using date.today()) and a specific time (using datetime.min.time()).
|
||||
end_date = timezone.make_aware(datetime.combine(date.today() + timedelta(days=2), datetime.min.time()))
|
||||
start_date = timezone.make_aware(datetime.combine(date.today() - timedelta(days=2), datetime.min.time()))
|
||||
|
||||
|
|
|
@ -20,6 +20,9 @@ from registrar.models.contact import Contact
|
|||
|
||||
from .common import MockSESClient, less_console_noise
|
||||
import boto3_mocking # type: ignore
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestProcessedMigrations(TestCase):
|
||||
|
@ -55,6 +58,7 @@ class TestProcessedMigrations(TestCase):
|
|||
The 'call_command' function from Django's management framework is then used to
|
||||
execute the load_transition_domain command with the specified arguments.
|
||||
"""
|
||||
with less_console_noise():
|
||||
# noqa here because splitting this up makes it confusing.
|
||||
# ES501
|
||||
with patch(
|
||||
|
@ -74,6 +78,7 @@ class TestProcessedMigrations(TestCase):
|
|||
The 'call_command' function from Django's management framework is then used to
|
||||
execute the load_transition_domain command with the specified arguments.
|
||||
"""
|
||||
with less_console_noise():
|
||||
call_command("transfer_transition_domains_to_domains")
|
||||
|
||||
def test_domain_idempotent(self):
|
||||
|
@ -81,6 +86,7 @@ class TestProcessedMigrations(TestCase):
|
|||
This test ensures that the domain transfer process
|
||||
is idempotent on Domain and DomainInformation.
|
||||
"""
|
||||
with less_console_noise():
|
||||
unchanged_domain, _ = Domain.objects.get_or_create(
|
||||
name="testdomain.gov",
|
||||
state=Domain.State.READY,
|
||||
|
@ -139,6 +145,7 @@ class TestProcessedMigrations(TestCase):
|
|||
"""
|
||||
This test checks if a domain is correctly marked as processed in the transition.
|
||||
"""
|
||||
with less_console_noise():
|
||||
old_transition_domain, _ = TransitionDomain.objects.get_or_create(domain_name="testdomain.gov")
|
||||
# Asser that old records default to 'True'
|
||||
self.assertTrue(old_transition_domain.processed)
|
||||
|
@ -200,6 +207,7 @@ class TestOrganizationMigration(TestCase):
|
|||
The 'call_command' function from Django's management framework is then used to
|
||||
execute the load_transition_domain command with the specified arguments.
|
||||
"""
|
||||
with less_console_noise():
|
||||
# noqa here because splitting this up makes it confusing.
|
||||
# ES501
|
||||
with patch(
|
||||
|
@ -219,6 +227,7 @@ class TestOrganizationMigration(TestCase):
|
|||
The 'call_command' function from Django's management framework is then used to
|
||||
execute the load_transition_domain command with the specified arguments.
|
||||
"""
|
||||
with less_console_noise():
|
||||
call_command("transfer_transition_domains_to_domains")
|
||||
|
||||
def run_load_organization_data(self):
|
||||
|
@ -232,6 +241,7 @@ class TestOrganizationMigration(TestCase):
|
|||
The 'call_command' function from Django's management framework is then used to
|
||||
execute the load_organization_data command with the specified arguments.
|
||||
"""
|
||||
with less_console_noise():
|
||||
# noqa here (E501) because splitting this up makes it
|
||||
# confusing to read.
|
||||
with patch(
|
||||
|
@ -256,7 +266,6 @@ class TestOrganizationMigration(TestCase):
|
|||
"""Does a diff between the transition_domain and the following tables:
|
||||
domain, domain_information and the domain_invitation.
|
||||
Verifies that the data loaded correctly."""
|
||||
|
||||
missing_domains = []
|
||||
duplicate_domains = []
|
||||
missing_domain_informations = []
|
||||
|
@ -300,8 +309,11 @@ class TestOrganizationMigration(TestCase):
|
|||
3. Checks that the data has been loaded as expected.
|
||||
|
||||
The expected result is a set of TransitionDomain objects with specific attributes.
|
||||
The test fetches the actual TransitionDomain objects from the database and compares them with the expected objects.
|
||||
""" # noqa - E501 (harder to read)
|
||||
The test fetches the actual TransitionDomain objects from the database and compares them with
|
||||
the expected objects.
|
||||
"""
|
||||
with less_console_noise():
|
||||
# noqa - E501 (harder to read)
|
||||
# == First, parse all existing data == #
|
||||
self.run_load_domains()
|
||||
self.run_transfer_domains()
|
||||
|
@ -346,7 +358,9 @@ class TestOrganizationMigration(TestCase):
|
|||
def test_transition_domain_status_unknown(self):
|
||||
"""
|
||||
Test that a domain in unknown status can be loaded
|
||||
""" # noqa - E501 (harder to read)
|
||||
"""
|
||||
with less_console_noise():
|
||||
# noqa - E501 (harder to read)
|
||||
# == First, parse all existing data == #
|
||||
self.run_load_domains()
|
||||
self.run_transfer_domains()
|
||||
|
@ -367,6 +381,7 @@ class TestOrganizationMigration(TestCase):
|
|||
The test fetches the actual DomainInformation object from the database
|
||||
and compares it with the expected object.
|
||||
"""
|
||||
with less_console_noise():
|
||||
# == First, parse all existing data == #
|
||||
self.run_load_domains()
|
||||
self.run_transfer_domains()
|
||||
|
@ -379,7 +394,9 @@ class TestOrganizationMigration(TestCase):
|
|||
domain_information = DomainInformation.objects.filter(domain=_domain).get()
|
||||
|
||||
expected_creator = User.objects.filter(username="System").get()
|
||||
expected_ao = Contact.objects.filter(first_name="Seline", middle_name="testmiddle2", last_name="Tower").get()
|
||||
expected_ao = Contact.objects.filter(
|
||||
first_name="Seline", middle_name="testmiddle2", last_name="Tower"
|
||||
).get()
|
||||
expected_domain_information = DomainInformation(
|
||||
creator=expected_creator,
|
||||
organization_type="federal",
|
||||
|
@ -410,6 +427,7 @@ class TestOrganizationMigration(TestCase):
|
|||
The expected result is that the DomainInformation object retains its pre-existing data
|
||||
after the load_organization_data method is run.
|
||||
"""
|
||||
with less_console_noise():
|
||||
# == First, parse all existing data == #
|
||||
self.run_load_domains()
|
||||
self.run_transfer_domains()
|
||||
|
@ -431,7 +449,9 @@ class TestOrganizationMigration(TestCase):
|
|||
domain_information = DomainInformation.objects.filter(domain=_domain).get()
|
||||
|
||||
expected_creator = User.objects.filter(username="System").get()
|
||||
expected_ao = Contact.objects.filter(first_name="Seline", middle_name="testmiddle2", last_name="Tower").get()
|
||||
expected_ao = Contact.objects.filter(
|
||||
first_name="Seline", middle_name="testmiddle2", last_name="Tower"
|
||||
).get()
|
||||
expected_domain_information = DomainInformation(
|
||||
creator=expected_creator,
|
||||
organization_type="federal",
|
||||
|
@ -462,6 +482,7 @@ class TestOrganizationMigration(TestCase):
|
|||
The expected result is that the counts of objects in the database
|
||||
match the expected counts, indicating that the data has not been corrupted.
|
||||
"""
|
||||
with less_console_noise():
|
||||
# First, parse all existing data
|
||||
self.run_load_domains()
|
||||
self.run_transfer_domains()
|
||||
|
@ -521,6 +542,7 @@ class TestMigrations(TestCase):
|
|||
UserDomainRole.objects.all().delete()
|
||||
|
||||
def run_load_domains(self):
|
||||
with less_console_noise():
|
||||
# noqa here because splitting this up makes it confusing.
|
||||
# ES501
|
||||
with patch(
|
||||
|
@ -534,9 +556,11 @@ class TestMigrations(TestCase):
|
|||
)
|
||||
|
||||
def run_transfer_domains(self):
|
||||
with less_console_noise():
|
||||
call_command("transfer_transition_domains_to_domains")
|
||||
|
||||
def run_master_script(self):
|
||||
with less_console_noise():
|
||||
# noqa here (E501) because splitting this up makes it
|
||||
# confusing to read.
|
||||
mock_client = MockSESClient()
|
||||
|
@ -553,7 +577,7 @@ class TestMigrations(TestCase):
|
|||
migrationJSON=self.migration_json_filename,
|
||||
disablePrompts=True,
|
||||
)
|
||||
print(f"here: {mock_client.EMAILS_SENT}")
|
||||
logger.debug(f"here: {mock_client.EMAILS_SENT}")
|
||||
|
||||
def compare_tables(
|
||||
self,
|
||||
|
@ -607,7 +631,7 @@ class TestMigrations(TestCase):
|
|||
total_domain_informations = len(DomainInformation.objects.all())
|
||||
total_domain_invitations = len(DomainInvitation.objects.all())
|
||||
|
||||
print(
|
||||
logger.debug(
|
||||
f"""
|
||||
total_missing_domains = {len(missing_domains)}
|
||||
total_duplicate_domains = {len(duplicate_domains)}
|
||||
|
@ -636,7 +660,7 @@ class TestMigrations(TestCase):
|
|||
follow best practice of limiting the number of assertions per test.
|
||||
But for now, this will double-check that the script
|
||||
works as intended."""
|
||||
|
||||
with less_console_noise():
|
||||
self.run_master_script()
|
||||
|
||||
# STEP 2: (analyze the tables just like the
|
||||
|
@ -664,6 +688,7 @@ class TestMigrations(TestCase):
|
|||
|
||||
def test_load_empty_transition_domain(self):
|
||||
"""Loads TransitionDomains without additional data"""
|
||||
with less_console_noise():
|
||||
self.run_load_domains()
|
||||
|
||||
# STEP 2: (analyze the tables just like the migration
|
||||
|
@ -689,6 +714,7 @@ class TestMigrations(TestCase):
|
|||
)
|
||||
|
||||
def test_load_full_domain(self):
|
||||
with less_console_noise():
|
||||
self.run_load_domains()
|
||||
self.run_transfer_domains()
|
||||
|
||||
|
@ -733,6 +759,7 @@ class TestMigrations(TestCase):
|
|||
self.assertEqual(testdomain.state, "on hold")
|
||||
|
||||
def test_load_full_domain_information(self):
|
||||
with less_console_noise():
|
||||
self.run_load_domains()
|
||||
self.run_transfer_domains()
|
||||
|
||||
|
@ -800,6 +827,7 @@ class TestMigrations(TestCase):
|
|||
self.assertEqual(anomaly.creator, Users.get())
|
||||
|
||||
def test_transfer_transition_domains_to_domains(self):
|
||||
with less_console_noise():
|
||||
self.run_load_domains()
|
||||
self.run_transfer_domains()
|
||||
|
||||
|
@ -825,6 +853,7 @@ class TestMigrations(TestCase):
|
|||
)
|
||||
|
||||
def test_logins(self):
|
||||
with less_console_noise():
|
||||
# TODO: setup manually instead of calling other scripts
|
||||
self.run_load_domains()
|
||||
self.run_transfer_domains()
|
||||
|
|
File diff suppressed because it is too large
Load diff
2199
src/registrar/tests/test_views_application.py
Normal file
2199
src/registrar/tests/test_views_application.py
Normal file
File diff suppressed because it is too large
Load diff
1436
src/registrar/tests/test_views_domain.py
Normal file
1436
src/registrar/tests/test_views_domain.py
Normal file
File diff suppressed because it is too large
Load diff
|
@ -9,7 +9,7 @@ from django.db.models import F, Value, CharField
|
|||
from django.db.models.functions import Concat, Coalesce
|
||||
|
||||
from registrar.models.public_contact import PublicContact
|
||||
|
||||
from registrar.utility.enums import DefaultEmail
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -65,7 +65,7 @@ def parse_row(columns, domain_info: DomainInformation, security_emails_dict=None
|
|||
security_email = _email if _email is not None else " "
|
||||
|
||||
# These are default emails that should not be displayed in the csv report
|
||||
invalid_emails = {"registrar@dotgov.gov", "dotgov@cisa.dhs.gov"}
|
||||
invalid_emails = {DefaultEmail.LEGACY_DEFAULT.value, DefaultEmail.PUBLIC_CONTACT_DEFAULT.value}
|
||||
if security_email.lower() in invalid_emails:
|
||||
security_email = "(blank)"
|
||||
|
||||
|
|
|
@ -26,3 +26,15 @@ class LogCode(Enum):
|
|||
INFO = 3
|
||||
DEBUG = 4
|
||||
DEFAULT = 5
|
||||
|
||||
|
||||
class DefaultEmail(Enum):
|
||||
"""Stores the string values of default emails
|
||||
|
||||
Overview of emails:
|
||||
- PUBLIC_CONTACT_DEFAULT: "dotgov@cisa.dhs.gov"
|
||||
- LEGACY_DEFAULT: "registrar@dotgov.gov"
|
||||
"""
|
||||
|
||||
PUBLIC_CONTACT_DEFAULT = "dotgov@cisa.dhs.gov"
|
||||
LEGACY_DEFAULT = "registrar@dotgov.gov"
|
||||
|
|
|
@ -22,6 +22,7 @@ from registrar.models import (
|
|||
UserDomainRole,
|
||||
)
|
||||
from registrar.models.public_contact import PublicContact
|
||||
from registrar.utility.enums import DefaultEmail
|
||||
from registrar.utility.errors import (
|
||||
GenericError,
|
||||
GenericErrorCodes,
|
||||
|
@ -142,11 +143,12 @@ class DomainView(DomainBaseView):
|
|||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
default_email = self.object.get_default_security_contact().email
|
||||
context["default_security_email"] = default_email
|
||||
default_emails = [DefaultEmail.PUBLIC_CONTACT_DEFAULT.value, DefaultEmail.LEGACY_DEFAULT.value]
|
||||
|
||||
context["hidden_security_emails"] = default_emails
|
||||
|
||||
security_email = self.object.get_security_email()
|
||||
if security_email is None or security_email == default_email:
|
||||
if security_email is None or security_email in default_emails:
|
||||
context["security_email"] = None
|
||||
return context
|
||||
context["security_email"] = security_email
|
||||
|
@ -570,7 +572,7 @@ class DomainSecurityEmailView(DomainFormBaseView):
|
|||
initial = super().get_initial()
|
||||
security_contact = self.object.security_contact
|
||||
|
||||
invalid_emails = ["dotgov@cisa.dhs.gov", "registrar@dotgov.gov"]
|
||||
invalid_emails = [DefaultEmail.PUBLIC_CONTACT_DEFAULT.value, DefaultEmail.LEGACY_DEFAULT.value]
|
||||
if security_contact is None or security_contact.email in invalid_emails:
|
||||
initial["security_email"] = None
|
||||
return initial
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue