mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-22 18:56:15 +02:00
Clean up and add unit tests
This commit is contained in:
parent
1876f08ca6
commit
b3d4631d45
4 changed files with 73 additions and 76 deletions
|
@ -1,2 +1,7 @@
|
||||||
from .application_wizard import *
|
from .application_wizard import *
|
||||||
from .domain import DomainAddUserForm, NameserverFormset, DomainSecurityEmailForm, ContactForm
|
from .domain import (
|
||||||
|
DomainAddUserForm,
|
||||||
|
NameserverFormset,
|
||||||
|
DomainSecurityEmailForm,
|
||||||
|
ContactForm,
|
||||||
|
)
|
||||||
|
|
|
@ -54,21 +54,13 @@ class ContactForm(forms.ModelForm):
|
||||||
# the database fields have blank=True so ModelForm doesn't create
|
# the database fields have blank=True so ModelForm doesn't create
|
||||||
# required fields by default. Use this list in __init__ to mark each
|
# required fields by default. Use this list in __init__ to mark each
|
||||||
# of these fields as required
|
# of these fields as required
|
||||||
required = [
|
required = ["first_name", "last_name", "title", "email", "phone"]
|
||||||
"first_name",
|
|
||||||
"last_name",
|
|
||||||
"title",
|
|
||||||
"email",
|
|
||||||
"phone"
|
|
||||||
]
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
# take off maxlength attribute for the phone number field
|
# take off maxlength attribute for the phone number field
|
||||||
# which interferes with out input_with_errors template tag
|
# which interferes with out input_with_errors template tag
|
||||||
self.fields['phone'].widget.attrs.pop('maxlength', None)
|
self.fields["phone"].widget.attrs.pop("maxlength", None)
|
||||||
|
|
||||||
for field_name in self.required:
|
for field_name in self.required:
|
||||||
self.fields[field_name].required = True
|
self.fields[field_name].required = True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import boto3_mocking # type: ignore
|
||||||
from registrar.models import (
|
from registrar.models import (
|
||||||
DomainApplication,
|
DomainApplication,
|
||||||
Domain,
|
Domain,
|
||||||
|
DomainInformation,
|
||||||
DomainInvitation,
|
DomainInvitation,
|
||||||
Contact,
|
Contact,
|
||||||
Website,
|
Website,
|
||||||
|
@ -1029,12 +1030,16 @@ class TestWithDomainPermissions(TestWithUser):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
self.domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
||||||
|
self.domain_information, _ = DomainInformation.objects.get_or_create(
|
||||||
|
creator=self.user, domain=self.domain
|
||||||
|
)
|
||||||
self.role, _ = UserDomainRole.objects.get_or_create(
|
self.role, _ = UserDomainRole.objects.get_or_create(
|
||||||
user=self.user, domain=self.domain, role=UserDomainRole.Roles.ADMIN
|
user=self.user, domain=self.domain, role=UserDomainRole.Roles.ADMIN
|
||||||
)
|
)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
try:
|
try:
|
||||||
|
self.domain_information.delete()
|
||||||
self.domain.delete()
|
self.domain.delete()
|
||||||
self.role.delete()
|
self.role.delete()
|
||||||
except ValueError: # pass if already deleted
|
except ValueError: # pass if already deleted
|
||||||
|
@ -1045,26 +1050,16 @@ class TestWithDomainPermissions(TestWithUser):
|
||||||
class TestDomainPermissions(TestWithDomainPermissions):
|
class TestDomainPermissions(TestWithDomainPermissions):
|
||||||
def test_not_logged_in(self):
|
def test_not_logged_in(self):
|
||||||
"""Not logged in gets a redirect to Login."""
|
"""Not logged in gets a redirect to Login."""
|
||||||
response = self.client.get(reverse("domain", kwargs={"pk": self.domain.id}))
|
for view_name in [
|
||||||
self.assertEqual(response.status_code, 302)
|
"domain",
|
||||||
|
"domain-users",
|
||||||
|
"domain-users-add",
|
||||||
|
"domain-nameservers",
|
||||||
|
"domain-your-contact-information" "domain-security-email",
|
||||||
|
]:
|
||||||
|
with self.subTest(view_name=view_name):
|
||||||
response = self.client.get(
|
response = self.client.get(
|
||||||
reverse("domain-users", kwargs={"pk": self.domain.id})
|
reverse(view_name, kwargs={"pk": self.domain.id})
|
||||||
)
|
|
||||||
self.assertEqual(response.status_code, 302)
|
|
||||||
|
|
||||||
response = self.client.get(
|
|
||||||
reverse("domain-users-add", kwargs={"pk": self.domain.id})
|
|
||||||
)
|
|
||||||
self.assertEqual(response.status_code, 302)
|
|
||||||
|
|
||||||
response = self.client.get(
|
|
||||||
reverse("domain-nameservers", kwargs={"pk": self.domain.id})
|
|
||||||
)
|
|
||||||
self.assertEqual(response.status_code, 302)
|
|
||||||
|
|
||||||
response = self.client.get(
|
|
||||||
reverse("domain-security-email", kwargs={"pk": self.domain.id})
|
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 302)
|
self.assertEqual(response.status_code, 302)
|
||||||
|
|
||||||
|
@ -1073,25 +1068,17 @@ class TestDomainPermissions(TestWithDomainPermissions):
|
||||||
self.client.force_login(self.user)
|
self.client.force_login(self.user)
|
||||||
self.role.delete() # user no longer has a role on this domain
|
self.role.delete() # user no longer has a role on this domain
|
||||||
|
|
||||||
with less_console_noise():
|
for view_name in [
|
||||||
response = self.client.get(reverse("domain", kwargs={"pk": self.domain.id}))
|
"domain",
|
||||||
self.assertEqual(response.status_code, 403)
|
"domain-users",
|
||||||
|
"domain-users-add",
|
||||||
|
"domain-nameservers",
|
||||||
|
"domain-your-contact-information" "domain-security-email",
|
||||||
|
]:
|
||||||
|
with self.subTest(view_name=view_name):
|
||||||
with less_console_noise():
|
with less_console_noise():
|
||||||
response = self.client.get(
|
response = self.client.get(
|
||||||
reverse("domain-users", kwargs={"pk": self.domain.id})
|
reverse(view_name, kwargs={"pk": self.domain.id})
|
||||||
)
|
|
||||||
self.assertEqual(response.status_code, 403)
|
|
||||||
|
|
||||||
with less_console_noise():
|
|
||||||
response = self.client.get(
|
|
||||||
reverse("domain-users-add", kwargs={"pk": self.domain.id})
|
|
||||||
)
|
|
||||||
self.assertEqual(response.status_code, 403)
|
|
||||||
|
|
||||||
with less_console_noise():
|
|
||||||
response = self.client.get(
|
|
||||||
reverse("domain-nameservers", kwargs={"pk": self.domain.id})
|
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
@ -1287,6 +1274,23 @@ class TestDomainDetail(TestWithDomainPermissions, WebTest):
|
||||||
# the field.
|
# the field.
|
||||||
self.assertContains(result, "This field is required", count=2, status_code=200)
|
self.assertContains(result, "This field is required", count=2, status_code=200)
|
||||||
|
|
||||||
|
def test_domain_your_contact_information(self):
|
||||||
|
"""Can load domain's your contact information page."""
|
||||||
|
page = self.client.get(
|
||||||
|
reverse("domain-your-contact-information", kwargs={"pk": self.domain.id})
|
||||||
|
)
|
||||||
|
self.assertContains(page, "Domain contact information")
|
||||||
|
|
||||||
|
def test_domain_your_contact_information(self):
|
||||||
|
"""Your contact information appears on the page."""
|
||||||
|
self.domain_information.submitter = Contact(first_name="Testy")
|
||||||
|
self.domain_information.submitter.save()
|
||||||
|
self.domain_information.save()
|
||||||
|
page = self.app.get(
|
||||||
|
reverse("domain-your-contact-information", kwargs={"pk": self.domain.id})
|
||||||
|
)
|
||||||
|
self.assertContains(page, "Testy")
|
||||||
|
|
||||||
def test_domain_security_email(self):
|
def test_domain_security_email(self):
|
||||||
"""Can load domain's security email page."""
|
"""Can load domain's security email page."""
|
||||||
page = self.client.get(
|
page = self.client.get(
|
||||||
|
|
|
@ -10,9 +10,20 @@ from django.urls import reverse
|
||||||
from django.views.generic import DetailView
|
from django.views.generic import DetailView
|
||||||
from django.views.generic.edit import DeleteView, FormMixin
|
from django.views.generic.edit import DeleteView, FormMixin
|
||||||
|
|
||||||
from registrar.models import Domain, DomainInvitation, User, UserDomainRole, DomainInformation
|
from registrar.models import (
|
||||||
|
Domain,
|
||||||
|
DomainInvitation,
|
||||||
|
User,
|
||||||
|
UserDomainRole,
|
||||||
|
DomainInformation,
|
||||||
|
)
|
||||||
|
|
||||||
from ..forms import DomainAddUserForm, NameserverFormset, DomainSecurityEmailForm, ContactForm
|
from ..forms import (
|
||||||
|
DomainAddUserForm,
|
||||||
|
NameserverFormset,
|
||||||
|
DomainSecurityEmailForm,
|
||||||
|
ContactForm,
|
||||||
|
)
|
||||||
from ..utility.email import send_templated_email, EmailSendingError
|
from ..utility.email import send_templated_email, EmailSendingError
|
||||||
from .utility import DomainPermission
|
from .utility import DomainPermission
|
||||||
|
|
||||||
|
@ -105,18 +116,6 @@ class DomainYourContactInformationView(DomainPermission, FormMixin, DetailView):
|
||||||
context_object_name = "domain"
|
context_object_name = "domain"
|
||||||
form_class = ContactForm
|
form_class = ContactForm
|
||||||
|
|
||||||
# def get_initial(self):
|
|
||||||
# """The initial value for the form."""
|
|
||||||
# domainInformation = self.get_object()
|
|
||||||
# initial = super().get_initial()
|
|
||||||
# initial["first_name"] = domainInformation.submitter.first_name
|
|
||||||
# initial["middle_name"] = domainInformation.submitter.middle_name
|
|
||||||
# initial["last_name"] = domainInformation.submitter.last_name
|
|
||||||
# initial["title"] = domainInformation.submitter.title
|
|
||||||
# initial["email"] = domainInformation.submitter.email
|
|
||||||
# initial["phone"] = domainInformation.submitter.phone
|
|
||||||
# return initial
|
|
||||||
|
|
||||||
def get_form_kwargs(self, *args, **kwargs):
|
def get_form_kwargs(self, *args, **kwargs):
|
||||||
"""Add domain_info.submitter instance to make a bound form."""
|
"""Add domain_info.submitter instance to make a bound form."""
|
||||||
form_kwargs = super().get_form_kwargs(*args, **kwargs)
|
form_kwargs = super().get_form_kwargs(*args, **kwargs)
|
||||||
|
@ -141,9 +140,6 @@ class DomainYourContactInformationView(DomainPermission, FormMixin, DetailView):
|
||||||
"""The form is valid, call setter in model."""
|
"""The form is valid, call setter in model."""
|
||||||
|
|
||||||
# Post to DB using values from the form
|
# Post to DB using values from the form
|
||||||
# new_email = form.cleaned_data["security_email"]
|
|
||||||
# domain = self.get_object()
|
|
||||||
# domain.set_security_email(new_email)
|
|
||||||
domain = self.get_object()
|
domain = self.get_object()
|
||||||
form.save()
|
form.save()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue