Switch settings password tests to mock
Change-Id: I8ee74d4052a2c04d7890942c646fa07f44e724d2 Partially-Implements: blueprint mock-framework-in-unit-tests
This commit is contained in:
parent
e3715e0008
commit
66e868a5b7
@ -17,7 +17,7 @@ from django.core.urlresolvers import reverse
|
|||||||
from django import http
|
from django import http
|
||||||
from django.utils.six.moves.urllib.parse import urlsplit
|
from django.utils.six.moves.urllib.parse import urlsplit
|
||||||
|
|
||||||
from mox3.mox import IsA
|
import mock
|
||||||
|
|
||||||
from openstack_dashboard import api
|
from openstack_dashboard import api
|
||||||
from openstack_dashboard.test import helpers as test
|
from openstack_dashboard.test import helpers as test
|
||||||
@ -28,12 +28,9 @@ INDEX_URL = reverse('horizon:settings:password:index')
|
|||||||
|
|
||||||
class ChangePasswordTests(test.TestCase):
|
class ChangePasswordTests(test.TestCase):
|
||||||
|
|
||||||
@test.create_stubs({api.keystone: ('user_update_own_password', )})
|
@mock.patch.object(api.keystone, 'user_update_own_password')
|
||||||
def test_change_password(self):
|
def test_change_password(self, mock_user_update_own_password):
|
||||||
api.keystone.user_update_own_password(IsA(http.HttpRequest),
|
mock_user_update_own_password.return_value = None
|
||||||
'oldpwd',
|
|
||||||
'normalpwd',).AndReturn(None)
|
|
||||||
self.mox.ReplayAll()
|
|
||||||
|
|
||||||
formData = {'method': 'PasswordForm',
|
formData = {'method': 'PasswordForm',
|
||||||
'current_password': 'oldpwd',
|
'current_password': 'oldpwd',
|
||||||
@ -42,6 +39,8 @@ class ChangePasswordTests(test.TestCase):
|
|||||||
res = self.client.post(INDEX_URL, formData)
|
res = self.client.post(INDEX_URL, formData)
|
||||||
|
|
||||||
self.assertNoFormErrors(res)
|
self.assertNoFormErrors(res)
|
||||||
|
mock_user_update_own_password.assert_called_once_with(
|
||||||
|
test.IsHttpRequest(), 'oldpwd', 'normalpwd')
|
||||||
|
|
||||||
def test_change_validation_passwords_not_matching(self):
|
def test_change_validation_passwords_not_matching(self):
|
||||||
formData = {'method': 'PasswordForm',
|
formData = {'method': 'PasswordForm',
|
||||||
@ -52,12 +51,10 @@ class ChangePasswordTests(test.TestCase):
|
|||||||
|
|
||||||
self.assertFormError(res, "form", None, ['Passwords do not match.'])
|
self.assertFormError(res, "form", None, ['Passwords do not match.'])
|
||||||
|
|
||||||
@test.create_stubs({api.keystone: ('user_update_own_password', )})
|
@mock.patch.object(api.keystone, 'user_update_own_password')
|
||||||
def test_change_password_sets_logout_reason(self):
|
def test_change_password_sets_logout_reason(self,
|
||||||
api.keystone.user_update_own_password(IsA(http.HttpRequest),
|
mock_user_update_own_password):
|
||||||
'oldpwd',
|
mock_user_update_own_password.return_value = None
|
||||||
'normalpwd').AndReturn(None)
|
|
||||||
self.mox.ReplayAll()
|
|
||||||
|
|
||||||
formData = {'method': 'PasswordForm',
|
formData = {'method': 'PasswordForm',
|
||||||
'current_password': 'oldpwd',
|
'current_password': 'oldpwd',
|
||||||
@ -74,3 +71,6 @@ class ChangePasswordTests(test.TestCase):
|
|||||||
scheme, netloc, path, query, fragment = urlsplit(res.url)
|
scheme, netloc, path, query, fragment = urlsplit(res.url)
|
||||||
redirect_response = res.client.get(path, http.QueryDict(query))
|
redirect_response = res.client.get(path, http.QueryDict(query))
|
||||||
self.assertRedirectsNoFollow(redirect_response, settings.LOGIN_URL)
|
self.assertRedirectsNoFollow(redirect_response, settings.LOGIN_URL)
|
||||||
|
|
||||||
|
mock_user_update_own_password.assert_called_once_with(
|
||||||
|
test.IsHttpRequest(), 'oldpwd', 'normalpwd')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user