changeset 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 (2014-01-22)
parents a4ae99359286
children cd3343abca9d
files bio/tests/test_views.py sg101/settings/test.py
diffstat 2 files changed, 42 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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