コード例 #1
0
def test_get_single(db, session):  # pylint: disable=unused-argument
    """Verify that the get_single() returns correct results as expected
    from database table.
    """
    # add a notification for user
    user_id = 'notf-user'
    request_id = 225
    request_type = 'registration'
    request_status = 3
    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()
    notification_id = get_notification_id(session, request_id)
    notification_data = Notification.get_single(notification_id)
    notification_data_raw = get_single_notification(session, notification_id)

    # verify results of both
    assert notification_data_raw.id == notification_data.id
    assert notification_data_raw.user_id == notification_data.user_id
    assert notification_data_raw.request_id == notification_data.request_id
    assert notification_data_raw.request_status == notification_data.request_status
    assert notification_data_raw.message == notification_data.message
コード例 #2
0
    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')