summaryrefslogtreecommitdiffstats
path: root/hyperkitty/tests
diff options
context:
space:
mode:
Diffstat (limited to 'hyperkitty/tests')
-rw-r--r--hyperkitty/tests/test_views.py52
1 files changed, 33 insertions, 19 deletions
diff --git a/hyperkitty/tests/test_views.py b/hyperkitty/tests/test_views.py
index e522f07..948b621 100644
--- a/hyperkitty/tests/test_views.py
+++ b/hyperkitty/tests/test_views.py
@@ -40,43 +40,57 @@ from kittystore.test import FakeList, SettingsModule
from hyperkitty.models import Rating, LastView
+from hyperkitty.views.accounts import user_profile, user_registration
+
+
+def genericAssertRedirects(self, response, target):
+ # A version of assertRedirects that works with view responses
+ if hasattr(response, "client"):
+ return TestCase.assertRedirects(self, response, target)
+ self.assertEqual(response.status_code, 302)
+ self.assertEqual(response._headers["location"][1], target)
+
class AccountViewsTestCase(TestCase):
+ assertRedirects = genericAssertRedirects
+
def setUp(self):
- self.client = Client()
+ store = kittystore.get_store(SettingsModule(),
+ debug=False, auto_create=True)
+ defaults = {"kittystore.store": store, "HTTP_USER_AGENT": "testbot"}
+ self.factory = RequestFactory(**defaults)
def test_login(self):
# Try to access user profile (private data) without logging in
- response = self.client.get(reverse('user_profile'))
- self.assertRedirects(response, "%s?next=%s" % (reverse('user_login'), reverse('user_profile')))
+ request = self.factory.get(reverse(user_profile))
+ request.user = AnonymousUser()
+ response = user_profile(request)
+ self.assertRedirects(response,
+ "%s?next=%s" % (reverse('user_login'), reverse(user_profile)))
def test_profile(self):
- User.objects.create_user('testuser', 'test@example.com', 'testPass')
- self.client.login(username='testuser', password='testPass')
-
- response = self.client.get(reverse('user_profile'))
+ request = self.factory.get(reverse(user_profile))
+ request.user = User.objects.create_user('testuser', 'test@example.com', 'testPass')
+ response = user_profile(request)
self.assertEqual(response.status_code, 200)
- # Verify that user_profile is present in request context
- self.assertTrue('user_profile' in response.context)
-
- # Verify karma for newly created user is 1
- self.assertEqual(response.context['user_profile'].karma, 1)
-
-
def test_registration(self):
- User.objects.create_user('testuser', 'test@example.com', 'testPass')
- self.client.login(username='testuser', password='testPass')
+ request = self.factory.get(reverse(user_registration))
+ request.user = User.objects.create_user('testuser', 'test@example.com', 'testPass')
+ response = user_registration(request)
+ #self.client.login(username='testuser', password='testPass')
# If the user if already logged in, redirect to index page...
# Don't let him register again
- response = self.client.get(reverse('user_registration'))
+ #response = self.client.get(reverse('user_registration'))
self.assertRedirects(response, reverse('root'))
- self.client.logout()
+ #self.client.logout()
+ request.user = AnonymousUser()
# Access the user registration page after logging out and try to register now
- response = self.client.get(reverse('user_registration'))
+ #response = self.client.get(reverse('user_registration'))
+ response = user_registration(request)
self.assertEqual(response.status_code, 200)
# @TODO: Try to register a user and verify its working