update accounts/tests/test_edit_profile_view.py add function

test_edit_profile_view_email_already_exists
This commit is contained in:
Trent Palmer 2021-04-20 20:21:44 -07:00
parent a9679cff69
commit 9d48b5b0ed

View File

@ -11,6 +11,26 @@ class EditProfileViewTestCase(TestCase):
user_a.set_password('password123456donkey') user_a.set_password('password123456donkey')
user_a.save() user_a.save()
Account.objects.create(user=user_a) Account.objects.create(user=user_a)
User.objects.create(username='user_c', email='user_c@example.com')
def test_edit_profile_view_email_already_exists(self):
self.client.login(username='user_a', password='password123456donkey')
response = self.client.post(reverse('accounts:edit_profile'), {
'email': 'user_c@example.com',
'first_name': 'User_a',
'last_name': 'Smith',
'twitter_handle': '@user_a',
'password': 'password123456donkey',
}, follow=True)
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'base_form.html')
user_a = User.objects.get(username='user_a')
self.assertEquals(user_a.email, 'user_a@example.com')
self.assertEquals(user_a.first_name, '')
self.assertEquals(user_a.account.twitter_handle, '@Twitter')
self.assertEquals(response.request['PATH_INFO'], '/accounts/edit-profile/')
msg = "An account already exists with this email address."
self.assertEquals(response.content.decode('utf-8').count(msg), 1)
def test_edit_profile_view_no_login(self): def test_edit_profile_view_no_login(self):
response = self.client.post(reverse('accounts:edit_profile'), { response = self.client.post(reverse('accounts:edit_profile'), {