def test_change_password_and_username_invalid_username(self): user = User('username', 'whisperDieselEngine') db.session.add(user) user2 = User('user2', 'somethingelse#@!@#') db.session.add(user) db.session.add(user2) db.session.commit() data = { 'id': user.id, 'old_password': '******', 'password': '******', 'username': '******' } self.post_with_status_check('/api/users', headers=self.headers, content_type='application/json', data=json.dumps(data), status_code=BAD_REQUEST) self.assertTrue(user.verify_password('whisperDieselEngine')) self.assertEqual(user.username, 'username') self.assertTrue(user2.verify_password('somethingelse#@!@#')) self.assertEqual(user2.username, 'user2')
def test_update_username_name_already_exists(self): user = User('username', 'whisperDieselEngine') db.session.add(user) user2 = User('user2', 'shhnow') db.session.add(user) db.session.add(user2) db.session.commit() data = {'id': user.id, 'username': '******'} self.post_with_status_check('/api/users', headers=self.headers, content_type='application/json', data=json.dumps(data), status_code=BAD_REQUEST) self.assertTrue(user.verify_password( 'whisperDieselEngine')) # check password wasn't changed
def test_update_user_password_only_invalid_old_password(self): user = User('username', 'asdfghjkl;') db.session.add(user) db.session.commit() data = { 'id': user.id, 'old_password': '******', 'password': '******' } self.post_with_status_check('/api/users', headers=self.headers, content_type='application/json', data=json.dumps(data), status_code=BAD_REQUEST) self.assertTrue(user.verify_password('asdfghjkl;'))
def test_update_user_password_only(self): user = User('username', 'asdfghjkl;') db.session.add(user) db.session.commit() data = { 'id': user.id, 'old_password': '******', 'password': '******' } response = self.post_with_status_check('/api/users', headers=self.headers, content_type='application/json', data=json.dumps(data), status_code=SUCCESS) self.assertDictEqual(response, user.as_json()) self.assertTrue(user.verify_password('changed!'))
def test_verify_invalid_password(self): user = User('username', 'invalid') self.assertFalse(user.verify_password('password'))
def test_verify_valid_password(self): user = User('username', 'password') self.assertTrue(user.verify_password('password'))