# HG changeset patch # User Brian Neal # Date 1390354929 21600 # Node ID 1b1a12abde3b9c1a7aab40836d6081fbc7251f59 # Parent a4ae9935928644ea6a32f0cde0716633107452d1 More bio tests. Change Celery to be eager during testing. diff -r a4ae99359286 -r 1b1a12abde3b bio/tests/test_views.py --- a/bio/tests/test_views.py Mon Jan 20 20:04:25 2014 -0600 +++ b/bio/tests/test_views.py Tue Jan 21 19:42:09 2014 -0600 @@ -8,10 +8,11 @@ from django.contrib.auth.models import User from django.test import TestCase from django.core.urlresolvers import reverse, NoReverseMatch +from django.core import mail from PIL import Image -from bio.models import UserProfile +from bio.models import UserProfile, UserProfileFlag class MemberSearchTest(TestCase): @@ -216,3 +217,40 @@ response = self.client.post(url, {'avatar_file': file_obj}, follow=True) self.assertRedirects(response, reverse('bio-me')) + profile = UserProfile.objects.get(user__username='paul') + self.assertTrue(profile.avatar.path) + self.assertTrue(profile.avatar.name) + self.assertTrue(os.path.exists(profile.avatar.path)) + + def test_flag_profile_get(self): + paul = User.objects.get(username='paul') + eddie = User.objects.get(username='eddie') + url = reverse('bio-flag_profile', args=[eddie.pk]) + + # not logged in, wrong request method: + response = self.client.get(url) + self.assertEqual(response.status_code, 405) + + # logged in, wrong request method + self.client.login(username='paul', password='pw') + response = self.client.get(url) + self.assertEqual(response.status_code, 405) + + # logged out, right request method + self.client.logout() + response = self.client.post(url) + self.assertEqual(response.status_code, 200) + self.assertEqual(UserProfileFlag.objects.all().count(), 0) + + # logged in, right request method + self.client.login(username='paul', password='pw') + response = self.client.post(url) + self.assertEqual(response.status_code, 200) + self.assertEqual(UserProfileFlag.objects.all().count(), 1) + + flag = UserProfileFlag.objects.first() + self.assertEqual(flag.user, paul) + self.assertEqual(flag.profile, eddie.get_profile()) + + self.assertEqual(len(mail.outbox), 1) + self.assertTrue('A Profile Has Been Flagged' in mail.outbox[0].subject) diff -r a4ae99359286 -r 1b1a12abde3b sg101/settings/test.py --- a/sg101/settings/test.py Mon Jan 20 20:04:25 2014 -0600 +++ b/sg101/settings/test.py Tue Jan 21 19:42:09 2014 -0600 @@ -15,6 +15,9 @@ 'django.contrib.auth.hashers.MD5PasswordHasher', ] +# Celery should always execute tasks immediately +CELERY_ALWAYS_EAGER = True + # Use a different database in Redis for tests REDIS_DB = 14 QUEUE_REDIS_DB = 14