Add email validation by using EmailField in Contact

This commit is contained in:
Neil Martinsen-Burrell 2023-06-01 14:25:40 -05:00
parent b5706c3829
commit 4623a5dfb2
No known key found for this signature in database
GPG key ID: 6A3C818CC10D0184
3 changed files with 38 additions and 1 deletions

View file

@ -0,0 +1,19 @@
# Generated by Django 4.2.1 on 2023-06-01 19:23
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("registrar", "0023_alter_contact_first_name_alter_contact_last_name_and_more"),
]
operations = [
migrations.AlterField(
model_name="contact",
name="email",
field=models.EmailField(
blank=True, db_index=True, help_text="Email", max_length=254, null=True
),
),
]

View file

@ -41,7 +41,7 @@ class Contact(TimeStampedModel):
help_text="Title",
verbose_name="title or role in your organization",
)
email = models.TextField(
email = models.EmailField(
null=True,
blank=True,
help_text="Email",

View file

@ -15,6 +15,7 @@ from registrar.forms.application_wizard import (
AnythingElseForm,
TypeOfWorkForm,
)
from registrar.forms.domain import ContactForm
class TestFormValidation(TestCase):
@ -277,3 +278,20 @@ class TestFormValidation(TestCase):
for error in form.non_field_errors()
)
)
class TestContactForm(TestCase):
def test_contact_form_email_invalid(self):
form = ContactForm(data={"email": "example.net"})
self.assertEqual(
form.errors["email"],
["Enter a valid email address."]
)
def test_contact_form_email_invalid2(self):
form = ContactForm(data={"email": "@"})
self.assertEqual(
form.errors["email"],
["Enter a valid email address."]
)