Remove submitter from model tests

This commit is contained in:
Erin Song 2024-08-26 15:59:48 -07:00
parent 2f2b2fe10f
commit 2713e59795
No known key found for this signature in database
9 changed files with 57 additions and 118 deletions

View file

@ -1137,6 +1137,10 @@ class DomainRequest(TimeStampedModel):
# Special District -> "Election office" and "About your organization" page can't be empty
return self.is_election_board is not None and self.about_your_organization is not None
# Do we still want to test this after creator is autogenerated? Currently it went back to being selectable
def _is_creator_complete(self):
return self.creator is not None
def _is_organization_name_and_address_complete(self):
return not (
self.organization_name is None
@ -1205,7 +1209,8 @@ class DomainRequest(TimeStampedModel):
def _is_general_form_complete(self, request):
has_profile_feature_flag = flag_is_active(request, "profile_feature")
return (
self._is_organization_name_and_address_complete()
self._is_creator_complete()
and self._is_organization_name_and_address_complete()
and self._is_senior_official_complete()
and self._is_requested_domain_complete()
and self._is_purpose_complete()

View file

@ -392,7 +392,6 @@ class AuditedAdminMockData:
about_your_organization: str = "e-Government",
anything_else: str = "There is more",
senior_official: Contact = self.dummy_contact(item_name, "senior_official"),
submitter: Contact = self.dummy_contact(item_name, "submitter"),
creator: User = self.dummy_user(item_name, "creator"),
}
""" # noqa
@ -410,7 +409,6 @@ class AuditedAdminMockData:
about_your_organization="e-Government",
anything_else="There is more",
senior_official=self.dummy_contact(item_name, "senior_official"),
submitter=self.dummy_contact(item_name, "submitter"),
creator=creator,
)
return common_args
@ -897,7 +895,6 @@ def completed_domain_request( # noqa
has_cisa_representative=True,
status=DomainRequest.DomainRequestStatus.STARTED,
user=False,
submitter=False,
name="city.gov",
investigator=None,
generic_org_type="federal",
@ -921,14 +918,14 @@ def completed_domain_request( # noqa
domain, _ = DraftDomain.objects.get_or_create(name=name)
alt, _ = Website.objects.get_or_create(website="city1.gov")
current, _ = Website.objects.get_or_create(website="city.com")
if not submitter:
submitter, _ = Contact.objects.get_or_create(
first_name="Testy2",
last_name="Tester2",
title="Admin Tester",
email="mayor@igorville.gov",
phone="(555) 555 5556",
)
# if not creator:
# creator, _ = Contact.objects.get_or_create(
# first_name="Testy2",
# last_name="Tester2",
# title="Admin Tester",
# email="mayor@igorville.gov",
# phone="(555) 555 5556",
# )
other, _ = Contact.objects.get_or_create(
first_name="Testy",
last_name="Tester",
@ -957,7 +954,6 @@ def completed_domain_request( # noqa
zipcode="10002",
senior_official=so,
requested_domain=domain,
submitter=submitter,
creator=user,
status=status,
investigator=investigator,

View file

@ -380,7 +380,7 @@ class TestDomainInformationAdmin(TestCase):
contact, _ = Contact.objects.get_or_create(first_name="Henry", last_name="McFakerson")
domain_request = completed_domain_request(
submitter=contact, name="city1244.gov", status=DomainRequest.DomainRequestStatus.IN_REVIEW
name="city1244.gov", status=DomainRequest.DomainRequestStatus.IN_REVIEW
)
domain_request.approve()
@ -505,7 +505,6 @@ class TestDomainInformationAdmin(TestCase):
# These should exist in the response
expected_values = [
("creator", "Person who submitted the domain request"),
("submitter", 'Person listed under "your contact information" in the request form'),
("domain_request", "Request associated with this domain"),
("no_other_contacts_rationale", "Required if creator does not list other employees"),
("urbanization", "Required for Puerto Rico only"),
@ -629,16 +628,6 @@ class TestDomainInformationAdmin(TestCase):
# Check for the field itself
self.assertContains(response, "Meoward Jones")
# == Check for the submitter == #
self.assertContains(response, "mayor@igorville.gov", count=2)
expected_submitter_fields = [
# Field, expected value
("title", "Admin Tester"),
("phone", "(555) 555 5556"),
]
self.test_helper.assert_response_contains_distinct_values(response, expected_submitter_fields)
self.assertContains(response, "Testy2 Tester2")
# == Check for the senior_official == #
self.assertContains(response, "testy@town.com", count=2)
expected_so_fields = [
@ -684,7 +673,6 @@ class TestDomainInformationAdmin(TestCase):
"more_organization_information",
"domain",
"domain_request",
"submitter",
"no_other_contacts_rationale",
"anything_else",
"is_policy_acknowledged",
@ -703,19 +691,19 @@ class TestDomainInformationAdmin(TestCase):
# Assert that sorting in reverse works correctly
self.test_helper.assert_table_sorted("-1", ("-domain__name",))
def test_submitter_sortable(self):
"""Tests if DomainInformation sorts by submitter correctly"""
def test_creator_sortable(self):
"""Tests if DomainInformation sorts by creator correctly"""
with less_console_noise():
self.client.force_login(self.superuser)
# Assert that our sort works correctly
self.test_helper.assert_table_sorted(
"4",
("submitter__first_name", "submitter__last_name"),
("creator__first_name", "creator__last_name"),
)
# Assert that sorting in reverse works correctly
self.test_helper.assert_table_sorted("-4", ("-submitter__first_name", "-submitter__last_name"))
self.test_helper.assert_table_sorted("-4", ("-creator__first_name", "-creator__last_name"))
class TestUserDomainRoleAdmin(TestCase):
@ -1298,7 +1286,6 @@ class AuditedAdminTest(TestCase):
# Senior offical is commented out for now - this is alphabetized
# and this test does not accurately reflect that.
# DomainRequest.senior_official.field,
DomainRequest.submitter.field,
# DomainRequest.investigator.field,
DomainRequest.creator.field,
DomainRequest.requested_domain.field,
@ -1358,7 +1345,6 @@ class AuditedAdminTest(TestCase):
# Senior offical is commented out for now - this is alphabetized
# and this test does not accurately reflect that.
# DomainInformation.senior_official.field,
DomainInformation.submitter.field,
# DomainInformation.creator.field,
(DomainInformation.domain.field, ["name"]),
(DomainInformation.domain_request.field, ["requested_domain__name"]),
@ -1680,10 +1666,10 @@ class TestContactAdmin(TestCase):
)
# join it to 4 domain requests.
domain_request1 = completed_domain_request(submitter=contact, name="city1.gov")
domain_request2 = completed_domain_request(submitter=contact, name="city2.gov")
domain_request3 = completed_domain_request(submitter=contact, name="city3.gov")
domain_request4 = completed_domain_request(submitter=contact, name="city4.gov")
domain_request1 = completed_domain_request(name="city1.gov")
domain_request2 = completed_domain_request(name="city2.gov")
domain_request3 = completed_domain_request(name="city3.gov")
domain_request4 = completed_domain_request(name="city4.gov")
with patch("django.contrib.messages.warning") as mock_warning:
# Use the test client to simulate the request
@ -1720,12 +1706,12 @@ class TestContactAdmin(TestCase):
first_name="Henry",
last_name="McFakerson",
)
domain_request1 = completed_domain_request(submitter=contact, name="city1.gov")
domain_request2 = completed_domain_request(submitter=contact, name="city2.gov")
domain_request3 = completed_domain_request(submitter=contact, name="city3.gov")
domain_request4 = completed_domain_request(submitter=contact, name="city4.gov")
domain_request5 = completed_domain_request(submitter=contact, name="city5.gov")
completed_domain_request(submitter=contact, name="city6.gov")
domain_request1 = completed_domain_request(name="city1.gov")
domain_request2 = completed_domain_request(name="city2.gov")
domain_request3 = completed_domain_request(name="city3.gov")
domain_request4 = completed_domain_request(name="city4.gov")
domain_request5 = completed_domain_request(name="city5.gov")
completed_domain_request(name="city6.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]))

View file

@ -423,13 +423,6 @@ class TestDomainAdminWithClient(TestCase):
# Check for the field itself
self.assertContains(response, "Meoward Jones")
# == Check for the submitter == #
self.assertContains(response, "mayor@igorville.gov")
self.assertContains(response, "Admin Tester")
self.assertContains(response, "(555) 555 5556")
self.assertContains(response, "Testy2 Tester2")
# == Check for the senior_official == #
self.assertContains(response, "testy@town.com")
self.assertContains(response, "Chief Tester")

View file

@ -94,7 +94,7 @@ class TestDomainRequestAdmin(MockEppLib):
SeniorOfficial.objects.get_or_create(first_name="Zoup", last_name="Soup", title="title")
contact, _ = Contact.objects.get_or_create(first_name="Henry", last_name="McFakerson")
domain_request = completed_domain_request(submitter=contact, name="city1.gov")
domain_request = completed_domain_request(name="city1.gov")
request = self.factory.post("/admin/registrar/domainrequest/{}/change/".format(domain_request.pk))
model_admin = AuditedAdmin(DomainRequest, self.site)
@ -150,10 +150,6 @@ class TestDomainRequestAdmin(MockEppLib):
# These should exist in the response
expected_values = [
("creator", "Person who submitted the domain request; will not receive email updates"),
(
"submitter",
'Person listed under "your contact information" in the request form; will receive email updates',
),
("approved_domain", "Domain associated with this request; will be blank until request is approved"),
("no_other_contacts_rationale", "Required if creator does not list other employees"),
("alternative_domains", "Other domain names the creator provided for consideration"),
@ -409,8 +405,8 @@ class TestDomainRequestAdmin(MockEppLib):
self.test_helper.assert_table_sorted("-1", ("-requested_domain__name",))
@less_console_noise_decorator
def test_submitter_sortable(self):
"""Tests if the DomainRequest sorts by submitter correctly"""
def test_creator_sortable(self):
"""Tests if the DomainRequest sorts by creator correctly"""
self.client.force_login(self.superuser)
multiple_unalphabetical_domain_objects("domain_request")
@ -424,8 +420,8 @@ class TestDomainRequestAdmin(MockEppLib):
self.test_helper.assert_table_sorted(
"11",
(
"submitter__first_name",
"submitter__last_name",
"creator__first_name",
"creator__last_name",
),
)
@ -433,8 +429,8 @@ class TestDomainRequestAdmin(MockEppLib):
self.test_helper.assert_table_sorted(
"-11",
(
"-submitter__first_name",
"-submitter__last_name",
"-creator__first_name",
"-creator__last_name",
),
)
@ -1381,16 +1377,6 @@ class TestDomainRequestAdmin(MockEppLib):
# Check for the field itself
self.assertContains(response, "Meoward Jones")
# == Check for the submitter == #
self.assertContains(response, "mayor@igorville.gov", count=2)
expected_submitter_fields = [
# Field, expected value
("title", "Admin Tester"),
("phone", "(555) 555 5556"),
]
self.test_helper.assert_response_contains_distinct_values(response, expected_submitter_fields)
self.assertContains(response, "Testy2 Tester2")
# == Check for the senior_official == #
self.assertContains(response, "testy@town.com", count=2)
expected_so_fields = [
@ -1546,7 +1532,6 @@ class TestDomainRequestAdmin(MockEppLib):
"senior_official",
"approved_domain",
"requested_domain",
"submitter",
"purpose",
"no_other_contacts_rationale",
"anything_else",
@ -1583,7 +1568,6 @@ class TestDomainRequestAdmin(MockEppLib):
"approved_domain",
"alternative_domains",
"purpose",
"submitter",
"no_other_contacts_rationale",
"anything_else",
"is_policy_acknowledged",

View file

@ -168,7 +168,6 @@ class TestDomainRequest(TestCase):
zipcode="12345-6789",
senior_official=contact,
requested_domain=domain,
submitter=contact,
purpose="Igorville rules!",
anything_else="All of Igorville loves the dotgov program.",
is_policy_acknowledged=True,
@ -195,7 +194,6 @@ class TestDomainRequest(TestCase):
state_territory="CA",
zipcode="12345-6789",
senior_official=contact,
submitter=contact,
purpose="Igorville rules!",
anything_else="All of Igorville loves the dotgov program.",
is_policy_acknowledged=True,
@ -258,7 +256,7 @@ class TestDomainRequest(TestCase):
@less_console_noise_decorator
def test_submit_from_started_sends_email(self):
msg = "Create a domain request and submit it and see if email was sent."
domain_request = completed_domain_request(submitter=self.dummy_user, user=self.dummy_user_2)
domain_request = completed_domain_request(user=self.dummy_user_2)
self.check_email_sent(domain_request, msg, "submit", 1, expected_content="Hello")
@override_flag("profile_feature", active=True)
@ -266,7 +264,7 @@ class TestDomainRequest(TestCase):
def test_submit_from_started_sends_email_to_creator(self):
"""Tests if, when the profile feature flag is on, we send an email to the creator"""
msg = "Create a domain request and submit it and see if email was sent when the feature flag is on."
domain_request = completed_domain_request(submitter=self.dummy_user, user=self.dummy_user_2)
domain_request = completed_domain_request(user=self.dummy_user_2)
self.check_email_sent(
domain_request, msg, "submit", 1, expected_content="Lava", expected_email="intern@igorville.com"
)
@ -275,7 +273,7 @@ class TestDomainRequest(TestCase):
def test_submit_from_withdrawn_sends_email(self):
msg = "Create a withdrawn domain request and submit it and see if email was sent."
domain_request = completed_domain_request(
status=DomainRequest.DomainRequestStatus.WITHDRAWN, submitter=self.dummy_user
status=DomainRequest.DomainRequestStatus.WITHDRAWN
)
self.check_email_sent(domain_request, msg, "submit", 1, expected_content="Hello")
@ -294,25 +292,19 @@ class TestDomainRequest(TestCase):
@less_console_noise_decorator
def test_approve_sends_email(self):
msg = "Create a domain request and approve it and see if email was sent."
domain_request = completed_domain_request(
status=DomainRequest.DomainRequestStatus.IN_REVIEW, submitter=self.dummy_user
)
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW)
self.check_email_sent(domain_request, msg, "approve", 1, expected_content="Hello")
@less_console_noise_decorator
def test_withdraw_sends_email(self):
msg = "Create a domain request and withdraw it and see if email was sent."
domain_request = completed_domain_request(
status=DomainRequest.DomainRequestStatus.IN_REVIEW, submitter=self.dummy_user
)
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW)
self.check_email_sent(domain_request, msg, "withdraw", 1, expected_content="Hello")
@less_console_noise_decorator
def test_reject_sends_email(self):
msg = "Create a domain request and reject it and see if email was sent."
domain_request = completed_domain_request(
status=DomainRequest.DomainRequestStatus.APPROVED, submitter=self.dummy_user
)
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.APPROVED)
self.check_email_sent(domain_request, msg, "reject", 1, expected_content="Hello")
@less_console_noise_decorator
@ -1877,7 +1869,6 @@ class TestDomainRequestIncomplete(TestCase):
senior_official=so,
requested_domain=draft_domain,
purpose="Some purpose",
submitter=you,
no_other_contacts_rationale=None,
has_cisa_representative=True,
cisa_representative_email="somerep@cisa.com",
@ -2007,11 +1998,11 @@ class TestDomainRequestIncomplete(TestCase):
self.assertFalse(self.domain_request._is_purpose_complete())
@less_console_noise_decorator
def test_is_submitter_complete(self):
self.assertTrue(self.domain_request._is_submitter_complete())
self.domain_request.submitter = None
def test_is_creator_complete(self):
self.assertTrue(self.domain_request._is_creator_complete())
self.domain_request.creator = None
self.domain_request.save()
self.assertFalse(self.domain_request._is_submitter_complete())
self.assertFalse(self.domain_request._is_creator_complete())
@less_console_noise_decorator
def test_is_other_contacts_complete_missing_one_field(self):

View file

@ -381,7 +381,6 @@ class HomeTests(TestWithUser):
requested_domain=site,
status=DomainRequest.DomainRequestStatus.WITHDRAWN,
senior_official=contact,
submitter=contact_user,
)
domain_request.other_contacts.set([contact_2])
@ -392,7 +391,6 @@ class HomeTests(TestWithUser):
requested_domain=site_2,
status=DomainRequest.DomainRequestStatus.STARTED,
senior_official=contact_2,
submitter=contact_shared,
)
domain_request_2.other_contacts.set([contact_shared])
@ -455,7 +453,6 @@ class HomeTests(TestWithUser):
requested_domain=site,
status=DomainRequest.DomainRequestStatus.WITHDRAWN,
senior_official=contact,
submitter=contact_user,
)
domain_request.other_contacts.set([contact_2])
@ -466,7 +463,6 @@ class HomeTests(TestWithUser):
requested_domain=site_2,
status=DomainRequest.DomainRequestStatus.STARTED,
senior_official=contact_2,
submitter=contact_shared,
)
domain_request_2.other_contacts.set([contact_shared])
@ -1038,7 +1034,6 @@ class UserProfileTests(TestWithUser, WebTest):
requested_domain=site,
status=DomainRequest.DomainRequestStatus.SUBMITTED,
senior_official=contact_user,
submitter=contact_user,
)
with override_flag("profile_feature", active=True):
response = self.client.get(f"/domain-request/{domain_request.id}", follow=True)
@ -1060,7 +1055,6 @@ class UserProfileTests(TestWithUser, WebTest):
requested_domain=site,
status=DomainRequest.DomainRequestStatus.SUBMITTED,
senior_official=contact_user,
submitter=contact_user,
)
with override_flag("profile_feature", active=False):
response = self.client.get(f"/domain-request/{domain_request.id}", follow=True)

View file

@ -368,11 +368,11 @@ class DomainRequestTests(TestWithUser, WebTest):
your_contact_result = your_contact_form.submit()
# validate that data from this step are being saved
domain_request = DomainRequest.objects.get() # there's only one
self.assertEqual(domain_request.submitter.first_name, "Testy you")
self.assertEqual(domain_request.submitter.last_name, "Tester you")
self.assertEqual(domain_request.submitter.title, "Admin Tester")
self.assertEqual(domain_request.submitter.email, "testy-admin@town.com")
self.assertEqual(domain_request.submitter.phone, "(201) 555 5556")
self.assertEqual(domain_request.creator.first_name, self.user.first_name)
self.assertEqual(domain_request.creator.last_name, self.user.last_name)
self.assertEqual(domain_request.creator.title, self.user.title)
self.assertEqual(domain_request.creator.email, self.user.email)
self.assertEqual(domain_request.creator.phone, self.user.phone)
# the post request should return a redirect to the next form in
# the domain request page
self.assertEqual(your_contact_result.status_code, 302)
@ -1643,7 +1643,6 @@ class DomainRequestTests(TestWithUser, WebTest):
state_territory="NY",
zipcode="10002",
senior_official=so,
submitter=you,
creator=self.user,
status="started",
)
@ -1780,7 +1779,6 @@ class DomainRequestTests(TestWithUser, WebTest):
state_territory="NY",
zipcode="10002",
senior_official=so,
submitter=you,
creator=self.user,
status="started",
)
@ -1855,7 +1853,6 @@ class DomainRequestTests(TestWithUser, WebTest):
state_territory="NY",
zipcode="10002",
senior_official=so,
submitter=you,
creator=self.user,
status="started",
)
@ -1933,7 +1930,6 @@ class DomainRequestTests(TestWithUser, WebTest):
state_territory="NY",
zipcode="10002",
senior_official=so,
submitter=you,
creator=self.user,
status="started",
)
@ -2010,7 +2006,6 @@ class DomainRequestTests(TestWithUser, WebTest):
state_territory="NY",
zipcode="10002",
senior_official=so,
submitter=you,
creator=self.user,
status="started",
)
@ -2086,7 +2081,6 @@ class DomainRequestTests(TestWithUser, WebTest):
state_territory="NY",
zipcode="10002",
senior_official=so,
submitter=you,
creator=self.user,
status="started",
)
@ -2297,7 +2291,6 @@ class DomainRequestTests(TestWithUser, WebTest):
address_line1="address 1",
state_territory="NY",
zipcode="10002",
submitter=you,
creator=self.user,
status="started",
)
@ -2363,7 +2356,6 @@ class DomainRequestTests(TestWithUser, WebTest):
address_line1="address 1",
state_territory="NY",
zipcode="10002",
submitter=submitter,
creator=self.user,
status="started",
)
@ -2729,7 +2721,6 @@ class DomainRequestTests(TestWithUser, WebTest):
zipcode="10002",
senior_official=so,
requested_domain=domain,
submitter=you,
creator=self.user,
)
domain_request.other_contacts.add(other)
@ -3072,7 +3063,6 @@ class TestWizardUnlockingSteps(TestWithUser, WebTest):
requested_domain=site,
status=DomainRequest.DomainRequestStatus.WITHDRAWN,
senior_official=contact,
submitter=contact_user,
)
domain_request.other_contacts.set([contact_2])

View file

@ -81,12 +81,12 @@ class OrderableFieldsMixin:
Or for fields with multiple order_fields:
```
def get_sortable_submitter(self, obj):
return obj.submitter
def get_sortable_creator(self, obj):
return obj.creator
# Allows column order sorting
get_sortable_submitter.admin_order_field = ["submitter__first_name", "submitter__last_name"]
get_sortable_creator.admin_order_field = ["creator__first_name", "creaotr__last_name"]
# Sets column's header
get_sortable_submitter.short_description = "submitter"
get_sortable_creator.short_description = "creator"
```
Parameters:
@ -114,8 +114,8 @@ class OrderableFieldsMixin:
Returns (example):
```
def get_submitter(self, obj):
return obj.submitter
def get_creator(self, obj):
return obj.creator
```
"""
attr = getattr(obj, field)