예제 #1
0
 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.put_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')
예제 #2
0
 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.put_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')
예제 #3
0
 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.put_with_status_check('/api/users', headers=self.headers, content_type='application/json',
                                data=json.dumps(data), status_code=UNAUTHORIZED_ERROR)
     self.assertTrue(user.verify_password('asdfghjkl;'))
예제 #4
0
 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.put_with_status_check('/api/users', headers=self.headers, content_type='application/json',
                                data=json.dumps(data), status_code=UNAUTHORIZED_ERROR)
     self.assertTrue(user.verify_password('asdfghjkl;'))
예제 #5
0
 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.put_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!'))
예제 #6
0
 def test_change_password_and_username_invalid_password(self):
     user = User('username', 'whisperDieselEngine')
     db.session.add(user)
     db.session.commit()
     data = {'id': user.id, 'old_password': '******', 'password': '******', 'username': '******'}
     self.put_with_status_check('/api/users', headers=self.headers, content_type='application/json',
                                data=json.dumps(data), status_code=UNAUTHORIZED_ERROR)
     self.assertTrue(user.verify_password('whisperDieselEngine'))
     self.assertEqual(user.username, 'username')
예제 #7
0
 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.put_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!'))
예제 #8
0
 def test_change_password_and_username_invalid_password(self):
     user = User('username', 'whisperDieselEngine')
     db.session.add(user)
     db.session.commit()
     data = {'id': user.id, 'old_password': '******', 'password': '******', 'username': '******'}
     self.put_with_status_check('/api/users', headers=self.headers, content_type='application/json',
                                data=json.dumps(data), status_code=UNAUTHORIZED_ERROR)
     self.assertTrue(user.verify_password('whisperDieselEngine'))
     self.assertEqual(user.username, 'username')
예제 #9
0
 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.put_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
예제 #10
0
 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.put_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
예제 #11
0
 def test_verify_invalid_password(self):
     user = User('username', 'invalid')
     self.assertFalse(user.verify_password('password'))
예제 #12
0
 def test_verify_valid_password(self):
     user = User('username', 'password')
     self.assertTrue(user.verify_password('password'))