def update_user(): """ Update user with suplied data, now works only for email, password, name and user type """ data = request.get_json() validate_data(data, {'token', 'user_id'}) user_id = data['user_id'] token = data['token'] validate_token(token) user = User.update_user_by_id_from_array(user_id, data) return response_ok_obj(user)
def test_update_user_by_id_from_array(self, session): """Test method update_user_by_id_from_array in User""" array = { 'name': 'kektimusMaximusPrime', 'email': '*****@*****.**', 'password': '******', 'user_type_id': 2 } #Test something that really shouldn't be there with pytest.raises(DbException) as err: User.update_user_by_id_from_array(0, array) assert str(err.value) == "(404, 'User not found.')" user = User("DUMMY", "*****@*****.**", "hackPr00f", None, None, True) user.user_type_id = UserType.get_type_by_name('GUEST').id user.activated = True session.add(user) session.commit() self.userList.append(user) assert len(self.userList) == 2 User.update_user_by_id_from_array(self.userList[1].id, array) user = User.get_user_by_id(self.userList[1].id) assert user.id == self.userList[1].id assert user.name == 'kektimusMaximusPrime' assert user.email == '*****@*****.**' assert user.confirm_password('passwd') assert user.user_type_id == 2 array = {} User.update_user_by_id_from_array(self.userList[1].id, array) user = User.get_user_by_id(self.userList[1].id) assert user.id == self.userList[1].id assert user.name == 'kektimusMaximusPrime' assert user.email == '*****@*****.**' assert user.confirm_password('passwd') assert user.user_type_id == 2 array = {'kek': 123, 'token': '01235'} User.update_user_by_id_from_array(self.userList[1].id, array) user = User.get_user_by_id(self.userList[1].id) assert user.id == self.userList[1].id assert user.name == 'kektimusMaximusPrime' assert user.email == '*****@*****.**' assert user.confirm_password('passwd') assert user.user_type_id == 2 array = {'name': 'kektimusMaximusPrime'} with pytest.raises(DbException) as err: User.update_user_by_id_from_array(self.userList[0].id, array) assert str(err.value) == "(400, 'username')" array = {'email': '*****@*****.**'} with pytest.raises(DbException) as err: User.update_user_by_id_from_array(self.userList[0].id, array) assert str(err.value) == "(400, 'email')" array = {'user_type_id': 200} with pytest.raises(DbException) as err: User.update_user_by_id_from_array(self.userList[0].id, array) assert str(err.value) == "(400, 'usertype')" array = {'name': 'kektimusMaximusPrime', 'password': '******'} with pytest.raises(DbException) as err: User.update_user_by_id_from_array(self.userList[0].id, array) assert str(err.value) == "(400, 'username')" user = User.get_user_by_id(self.userList[0].id) assert not user.confirm_password('passwd') array = {'email': '*****@*****.**', 'password': '******'} with pytest.raises(DbException) as err: User.update_user_by_id_from_array(self.userList[0].id, array) assert str(err.value) == "(400, 'email')" user = User.get_user_by_id(self.userList[0].id) assert not user.confirm_password('passwd') array = {'user_type_id': 200, 'password': '******'} with pytest.raises(DbException) as err: User.update_user_by_id_from_array(self.userList[0].id, array) assert str(err.value) == "(400, 'usertype')" user = User.get_user_by_id(self.userList[0].id) assert not user.confirm_password('passwd')