Package madrona :: Package user_profile :: Module tests
[hide private]

Source Code for Module madrona.user_profile.tests

 1  from django.test import TestCase 
 2  from django.core.urlresolvers import reverse 
 3  from django.contrib.auth.models import User 
 4  from madrona.user_profile.models import UserProfile 
 5   
6 -class UserProfileTest(TestCase):
7 - def setUp(self):
8 self.user1 = User.objects.create_user("user1", "user1@madrona.org",password="pword") 9 self.user2 = User.objects.create_user("user2", "user2@madrona.org",password="pword")
10
11 - def test_login_required(self):
12 url = reverse('user_profile-form',args=['nomatter']) 13 response = self.client.get(url) 14 self.assertEquals(response.status_code, 302)
15
16 - def test_401_profile(self):
17 self.client.login(username=self.user2.username, password='pword') 18 url = reverse('user_profile-form',args=[self.user1.username]) 19 response = self.client.get(url) 20 self.assertEquals(response.status_code, 401)
21
22 - def test_get_profile(self):
23 self.client.login(username=self.user1.username, password='pword') 24 url = reverse('user_profile-form',args=[self.user1.username]) 25 response = self.client.get(url) 26 self.assertEquals(response.status_code, 200)
27
28 - def test_post_profile(self):
29 self.client.login(username=self.user1.username, password='pword') 30 url = reverse('user_profile-form',args=[self.user1.username]) 31 response = self.client.get(url) 32 self.assertEquals(response.status_code, 200) 33 34 data = {'first_name': 'Joe', 'last_name': 'Rando', 'email': 'joe@madrona.org', 'about': 'Joe Rando is a man of few words'} 35 response = self.client.post(url, data) 36 self.assertEquals(response.status_code, 302, response) 37 38 joe = User.objects.get(pk=self.user1.pk) 39 joepro = UserProfile.objects.get(user=joe) 40 self.assertEquals(joepro.about, 'Joe Rando is a man of few words')
41