mirror of
https://github.com/TrentSPalmer/trentpalmerdotorg.git
synced 2024-11-21 09:01:31 -08:00
update accounts/tests/test_register_view.py add functions
test_register_user_already_exists and test_register_email_already_exists
This commit is contained in:
parent
f1109519db
commit
a9679cff69
@ -10,8 +10,44 @@ class RegisterViewTestCase(TestCase):
|
||||
user_b = User(email='user_b@example.com', username='user_b')
|
||||
user_b.set_password('123456password')
|
||||
user_b.save()
|
||||
user_c = User(username='user_c')
|
||||
user_c.set_password('123456password')
|
||||
user_c.save()
|
||||
Account.objects.create(user=user_b, twitter_handle='@user_b')
|
||||
Account.objects.create(user=user_c)
|
||||
EmailWhiteList.objects.create(email='user_a@example.com')
|
||||
EmailWhiteList.objects.create(email='user_b@example.com')
|
||||
EmailWhiteList.objects.create(email='user_c@example.com')
|
||||
|
||||
def test_register_user_already_exists(self):
|
||||
response = self.client.post(reverse('accounts:register'), {
|
||||
'username': 'user_c',
|
||||
'email': 'user_c@example.com',
|
||||
'password1': 'password123456donkey',
|
||||
'password2': 'password123456donkey'
|
||||
}, follow=True)
|
||||
self.assertEquals(response.status_code, 200)
|
||||
self.assertTemplateUsed(response, 'base_form.html')
|
||||
qs = User.objects.filter(username="user_a")
|
||||
self.assertEquals(len(qs), 0)
|
||||
self.assertEquals(response.request['PATH_INFO'], '/accounts/register/')
|
||||
msg = "Try a different username, that one already exists."
|
||||
self.assertEquals(response.content.decode('utf-8').count(msg), 1)
|
||||
|
||||
def test_register_email_already_exists(self):
|
||||
response = self.client.post(reverse('accounts:register'), {
|
||||
'username': 'user_a',
|
||||
'email': 'user_b@example.com',
|
||||
'password1': 'password123456donkey',
|
||||
'password2': 'password123456donkey'
|
||||
}, follow=True)
|
||||
self.assertEquals(response.status_code, 200)
|
||||
self.assertTemplateUsed(response, 'base_form.html')
|
||||
qs = User.objects.filter(username="user_a")
|
||||
self.assertEquals(len(qs), 0)
|
||||
self.assertEquals(response.request['PATH_INFO'], '/accounts/register/')
|
||||
msg = "An account already exists with this email address."
|
||||
self.assertEquals(response.content.decode('utf-8').count(msg), 1)
|
||||
|
||||
def test_register_already_logged_in(self):
|
||||
self.client.login(username='user_b', password='123456password')
|
||||
|
Loading…
Reference in New Issue
Block a user