mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-28 12:30:27 +02:00
updated comments, updated test_models
This commit is contained in:
parent
bc75600202
commit
a2558bd762
5 changed files with 233 additions and 158 deletions
|
@ -181,7 +181,12 @@ class TestDomainRequestAdminForm(TestCase):
|
||||||
|
|
||||||
|
|
||||||
class TestDomainInvitationAdmin(TestCase):
|
class TestDomainInvitationAdmin(TestCase):
|
||||||
"""Tests for the DomainInvitation page"""
|
"""Tests for the DomainInvitationAdmin class as super user
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
all tests share superuser; do not change this model in tests
|
||||||
|
tests have available superuser, client, and admin
|
||||||
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
|
@ -246,6 +251,12 @@ class TestDomainInvitationAdmin(TestCase):
|
||||||
|
|
||||||
|
|
||||||
class TestHostAdmin(TestCase):
|
class TestHostAdmin(TestCase):
|
||||||
|
"""Tests for the HostAdmin class as super user
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
all tests share superuser; do not change this model in tests
|
||||||
|
tests have available superuser, client, and admin
|
||||||
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
|
@ -317,6 +328,12 @@ class TestHostAdmin(TestCase):
|
||||||
|
|
||||||
|
|
||||||
class TestDomainInformationAdmin(TestCase):
|
class TestDomainInformationAdmin(TestCase):
|
||||||
|
"""Tests for the DomainInformationAdmin class as super or staff user
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
all tests share superuser/staffuser; do not change these models in tests
|
||||||
|
tests have available staffuser, superuser, client, test_helper and admin
|
||||||
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
|
@ -699,6 +716,12 @@ class TestDomainInformationAdmin(TestCase):
|
||||||
|
|
||||||
|
|
||||||
class TestUserDomainRoleAdmin(TestCase):
|
class TestUserDomainRoleAdmin(TestCase):
|
||||||
|
"""Tests for the UserDomainRoleAdmin class as super user
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
all tests share superuser; do not change this model in tests
|
||||||
|
tests have available superuser, client, test_helper and admin
|
||||||
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
|
@ -876,6 +899,12 @@ class TestUserDomainRoleAdmin(TestCase):
|
||||||
fake_user.delete()
|
fake_user.delete()
|
||||||
|
|
||||||
class TestListHeaderAdmin(TestCase):
|
class TestListHeaderAdmin(TestCase):
|
||||||
|
"""Tests for the ListHeaderAdmin class as super user
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
all tests share superuser; do not change this model in tests
|
||||||
|
tests have available superuser, client and admin
|
||||||
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
|
@ -957,6 +986,13 @@ class TestListHeaderAdmin(TestCase):
|
||||||
|
|
||||||
|
|
||||||
class TestMyUserAdmin(MockDbForSharedTests):
|
class TestMyUserAdmin(MockDbForSharedTests):
|
||||||
|
"""Tests for the MyUserAdmin class as super or staff user
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
all tests share superuser/staffuser; do not change these models in tests
|
||||||
|
all tests share MockDb; do not change models defined therein in tests
|
||||||
|
tests have available staffuser, superuser, client, test_helper and admin
|
||||||
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
|
|
|
@ -36,6 +36,12 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class TestDomainAdminAsStaff(MockEppLib):
|
class TestDomainAdminAsStaff(MockEppLib):
|
||||||
|
"""Test DomainAdmin class as staff user.
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
all tests share staffuser; do not change staffuser model in tests
|
||||||
|
tests have available staffuser, client, and admin
|
||||||
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(self):
|
def setUpClass(self):
|
||||||
|
@ -367,6 +373,12 @@ class TestDomainAdminAsStaff(MockEppLib):
|
||||||
|
|
||||||
|
|
||||||
class TestDomainAdminWClient(TestCase):
|
class TestDomainAdminWClient(TestCase):
|
||||||
|
"""Test DomainAdmin class as super user.
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
all tests share superuser; tests must not update superuser
|
||||||
|
tests have available superuser, client, and admin
|
||||||
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(self):
|
def setUpClass(self):
|
||||||
|
@ -651,6 +663,14 @@ class TestDomainAdminWClient(TestCase):
|
||||||
|
|
||||||
|
|
||||||
class TestDomainAdminWebTest(MockEppLib, WebTest):
|
class TestDomainAdminWebTest(MockEppLib, WebTest):
|
||||||
|
"""Test DomainAdmin class as super user, using WebTest.
|
||||||
|
WebTest allows for easier handling of forms and html responses.
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
all tests share superuser; tests must not update superuser
|
||||||
|
tests have available superuser, app, and admin
|
||||||
|
"""
|
||||||
|
|
||||||
# csrf checks do not work with WebTest.
|
# csrf checks do not work with WebTest.
|
||||||
# We disable them here. TODO for another ticket.
|
# We disable them here. TODO for another ticket.
|
||||||
csrf_checks = False
|
csrf_checks = False
|
||||||
|
|
|
@ -42,6 +42,12 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@boto3_mocking.patching
|
@boto3_mocking.patching
|
||||||
class TestDomainRequestAdmin(MockEppLib):
|
class TestDomainRequestAdmin(MockEppLib):
|
||||||
|
"""Test DomainRequestAdmin class as either staff or super user.
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
all tests share superuser/staffuser; do not change these models in tests
|
||||||
|
tests have available staffuser, superuser, client, admin and test_helper
|
||||||
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(self):
|
def setUpClass(self):
|
||||||
|
@ -61,6 +67,20 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
)
|
)
|
||||||
self.mock_client = MockSESClient()
|
self.mock_client = MockSESClient()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
super().tearDown()
|
||||||
|
Domain.objects.all().delete()
|
||||||
|
DomainInformation.objects.all().delete()
|
||||||
|
DomainRequest.objects.all().delete()
|
||||||
|
Contact.objects.all().delete()
|
||||||
|
Website.objects.all().delete()
|
||||||
|
self.mock_client.EMAILS_SENT.clear()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDownClass(self):
|
||||||
|
super().tearDownClass()
|
||||||
|
User.objects.all().delete()
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_has_model_description(self):
|
def test_has_model_description(self):
|
||||||
"""Tests if this model has a model description on the table view"""
|
"""Tests if this model has a model description on the table view"""
|
||||||
|
@ -1854,18 +1874,4 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
# Check if response contains expected_html
|
# Check if response contains expected_html
|
||||||
self.assertIn(expected_html, response_content)
|
self.assertIn(expected_html, response_content)
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
super().tearDown()
|
|
||||||
Domain.objects.all().delete()
|
|
||||||
DomainInformation.objects.all().delete()
|
|
||||||
DomainRequest.objects.all().delete()
|
|
||||||
Contact.objects.all().delete()
|
|
||||||
Website.objects.all().delete()
|
|
||||||
self.mock_client.EMAILS_SENT.clear()
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def tearDownClass(self):
|
|
||||||
super().tearDownClass()
|
|
||||||
User.objects.all().delete()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.db.utils import IntegrityError
|
from django.db.utils import IntegrityError
|
||||||
|
from django.db import transaction
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
@ -23,15 +24,12 @@ from registrar.models.transition_domain import TransitionDomain
|
||||||
from registrar.models.verified_by_staff import VerifiedByStaff # type: ignore
|
from registrar.models.verified_by_staff import VerifiedByStaff # type: ignore
|
||||||
from registrar.utility.constants import BranchChoices
|
from registrar.utility.constants import BranchChoices
|
||||||
|
|
||||||
from .common import MockSESClient, less_console_noise, completed_domain_request, set_domain_request_investigators
|
from .common import MockSESClient, less_console_noise, completed_domain_request, set_domain_request_investigators, create_test_user
|
||||||
from django_fsm import TransitionNotAllowed
|
from django_fsm import TransitionNotAllowed
|
||||||
from waffle.testutils import override_flag
|
from waffle.testutils import override_flag
|
||||||
|
|
||||||
from api.tests.common import less_console_noise_decorator
|
from api.tests.common import less_console_noise_decorator
|
||||||
|
|
||||||
# Test comment for push -- will remove
|
|
||||||
# The DomainRequest submit method has a side effect of sending an email
|
|
||||||
# with AWS SES, so mock that out in all of these test cases
|
|
||||||
@boto3_mocking.patching
|
@boto3_mocking.patching
|
||||||
class TestDomainRequest(TestCase):
|
class TestDomainRequest(TestCase):
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
|
@ -92,6 +90,11 @@ class TestDomainRequest(TestCase):
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
DomainInformation.objects.all().delete()
|
||||||
|
DomainRequest.objects.all().delete()
|
||||||
|
DraftDomain.objects.all().delete()
|
||||||
|
Domain.objects.all().delete()
|
||||||
|
User.objects.all().delete()
|
||||||
self.mock_client.EMAILS_SENT.clear()
|
self.mock_client.EMAILS_SENT.clear()
|
||||||
|
|
||||||
def assertNotRaises(self, exception_type):
|
def assertNotRaises(self, exception_type):
|
||||||
|
@ -121,103 +124,103 @@ class TestDomainRequest(TestCase):
|
||||||
self.assertEqual(domain_request.federal_agency, expected_federal_agency)
|
self.assertEqual(domain_request.federal_agency, expected_federal_agency)
|
||||||
|
|
||||||
def test_empty_create_fails(self):
|
def test_empty_create_fails(self):
|
||||||
"""Can't create a completely empty domain request.
|
"""Can't create a completely empty domain request."""
|
||||||
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 less_console_noise():
|
||||||
with self.assertRaisesRegex(IntegrityError, "creator"):
|
with transaction.atomic():
|
||||||
DomainRequest.objects.create()
|
with self.assertRaisesRegex(IntegrityError, "creator"):
|
||||||
|
DomainRequest.objects.create()
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
def test_minimal_create(self):
|
def test_minimal_create(self):
|
||||||
"""Can create with just a creator."""
|
"""Can create with just a creator."""
|
||||||
with less_console_noise():
|
user, _ = User.objects.get_or_create(username="testy")
|
||||||
user, _ = User.objects.get_or_create(username="testy")
|
domain_request = DomainRequest.objects.create(creator=user)
|
||||||
domain_request = DomainRequest.objects.create(creator=user)
|
self.assertEqual(domain_request.status, DomainRequest.DomainRequestStatus.STARTED)
|
||||||
self.assertEqual(domain_request.status, DomainRequest.DomainRequestStatus.STARTED)
|
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
def test_full_create(self):
|
def test_full_create(self):
|
||||||
"""Can create with all fields."""
|
"""Can create with all fields."""
|
||||||
with less_console_noise():
|
user, _ = User.objects.get_or_create(username="testy")
|
||||||
user, _ = User.objects.get_or_create(username="testy")
|
contact = Contact.objects.create()
|
||||||
contact = Contact.objects.create()
|
com_website, _ = Website.objects.get_or_create(website="igorville.com")
|
||||||
com_website, _ = Website.objects.get_or_create(website="igorville.com")
|
gov_website, _ = Website.objects.get_or_create(website="igorville.gov")
|
||||||
gov_website, _ = Website.objects.get_or_create(website="igorville.gov")
|
domain, _ = DraftDomain.objects.get_or_create(name="igorville.gov")
|
||||||
domain, _ = DraftDomain.objects.get_or_create(name="igorville.gov")
|
domain_request = DomainRequest.objects.create(
|
||||||
domain_request = DomainRequest.objects.create(
|
creator=user,
|
||||||
creator=user,
|
investigator=user,
|
||||||
investigator=user,
|
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
|
||||||
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
|
federal_type=BranchChoices.EXECUTIVE,
|
||||||
federal_type=BranchChoices.EXECUTIVE,
|
is_election_board=False,
|
||||||
is_election_board=False,
|
organization_name="Test",
|
||||||
organization_name="Test",
|
address_line1="100 Main St.",
|
||||||
address_line1="100 Main St.",
|
address_line2="APT 1A",
|
||||||
address_line2="APT 1A",
|
state_territory="CA",
|
||||||
state_territory="CA",
|
zipcode="12345-6789",
|
||||||
zipcode="12345-6789",
|
senior_official=contact,
|
||||||
senior_official=contact,
|
requested_domain=domain,
|
||||||
requested_domain=domain,
|
submitter=contact,
|
||||||
submitter=contact,
|
purpose="Igorville rules!",
|
||||||
purpose="Igorville rules!",
|
anything_else="All of Igorville loves the dotgov program.",
|
||||||
anything_else="All of Igorville loves the dotgov program.",
|
is_policy_acknowledged=True,
|
||||||
is_policy_acknowledged=True,
|
)
|
||||||
)
|
domain_request.current_websites.add(com_website)
|
||||||
domain_request.current_websites.add(com_website)
|
domain_request.alternative_domains.add(gov_website)
|
||||||
domain_request.alternative_domains.add(gov_website)
|
domain_request.other_contacts.add(contact)
|
||||||
domain_request.other_contacts.add(contact)
|
domain_request.save()
|
||||||
domain_request.save()
|
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
def test_domain_info(self):
|
def test_domain_info(self):
|
||||||
"""Can create domain info with all fields."""
|
"""Can create domain info with all fields."""
|
||||||
with less_console_noise():
|
user, _ = User.objects.get_or_create(username="testy")
|
||||||
user, _ = User.objects.get_or_create(username="testy")
|
contact = Contact.objects.create()
|
||||||
contact = Contact.objects.create()
|
domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
||||||
domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
information = DomainInformation.objects.create(
|
||||||
information = DomainInformation.objects.create(
|
creator=user,
|
||||||
creator=user,
|
generic_org_type=DomainInformation.OrganizationChoices.FEDERAL,
|
||||||
generic_org_type=DomainInformation.OrganizationChoices.FEDERAL,
|
federal_type=BranchChoices.EXECUTIVE,
|
||||||
federal_type=BranchChoices.EXECUTIVE,
|
is_election_board=False,
|
||||||
is_election_board=False,
|
organization_name="Test",
|
||||||
organization_name="Test",
|
address_line1="100 Main St.",
|
||||||
address_line1="100 Main St.",
|
address_line2="APT 1A",
|
||||||
address_line2="APT 1A",
|
state_territory="CA",
|
||||||
state_territory="CA",
|
zipcode="12345-6789",
|
||||||
zipcode="12345-6789",
|
senior_official=contact,
|
||||||
senior_official=contact,
|
submitter=contact,
|
||||||
submitter=contact,
|
purpose="Igorville rules!",
|
||||||
purpose="Igorville rules!",
|
anything_else="All of Igorville loves the dotgov program.",
|
||||||
anything_else="All of Igorville loves the dotgov program.",
|
is_policy_acknowledged=True,
|
||||||
is_policy_acknowledged=True,
|
domain=domain,
|
||||||
domain=domain,
|
)
|
||||||
)
|
information.other_contacts.add(contact)
|
||||||
information.other_contacts.add(contact)
|
information.save()
|
||||||
information.save()
|
self.assertEqual(information.domain.id, domain.id)
|
||||||
self.assertEqual(information.domain.id, domain.id)
|
self.assertEqual(information.id, domain.domain_info.id)
|
||||||
self.assertEqual(information.id, domain.domain_info.id)
|
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
def test_status_fsm_submit_fail(self):
|
def test_status_fsm_submit_fail(self):
|
||||||
with less_console_noise():
|
user, _ = User.objects.get_or_create(username="testy")
|
||||||
user, _ = User.objects.get_or_create(username="testy")
|
domain_request = DomainRequest.objects.create(creator=user)
|
||||||
domain_request = DomainRequest.objects.create(creator=user)
|
|
||||||
|
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
|
||||||
with less_console_noise():
|
with less_console_noise():
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
# can't submit a domain request with a null domain name
|
# can't submit a domain request with a null domain name
|
||||||
domain_request.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")
|
|
||||||
domain_request = DomainRequest.objects.create(creator=user, requested_domain=site)
|
|
||||||
|
|
||||||
# no submitter email so this emits a log warning
|
|
||||||
|
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
|
|
||||||
with less_console_noise():
|
|
||||||
domain_request.submit()
|
domain_request.submit()
|
||||||
self.assertEqual(domain_request.status, domain_request.DomainRequestStatus.SUBMITTED)
|
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
def test_status_fsm_submit_succeed(self):
|
||||||
|
user, _ = User.objects.get_or_create(username="testy")
|
||||||
|
site = DraftDomain.objects.create(name="igorville.gov")
|
||||||
|
domain_request = DomainRequest.objects.create(creator=user, requested_domain=site)
|
||||||
|
|
||||||
|
# no submitter email so this emits a log warning
|
||||||
|
|
||||||
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
|
||||||
|
with less_console_noise():
|
||||||
|
domain_request.submit()
|
||||||
|
self.assertEqual(domain_request.status, domain_request.DomainRequestStatus.SUBMITTED)
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
def check_email_sent(
|
def check_email_sent(
|
||||||
self, domain_request, msg, action, expected_count, expected_content=None, expected_email="mayor@igorville.com"
|
self, domain_request, msg, action, expected_count, expected_content=None, expected_email="mayor@igorville.com"
|
||||||
):
|
):
|
||||||
|
@ -225,10 +228,9 @@ class TestDomainRequest(TestCase):
|
||||||
|
|
||||||
with self.subTest(msg=msg, action=action):
|
with self.subTest(msg=msg, action=action):
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
|
||||||
with less_console_noise():
|
# Perform the specified action
|
||||||
# Perform the specified action
|
action_method = getattr(domain_request, action)
|
||||||
action_method = getattr(domain_request, action)
|
action_method()
|
||||||
action_method()
|
|
||||||
|
|
||||||
# Check if an email was sent
|
# Check if an email was sent
|
||||||
sent_emails = [
|
sent_emails = [
|
||||||
|
@ -899,81 +901,81 @@ class TestDomainRequest(TestCase):
|
||||||
with self.assertRaises(TransitionNotAllowed):
|
with self.assertRaises(TransitionNotAllowed):
|
||||||
self.approved_domain_request.reject_with_prejudice()
|
self.approved_domain_request.reject_with_prejudice()
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
def test_approve_from_rejected_clears_rejection_reason(self):
|
def test_approve_from_rejected_clears_rejection_reason(self):
|
||||||
"""When transitioning from rejected to approved on a domain request,
|
"""When transitioning from rejected to approved on a domain request,
|
||||||
the rejection_reason is cleared."""
|
the rejection_reason is cleared."""
|
||||||
|
|
||||||
with less_console_noise():
|
# Create a sample domain request
|
||||||
# Create a sample domain request
|
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.REJECTED)
|
||||||
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.REJECTED)
|
domain_request.rejection_reason = DomainRequest.RejectionReasons.DOMAIN_PURPOSE
|
||||||
domain_request.rejection_reason = DomainRequest.RejectionReasons.DOMAIN_PURPOSE
|
|
||||||
|
|
||||||
# Approve
|
# Approve
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
|
||||||
domain_request.approve()
|
domain_request.approve()
|
||||||
|
|
||||||
self.assertEqual(domain_request.status, DomainRequest.DomainRequestStatus.APPROVED)
|
self.assertEqual(domain_request.status, DomainRequest.DomainRequestStatus.APPROVED)
|
||||||
self.assertEqual(domain_request.rejection_reason, None)
|
self.assertEqual(domain_request.rejection_reason, None)
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
def test_in_review_from_rejected_clears_rejection_reason(self):
|
def test_in_review_from_rejected_clears_rejection_reason(self):
|
||||||
"""When transitioning from rejected to in_review on a domain request,
|
"""When transitioning from rejected to in_review on a domain request,
|
||||||
the rejection_reason is cleared."""
|
the rejection_reason is cleared."""
|
||||||
|
|
||||||
with less_console_noise():
|
# Create a sample domain request
|
||||||
# Create a sample domain request
|
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.REJECTED)
|
||||||
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.REJECTED)
|
domain_request.domain_is_not_active = True
|
||||||
domain_request.domain_is_not_active = True
|
domain_request.rejection_reason = DomainRequest.RejectionReasons.DOMAIN_PURPOSE
|
||||||
domain_request.rejection_reason = DomainRequest.RejectionReasons.DOMAIN_PURPOSE
|
|
||||||
|
|
||||||
# Approve
|
# Approve
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
|
||||||
domain_request.in_review()
|
domain_request.in_review()
|
||||||
|
|
||||||
self.assertEqual(domain_request.status, DomainRequest.DomainRequestStatus.IN_REVIEW)
|
self.assertEqual(domain_request.status, DomainRequest.DomainRequestStatus.IN_REVIEW)
|
||||||
self.assertEqual(domain_request.rejection_reason, None)
|
self.assertEqual(domain_request.rejection_reason, None)
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
def test_action_needed_from_rejected_clears_rejection_reason(self):
|
def test_action_needed_from_rejected_clears_rejection_reason(self):
|
||||||
"""When transitioning from rejected to action_needed on a domain request,
|
"""When transitioning from rejected to action_needed on a domain request,
|
||||||
the rejection_reason is cleared."""
|
the rejection_reason is cleared."""
|
||||||
|
|
||||||
with less_console_noise():
|
# Create a sample domain request
|
||||||
# Create a sample domain request
|
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.REJECTED)
|
||||||
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.REJECTED)
|
domain_request.domain_is_not_active = True
|
||||||
domain_request.domain_is_not_active = True
|
domain_request.rejection_reason = DomainRequest.RejectionReasons.DOMAIN_PURPOSE
|
||||||
domain_request.rejection_reason = DomainRequest.RejectionReasons.DOMAIN_PURPOSE
|
|
||||||
|
|
||||||
# Approve
|
# Approve
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client):
|
||||||
domain_request.action_needed()
|
domain_request.action_needed()
|
||||||
|
|
||||||
self.assertEqual(domain_request.status, DomainRequest.DomainRequestStatus.ACTION_NEEDED)
|
self.assertEqual(domain_request.status, DomainRequest.DomainRequestStatus.ACTION_NEEDED)
|
||||||
self.assertEqual(domain_request.rejection_reason, None)
|
self.assertEqual(domain_request.rejection_reason, None)
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
def test_has_rationale_returns_true(self):
|
def test_has_rationale_returns_true(self):
|
||||||
"""has_rationale() returns true when a domain request has no_other_contacts_rationale"""
|
"""has_rationale() returns true when a domain request has no_other_contacts_rationale"""
|
||||||
with less_console_noise():
|
self.started_domain_request.no_other_contacts_rationale = "You talkin' to me?"
|
||||||
self.started_domain_request.no_other_contacts_rationale = "You talkin' to me?"
|
self.started_domain_request.save()
|
||||||
self.started_domain_request.save()
|
self.assertEquals(self.started_domain_request.has_rationale(), True)
|
||||||
self.assertEquals(self.started_domain_request.has_rationale(), True)
|
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
def test_has_rationale_returns_false(self):
|
def test_has_rationale_returns_false(self):
|
||||||
"""has_rationale() returns false when a domain request has no no_other_contacts_rationale"""
|
"""has_rationale() returns false when a domain request has no no_other_contacts_rationale"""
|
||||||
with less_console_noise():
|
self.assertEquals(self.started_domain_request.has_rationale(), False)
|
||||||
self.assertEquals(self.started_domain_request.has_rationale(), False)
|
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
def test_has_other_contacts_returns_true(self):
|
def test_has_other_contacts_returns_true(self):
|
||||||
"""has_other_contacts() returns true when a domain request has other_contacts"""
|
"""has_other_contacts() returns true when a domain request has other_contacts"""
|
||||||
with less_console_noise():
|
# completed_domain_request has other contacts by default
|
||||||
# completed_domain_request has other contacts by default
|
self.assertEquals(self.started_domain_request.has_other_contacts(), True)
|
||||||
self.assertEquals(self.started_domain_request.has_other_contacts(), True)
|
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
def test_has_other_contacts_returns_false(self):
|
def test_has_other_contacts_returns_false(self):
|
||||||
"""has_other_contacts() returns false when a domain request has no other_contacts"""
|
"""has_other_contacts() returns false when a domain request has no other_contacts"""
|
||||||
with less_console_noise():
|
domain_request = completed_domain_request(
|
||||||
domain_request = completed_domain_request(
|
status=DomainRequest.DomainRequestStatus.STARTED, name="no-others.gov", has_other_contacts=False
|
||||||
status=DomainRequest.DomainRequestStatus.STARTED, name="no-others.gov", has_other_contacts=False
|
)
|
||||||
)
|
self.assertEquals(domain_request.has_other_contacts(), False)
|
||||||
self.assertEquals(domain_request.has_other_contacts(), False)
|
|
||||||
|
|
||||||
|
|
||||||
class TestPermissions(TestCase):
|
class TestPermissions(TestCase):
|
||||||
|
@ -1072,8 +1074,13 @@ class TestInvitations(TestCase):
|
||||||
self.invitation, _ = DomainInvitation.objects.get_or_create(email=self.email, domain=self.domain)
|
self.invitation, _ = DomainInvitation.objects.get_or_create(email=self.email, domain=self.domain)
|
||||||
self.user, _ = User.objects.get_or_create(email=self.email)
|
self.user, _ = User.objects.get_or_create(email=self.email)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
super().tearDown()
|
||||||
# clean out the roles each time
|
# clean out the roles each time
|
||||||
UserDomainRole.objects.all().delete()
|
UserDomainRole.objects.all().delete()
|
||||||
|
self.domain.delete()
|
||||||
|
self.invitation.delete()
|
||||||
|
User.objects.all().delete()
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_retrieval_creates_role(self):
|
def test_retrieval_creates_role(self):
|
||||||
|
@ -1630,17 +1637,16 @@ class TestDomainInformationCustomSave(TestCase):
|
||||||
|
|
||||||
|
|
||||||
class TestDomainRequestIncomplete(TestCase):
|
class TestDomainRequestIncomplete(TestCase):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
cls.factory = RequestFactory()
|
||||||
|
cls.user = create_test_user()
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.factory = RequestFactory()
|
|
||||||
username = "test_user"
|
|
||||||
first_name = "First"
|
|
||||||
last_name = "Last"
|
|
||||||
email = "info@example.com"
|
|
||||||
self.user = get_user_model().objects.create(
|
|
||||||
username=username, first_name=first_name, last_name=last_name, email=email
|
|
||||||
)
|
|
||||||
so, _ = Contact.objects.get_or_create(
|
so, _ = Contact.objects.get_or_create(
|
||||||
first_name="Meowy",
|
first_name="Meowy",
|
||||||
last_name="Meoward",
|
last_name="Meoward",
|
||||||
|
@ -1698,6 +1704,11 @@ class TestDomainRequestIncomplete(TestCase):
|
||||||
DomainRequest.objects.all().delete()
|
DomainRequest.objects.all().delete()
|
||||||
Contact.objects.all().delete()
|
Contact.objects.all().delete()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDownClass(cls):
|
||||||
|
super().tearDownClass()
|
||||||
|
cls.user.delete()
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_is_federal_complete(self):
|
def test_is_federal_complete(self):
|
||||||
self.assertTrue(self.domain_request._is_federal_complete())
|
self.assertTrue(self.domain_request._is_federal_complete())
|
||||||
|
|
|
@ -8,6 +8,7 @@ from api.tests.common import less_console_noise_decorator
|
||||||
from registrar.models.contact import Contact
|
from registrar.models.contact import Contact
|
||||||
from registrar.models.domain import Domain
|
from registrar.models.domain import Domain
|
||||||
from registrar.models.draft_domain import DraftDomain
|
from registrar.models.draft_domain import DraftDomain
|
||||||
|
from registrar.models.federal_agency import FederalAgency
|
||||||
from registrar.models.portfolio import Portfolio
|
from registrar.models.portfolio import Portfolio
|
||||||
from registrar.models.public_contact import PublicContact
|
from registrar.models.public_contact import PublicContact
|
||||||
from registrar.models.user import User
|
from registrar.models.user import User
|
||||||
|
@ -988,16 +989,17 @@ class PortfoliosTests(TestWithUser, WebTest):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.user.save()
|
|
||||||
self.client.force_login(self.user)
|
self.client.force_login(self.user)
|
||||||
self.domain, _ = Domain.objects.get_or_create(name="sampledomain.gov", state=Domain.State.READY)
|
self.domain, _ = Domain.objects.get_or_create(name="sampledomain.gov", state=Domain.State.READY)
|
||||||
self.role, _ = UserDomainRole.objects.get_or_create(
|
self.role, _ = UserDomainRole.objects.get_or_create(
|
||||||
user=self.user, domain=self.domain, role=UserDomainRole.Roles.MANAGER
|
user=self.user, domain=self.domain, role=UserDomainRole.Roles.MANAGER
|
||||||
)
|
)
|
||||||
self.portfolio, _ = Portfolio.objects.get_or_create(creator=self.user, organization_name="xyz inc")
|
self.federal_agency = FederalAgency.objects.create()
|
||||||
|
self.portfolio, _ = Portfolio.objects.get_or_create(creator=self.user, organization_name="xyz inc", federal_agency=self.federal_agency)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
Portfolio.objects.all().delete()
|
Portfolio.objects.all().delete()
|
||||||
|
self.federal_agency.delete()
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
PublicContact.objects.filter(domain=self.domain).delete()
|
PublicContact.objects.filter(domain=self.domain).delete()
|
||||||
UserDomainRole.objects.all().delete()
|
UserDomainRole.objects.all().delete()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue