Commit 7c3fe6eb by Kálmán Viktor

dashboard: profile view test

parent 522b6bb3
...@@ -4,6 +4,7 @@ from django.contrib.auth.models import User, Group ...@@ -4,6 +4,7 @@ from django.contrib.auth.models import User, Group
from django.core.exceptions import SuspiciousOperation from django.core.exceptions import SuspiciousOperation
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.contrib.auth.models import Permission from django.contrib.auth.models import Permission
from django.contrib.auth import authenticate
from vm.models import Instance, InstanceTemplate, Lease, Node from vm.models import Instance, InstanceTemplate, Lease, Node
from ..models import Profile from ..models import Profile
...@@ -774,3 +775,68 @@ class IndexViewTest(LoginMixin, TestCase): ...@@ -774,3 +775,68 @@ class IndexViewTest(LoginMixin, TestCase):
self.u1.profile.notify("urgent", "dashboard/test_message.txt", ) self.u1.profile.notify("urgent", "dashboard/test_message.txt", )
response = c.get("/dashboard/") response = c.get("/dashboard/")
self.assertEqual(response.context['NEW_NOTIFICATIONS_COUNT'], 1) self.assertEqual(response.context['NEW_NOTIFICATIONS_COUNT'], 1)
class ProfileViewTest(LoginMixin, TestCase):
def setUp(self):
self.u1 = User.objects.create(username='user1')
self.u1.set_password('password')
self.u1.save()
self.p1 = Profile.objects.create(user=self.u1)
self.p1.save()
def test_permitted_language_change(self):
c = Client()
self.login(c, "user1")
old_language_cookie_value = c.cookies['django_language'].value
old_language_db_value = self.u1.profile.preferred_language
response = c.post("/dashboard/profile/", {
'preferred_language': "hu",
})
self.assertEqual(response.status_code, 302)
self.assertNotEqual(old_language_cookie_value,
c.cookies['django_language'].value)
self.assertNotEqual(old_language_db_value,
User.objects.get(
username="user1").profile.preferred_language)
def test_permitted_valid_password_change(self):
c = Client()
self.login(c, "user1")
c.post("/dashboard/profile/", {
'old_password': "password",
'new_password1': "asd",
'new_password2': "asd",
})
self.assertIsNone(authenticate(username="user1", password="password"))
self.assertIsNotNone(authenticate(username="user1", password="asd"))
def test_permitted_invalid_password_changes(self):
c = Client()
self.login(c, "user1")
# wrong current password
c.post("/dashboard/profile/", {
'old_password': "password1",
'new_password1': "asd",
'new_password2': "asd",
})
self.assertIsNotNone(authenticate(username="user1",
password="password"))
self.assertIsNone(authenticate(username="user1", password="asd"))
# wrong pw confirmation
c.post("/dashboard/profile/", {
'old_password': "password",
'new_password1': "asd",
'new_password2': "asd1",
})
self.assertIsNotNone(authenticate(username="user1",
password="password"))
self.assertIsNone(authenticate(username="user1", password="asd"))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment