comparison bio/tests/test_views.py @ 768:1b1a12abde3b

More bio tests. Change Celery to be eager during testing.
author Brian Neal <bgneal@gmail.com>
date Tue, 21 Jan 2014 19:42:09 -0600
parents a4ae99359286
children cd3343abca9d
comparison
equal deleted inserted replaced
767:a4ae99359286 768:1b1a12abde3b
6 import os 6 import os
7 7
8 from django.contrib.auth.models import User 8 from django.contrib.auth.models import User
9 from django.test import TestCase 9 from django.test import TestCase
10 from django.core.urlresolvers import reverse, NoReverseMatch 10 from django.core.urlresolvers import reverse, NoReverseMatch
11 from django.core import mail
11 12
12 from PIL import Image 13 from PIL import Image
13 14
14 from bio.models import UserProfile 15 from bio.models import UserProfile, UserProfileFlag
15 16
16 17
17 class MemberSearchTest(TestCase): 18 class MemberSearchTest(TestCase):
18 19
19 USERNAME = u'John' 20 USERNAME = u'John'
214 file_obj.seek(0) 215 file_obj.seek(0)
215 216
216 response = self.client.post(url, {'avatar_file': file_obj}, follow=True) 217 response = self.client.post(url, {'avatar_file': file_obj}, follow=True)
217 self.assertRedirects(response, reverse('bio-me')) 218 self.assertRedirects(response, reverse('bio-me'))
218 219
220 profile = UserProfile.objects.get(user__username='paul')
221 self.assertTrue(profile.avatar.path)
222 self.assertTrue(profile.avatar.name)
223 self.assertTrue(os.path.exists(profile.avatar.path))
224
225 def test_flag_profile_get(self):
226 paul = User.objects.get(username='paul')
227 eddie = User.objects.get(username='eddie')
228 url = reverse('bio-flag_profile', args=[eddie.pk])
229
230 # not logged in, wrong request method:
231 response = self.client.get(url)
232 self.assertEqual(response.status_code, 405)
233
234 # logged in, wrong request method
235 self.client.login(username='paul', password='pw')
236 response = self.client.get(url)
237 self.assertEqual(response.status_code, 405)
238
239 # logged out, right request method
240 self.client.logout()
241 response = self.client.post(url)
242 self.assertEqual(response.status_code, 200)
243 self.assertEqual(UserProfileFlag.objects.all().count(), 0)
244
245 # logged in, right request method
246 self.client.login(username='paul', password='pw')
247 response = self.client.post(url)
248 self.assertEqual(response.status_code, 200)
249 self.assertEqual(UserProfileFlag.objects.all().count(), 1)
250
251 flag = UserProfileFlag.objects.first()
252 self.assertEqual(flag.user, paul)
253 self.assertEqual(flag.profile, eddie.get_profile())
254
255 self.assertEqual(len(mail.outbox), 1)
256 self.assertTrue('A Profile Has Been Flagged' in mail.outbox[0].subject)