def test_validation_for_all_items(self): form = AidantCreationForm(data=self.data.copy()) self.assertTrue(form.is_valid()) form.save() self.assertEqual(Aidant.objects.all().count(), 2) new_aidant = Aidant.objects.get(email="*****@*****.**") self.assertEqual(new_aidant.username, "*****@*****.**")
def field_test(name_of_field: str, data_set: dict) -> None: data_set[name_of_field] = "" form = AidantCreationForm(data=data_set) self.assertFalse( form.is_valid(), f"Field {name_of_field} is considered valid, it should not.", ) self.assertEqual(form.errors[name_of_field], ["Ce champ est obligatoire."])
def test_cannot_create_new_aidant_with_same_email(self): AidantFactory( first_name="Henri", last_name="Bernart", email="*****@*****.**", username="******", password="******", profession="Mediateur", organisation=self.organisation, ) form = AidantCreationForm(data=self.data) self.assertFalse(form.is_valid())
def test_cannot_create_new_aidant_with_same_email(self): Aidant.objects.create( first_name="Henri", last_name="Bernart", email="*****@*****.**", username="******", password="******", profession="Mediateur", organisme="Association Aide au Numérique", ville="Nîmes", ) form = AidantCreationForm(data=self.data) self.assertFalse(form.is_valid())
def test_cannot_create_new_aidant_with_unsound_password(self): data_set = self.data.copy() # settings.py AUTH_PASSWORD_VALIDATORS.MinimumLengthValidator data_set["password"] = "******" form = AidantCreationForm(data=data_set) self.assertFalse(form.is_valid()) # settings.py AUTH_PASSWORD_VALIDATORS.CommonPasswordValidator data_set["password"] = "******" form = AidantCreationForm(data=data_set) self.assertFalse(form.is_valid()) # settings.py AUTH_PASSWORD_VALIDATORS.UserAttributeSimilarityValidator data_set["password"] = "******" form = AidantCreationForm(data=data_set) self.assertFalse(form.is_valid()) # settings.py AUTH_PASSWORD_VALIDATORS.NumericPasswordValidator data_set["password"] = "******" form = AidantCreationForm(data=data_set) self.assertFalse(form.is_valid())
def test_from_renders_item_text_input(self): form = AidantCreationForm() self.assertIn("Email", form.as_p())
def field_test(name_of_field: str, data_set: dict) -> None: data_set[name_of_field] = "" form = AidantCreationForm(data=data_set) self.assertFalse(form.is_valid()) self.assertEqual(form.errors[name_of_field], ["Ce champ est obligatoire."])