def test_partial_name_account_form(self): """ Filling out only the first name or only the last name produces an error. """ data = {"given_name": "Alicia", "gravatar": "*****@*****.**", "user": self.user} form = EditAccountForm(data, **{"user": self.user}) self.assertFalse(form.is_valid()) self.assertEqual(form.errors["family_name"][0], "Both a first and last name required.")
def test_both_names_account_form(self): """ Filling out both name fields produces a valid save. """ data = {"given_name": "Alicia", "family_name": "Smith", "gravatar": "*****@*****.**"} form = EditAccountForm(data, **{"user": self.user}) self.assertTrue(form.is_valid())
def test_no_name_account_form(self): """ Leaving both the first and last name fields blank produces a valid save. It also deletes the primary name object from the Name model. """ data = {"gravatar": "*****@*****.**", "user": self.user} form = EditAccountForm(data, **{"user": self.user}) self.assertTrue(form.is_valid()) form.save(self.user) self.assertEqual(Name.objects.count(), 0)
def test_no_name_account_form(self): """ Leaving both the first and last name fields blank produces a valid save. It also deletes the primary name object from the Name model. """ data = {"gravatar": "*****@*****.**", "user": self.user} form = EditAccountForm(data, **{'user': self.user}) self.assertTrue(form.is_valid()) form.save(self.user) self.assertEqual(Name.objects.count(), 0)
def test_both_names_account_form(self): """ Filling out both name fields produces a valid save. """ data = { "given_name": "Alicia", "family_name": "Smith", "gravatar": "*****@*****.**" } form = EditAccountForm(data, **{'user': self.user}) self.assertTrue(form.is_valid())
def test_partial_name_account_form(self): """ Filling out only the first name or only the last name produces an error. """ data = { "given_name": "Alicia", "gravatar": "*****@*****.**", "user": self.user } form = EditAccountForm(data, **{'user': self.user}) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['family_name'][0], "Both a first and last name required.")