diff --git a/tests/__init__.py b/tests/__init__.py index 35ceb79..d5e7d56 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -30,7 +30,8 @@ class SecurityTest(TestCase): session['csrf'] = 'csrf_token' csrf_hmac = hmac.new(self.app.config['SECRET_KEY'], - 'csrf_token'.encode('utf8'), digestmod=sha1) + 'csrf_token'.encode('utf8'), + digestmod=sha1) self.csrf_token = '##' + csrf_hmac.hexdigest() def _create_app(self, auth_config, **kwargs): @@ -38,17 +39,17 @@ class SecurityTest(TestCase): def _get(self, route, content_type=None, follow_redirects=None, headers=None): return self.client.get(route, follow_redirects=follow_redirects, - content_type=content_type or 'text/html', - headers=headers) + content_type=content_type or 'text/html', + headers=headers) def _post(self, route, data=None, content_type=None, follow_redirects=True, headers=None): if isinstance(data, dict): data['csrf_token'] = self.csrf_token + content_type = content_type or 'application/x-www-form-urlencoded' return self.client.post(route, data=data, - follow_redirects=follow_redirects, - content_type=content_type or 'application/x-www-form-urlencoded', - headers=headers) + follow_redirects=follow_redirects, + content_type=content_type, headers=headers) def register(self, email, password='password'): data = dict(email=email, password=password, csrf_token=self.csrf_token) diff --git a/tests/configured_tests.py b/tests/configured_tests.py index 7cef0e4..af27be0 100644 --- a/tests/configured_tests.py +++ b/tests/configured_tests.py @@ -122,7 +122,6 @@ class DefaultTemplatePathTests(SecurityTest): 'SECURITY_LOGIN_USER_TEMPLATE': 'custom_security/login_user.html', } - def test_login_user_template(self): r = self._get('/login') @@ -155,9 +154,8 @@ class RecoverableTemplatePathTests(SecurityTest): def test_reset_password_template(self): with capture_reset_password_requests() as requests: - r = self._post('/reset', - data=dict(email='joe@lp.com'), - follow_redirects=True) + r = self._post('/reset', data=dict(email='joe@lp.com'), + follow_redirects=True) t = requests[0]['token'] @@ -365,9 +363,8 @@ class RecoverableTests(SecurityTest): def test_reset_view(self): with capture_reset_password_requests() as requests: - r = self._post('/reset', - data=dict(email='joe@lp.com'), - follow_redirects=True) + r = self._post('/reset', data=dict(email='joe@lp.com'), + follow_redirects=True) t = requests[0]['token'] r = self._get('/reset/' + t) self.assertIn('

Reset password

', r.data) @@ -380,20 +377,18 @@ class RecoverableTests(SecurityTest): def test_forgot_password_json(self): r = self._post('/reset', data='{"email": "matt@lp.com"}', - content_type="application/json") + content_type="application/json") self.assertEquals(r.status_code, 200) def test_forgot_password_invalid_email(self): - r = self._post('/reset', - data=dict(email='larry@lp.com'), - follow_redirects=True) + r = self._post('/reset', data=dict(email='larry@lp.com'), + follow_redirects=True) self.assertIn("Specified user does not exist", r.data) def test_reset_password_with_valid_token(self): with capture_reset_password_requests() as requests: - r = self._post('/reset', - data=dict(email='joe@lp.com'), - follow_redirects=True) + r = self._post('/reset', data=dict(email='joe@lp.com'), + follow_redirects=True) t = requests[0]['token'] r = self._post('/reset/' + t, data={ @@ -480,13 +475,15 @@ class ChangePasswordTest(SecurityTest): self.assertIn('Password must be at least 6 characters', r.data) def test_change_password_success(self): + data = { + 'password': 'password', + 'new_password': 'newpassword', + 'new_password_confirm': 'newpassword' + } + self.authenticate() with self.app.extensions['mail'].record_messages() as outbox: - r = self._post('/change', data={ - 'password': 'password', - 'new_password': 'newpassword', - 'new_password_confirm': 'newpassword' - }, follow_redirects=True) + r = self._post('/change', data=data, follow_redirects=True) self.assertIn('You successfully changed your password', r.data) self.assertIn('Home Page', r.data) @@ -504,12 +501,13 @@ class ChangePasswordPostViewTest(SecurityTest): } def test_change_password_success(self): + data = { + 'password': 'password', + 'new_password': 'newpassword', + 'new_password_confirm': 'newpassword' + } self.authenticate() - r = self._post('/change', data={ - 'password': 'password', - 'new_password': 'newpassword', - 'new_password_confirm': 'newpassword' - }, follow_redirects=True) + r = self._post('/change', data=data, follow_redirects=True) self.assertIn('Profile Page', r.data) @@ -792,8 +790,6 @@ class ConfirmableExtendFormsTest(SecurityTest): r = self._get('/register', follow_redirects=True) self.assertIn("My Confirm Register Email Address Field", r.data) - def test_send_confirmation(self): r = self._get('/confirm', follow_redirects=True) self.assertIn("My Send Confirmation Email Address Field", r.data) -