def test_password_mismatch(self): # Set confirm password field to a different value data = self.valid_user data['password2'] = '54321' form = EmployeeRegistrationForm(data) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['password2'][0], 'The two password fields didn’t match.')
def test_field_required(self): form = EmployeeRegistrationForm(data={}) self.assertEqual(form.errors["gender"], ["Gender is required"]) self.assertEqual(form.errors["email"], ["This field is required."]) self.assertEqual(form.errors["password1"], ["This field is required."]) self.assertEqual(form.errors["password2"], ["This field is required."])
def setUp(self) -> None: self.form = EmployeeRegistrationForm( data={ 'password1': "Mahesh@94", 'user_gender': "male", 'first_name': "abc", 'last_name': "xyz", 'password2': "Mahesh@94", 'user_link': "likdin.com", 'email': "*****@*****.**" } ) self.form_update = UpdateEmployeeForm( data={ 'password1': "Mahesh@94", 'user_gender': "male", 'first_name': "abc", 'last_name': "xyz", 'password2': "Mahesh@94", 'user_link': "likdin.com", 'email': "*****@*****.**" } )
def test_valid_and_save_form(self): form = EmployeeRegistrationForm(data=self.valid_user) form.is_valid() user = form.save() self.assertIsInstance(user, User, "Not an user")
def test_too_short_password(self): data = self.valid_user data["password1"] = "test" form = EmployeeRegistrationForm(data=data) self.assertFalse(form.is_valid())
def test_invalid_email(self): data = self.valid_user data["email"] = "test" form = EmployeeRegistrationForm(data=data) self.assertFalse(form.is_valid(), "Invalid email")
def test_employee_registration_form_valid(self): form = EmployeeRegistrationForm(data=self.valid_user) self.assertEqual(True, form.is_valid(), "Invalid form")
def test__clean__ok(self): form = EmployeeRegistrationForm() form.save() assert form.fields["first_name"].label == "First Name"