def put(self, **kwargs): """Put method handler for notification route.""" user_id = kwargs.get('user_id') notification_id = kwargs.get('notification_id') if NotificationModel.exist_users(user_id): if NotificationModel.exists(notification_id): notification = NotificationModel.get_single(notification_id) if notification.user_id == user_id: NotificationModel.mark_read(notification_id) return Response(status=201, mimetype='application/json') else: res = {'error': ['invalid user id']} return Response(json.dumps(ErrorResponse().dump(res).data), status=400, mimetype='application/json') else: res = { 'error': [ 'notification {id} does not exists'.format( id=notification_id) ] } return Response(json.dumps(ErrorResponse().dump(res).data), status=400, mimetype='application/json') else: res = {'error': ['user {id} does not exists'.format(id=user_id)]} return Response(json.dumps(ErrorResponse().dump(res).data), status=400, mimetype='application/json')
def test_exists(db, session): # pylint: disable=unused-argument """Verify that exists() responds correctly while checking for existence of notifications.""" # add a new notification user_id = 'notf-user' request_id = 224 request_type = 'registration' request_status = 7 message = 'this is a test notification' notification = Notification(user_id=user_id, request_id=request_id, request_type=request_type, request_status=request_status, message=message) notification.add() # get notification id notification_id = get_notification_id(session, request_id) notification_bool = Notification.exists(notification_id) # check if it really exists res = exists_notification(session, notification_id) assert res is notification_bool