mirror of
https://github.com/TrentSPalmer/trentpalmerdotorg.git
synced 2024-11-21 09:01:31 -08:00
add accounts/tests/test_edit_profile_view.py
This commit is contained in:
parent
82ac0350f3
commit
12507888a8
88
accounts/tests/test_edit_profile_view.py
Normal file
88
accounts/tests/test_edit_profile_view.py
Normal file
@ -0,0 +1,88 @@
|
||||
from django.test import TestCase
|
||||
from django.contrib.auth.models import User
|
||||
from accounts.models import Account
|
||||
from django.urls import reverse
|
||||
|
||||
|
||||
class EditProfileViewTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
user_a = User(email='user_a@example.com', username='user_a')
|
||||
user_a.set_password('password123456donkey')
|
||||
user_a.save()
|
||||
Account.objects.create(user=user_a)
|
||||
|
||||
def test_edit_profile_view_no_login(self):
|
||||
response = self.client.post(reverse('accounts:edit_profile'), {
|
||||
'email': 'user_a@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, 'audio/index.html')
|
||||
user_a = User.objects.get(username='user_a')
|
||||
self.assertEquals(user_a.first_name, '')
|
||||
self.assertEquals(response.request['PATH_INFO'], '/')
|
||||
|
||||
def test_edit_profile_view_no_data(self):
|
||||
self.client.login(username='user_a', password='password123456donkey')
|
||||
response = self.client.post(reverse('accounts:edit_profile'), 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.first_name, '')
|
||||
self.assertEquals(response.request['PATH_INFO'], '/accounts/edit-profile/')
|
||||
self.assertEquals(response.content.decode('utf-8').count("This field is required."), 3)
|
||||
|
||||
def test_edit_profile_view_invalid_email(self):
|
||||
self.client.login(username='user_a', password='password123456donkey')
|
||||
response = self.client.post(reverse('accounts:edit_profile'), {
|
||||
'email': 'user_afoobar.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.first_name, '')
|
||||
self.assertEquals(user_a.account.twitter_handle, '@Twitter')
|
||||
self.assertEquals(response.request['PATH_INFO'], '/accounts/edit-profile/')
|
||||
|
||||
def test_edit_profile_view_invalid_twitter_handle(self):
|
||||
self.client.login(username='user_a', password='password123456donkey')
|
||||
response = self.client.post(reverse('accounts:edit_profile'), {
|
||||
'email': 'user_a@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.first_name, '')
|
||||
self.assertEquals(user_a.account.twitter_handle, '@Twitter')
|
||||
self.assertEquals(response.request['PATH_INFO'], '/accounts/edit-profile/')
|
||||
t_warning = "twitter_handle must begin with "@""
|
||||
self.assertTrue(t_warning in response.content.decode('utf-8'))
|
||||
|
||||
def test_edit_profile_view(self):
|
||||
self.client.login(username='user_a', password='password123456donkey')
|
||||
response = self.client.post(reverse('accounts:edit_profile'), {
|
||||
'email': 'user_a@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, 'audio/index.html')
|
||||
user_a = User.objects.get(username='user_a')
|
||||
self.assertEquals(user_a.first_name, 'User_a')
|
||||
self.assertEquals(user_a.last_name, 'Smith')
|
||||
self.assertEquals(user_a.account.twitter_handle, '@user_a')
|
||||
self.assertEquals(response.request['PATH_INFO'], '/')
|
Loading…
Reference in New Issue
Block a user