mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-25 12:08:40 +02:00
Add email validation by using EmailField in Contact
This commit is contained in:
parent
b5706c3829
commit
4623a5dfb2
3 changed files with 38 additions and 1 deletions
19
src/registrar/migrations/0024_alter_contact_email.py
Normal file
19
src/registrar/migrations/0024_alter_contact_email.py
Normal 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
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -41,7 +41,7 @@ class Contact(TimeStampedModel):
|
||||||
help_text="Title",
|
help_text="Title",
|
||||||
verbose_name="title or role in your organization",
|
verbose_name="title or role in your organization",
|
||||||
)
|
)
|
||||||
email = models.TextField(
|
email = models.EmailField(
|
||||||
null=True,
|
null=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
help_text="Email",
|
help_text="Email",
|
||||||
|
|
|
@ -15,6 +15,7 @@ from registrar.forms.application_wizard import (
|
||||||
AnythingElseForm,
|
AnythingElseForm,
|
||||||
TypeOfWorkForm,
|
TypeOfWorkForm,
|
||||||
)
|
)
|
||||||
|
from registrar.forms.domain import ContactForm
|
||||||
|
|
||||||
|
|
||||||
class TestFormValidation(TestCase):
|
class TestFormValidation(TestCase):
|
||||||
|
@ -277,3 +278,20 @@ class TestFormValidation(TestCase):
|
||||||
for error in form.non_field_errors()
|
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."]
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue