Although a passing test exists for the email validation method of my form, when I run coverage, it reports that the method has not been tested. What am I doing wrong?
**Form**
class SignUpForm(forms.ModelForm):
email = forms.EmailField(max_length=254,
error_messages={'invalid': 'Please enter a valid email address.'},
label=_('Email address'),
widget=forms.EmailInput(attrs={'class': 'form-control mb-4',
}))
full_name = forms.CharField(max_length=254,
error_messages={'required': 'Please enter your full name.'},
label=_('Full name'),
widget=forms.TextInput(attrs={'class': 'form-control mb-4',
}))
password = forms.CharField(label=_('Password'),
widget=forms.PasswordInput(attrs={'class': 'form-control mb-4',
'autocomplete': 'new-password',
'id': 'psw',
}))
class Meta:
model = CustomUser
fields = ('full_name', 'email', 'password')
def clean_email(self):
email = self.cleaned_data['email']
if CustomUser.objects.filter(email=email).exists():
raise forms.ValidationError(
_('A user with that email address already exists, click this <br>'
f'<a href="{reverse("accounts:login")}">'
'Password Reset</a> link to recover your account.'),
code='email_already_exists',
)
return email
**Test**
class SignUpFormTest(TestCase):
def setUp(self):
self.email = "testclient@example.com"
self.full_name = "test user"
self.password = "Ajkklwe1"
get_user_model().objects.create_user(self.email, self.full_name, self.password)
def test_user_already_exists(self):
data = {"email": self.email,
"full_name": self.full_name,
"password": self.password,
}
form = SignUpForm(data)
self.assertFalse(form.is_valid())
self.assertTrue(form.has_error('email', code='email_already_exists'))
Coverage report: