Exemple #1
0
def test_noop_event_update(db, default_namespace, calendar):
    event = add_fake_event(
        db.session, default_namespace.id, calendar=calendar, read_only=True
    )

    event.title = "Test event"
    event.participants = [{"email": "*****@*****.**"}, {"email": "*****@*****.**"}]

    assert noop_event_update(event, {}) is True

    update = {"title": "Test event"}
    assert noop_event_update(event, update) is True

    update = {"title": "Different"}
    assert noop_event_update(event, update) is False

    update = {"location": "Different"}
    assert noop_event_update(event, update) is False

    update = {"description": "Different"}
    assert noop_event_update(event, update) is False

    update = {"when": {"start_time": 123453453, "end_time": 1231231}}
    assert noop_event_update(event, update) is False

    event.when = {"start_time": 123453453, "end_time": 1231231}
    update = {"when": {"start_time": 123453453, "end_time": 1231231}}
    assert noop_event_update(event, update) is True

    update = {
        "participants": [{"email": "*****@*****.**"}, {"email": "*****@*****.**"}]
    }
    assert noop_event_update(event, update) is True

    update = {
        "participants": [
            {"email": "*****@*****.**", "status": "yes"},
            {"email": "*****@*****.**"},
        ]
    }
    assert noop_event_update(event, update) is False

    event.participants = [
        {"email": "*****@*****.**", "status": "yes"},
        {"email": "*****@*****.**"},
    ]
    update = {
        "participants": [
            {"email": "*****@*****.**", "status": "yes"},
            {"email": "*****@*****.**"},
        ]
    }
    assert noop_event_update(event, update) is True
def test_noop_event_update(db, default_namespace, calendar):
    event = add_fake_event(db.session, default_namespace.id,
                           calendar=calendar,
                           read_only=True)

    event.title = 'Test event'
    event.participants = [{'email': '*****@*****.**'},
                          {'email': '*****@*****.**'}]

    assert noop_event_update(event, {}) is True

    update = {'title': 'Test event'}
    assert noop_event_update(event, update) is True

    update = {'title': 'Different'}
    assert noop_event_update(event, update) is False

    update = {'location': 'Different'}
    assert noop_event_update(event, update) is False

    update = {'description': 'Different'}
    assert noop_event_update(event, update) is False

    update = {'when': {'start_time': 123453453, 'end_time': 1231231}}
    assert noop_event_update(event, update) is False

    event.when = {'start_time': 123453453, 'end_time': 1231231}
    update = {'when': {'start_time': 123453453, 'end_time': 1231231}}
    assert noop_event_update(event, update) is True

    update = {'participants': [{'email': '*****@*****.**'},
                               {'email': '*****@*****.**'}]}
    assert noop_event_update(event, update) is True

    update = {'participants': [{'email': '*****@*****.**', 'status': 'yes'},
                               {'email': '*****@*****.**'}]}
    assert noop_event_update(event, update) is False

    event.participants = [{'email': '*****@*****.**', 'status': 'yes'},
                          {'email': '*****@*****.**'}]
    update = {'participants': [{'email': '*****@*****.**', 'status': 'yes'},
                               {'email': '*****@*****.**'}]}
    assert noop_event_update(event, update) is True
Exemple #3
0
def event_update_api(public_id):
    g.parser.add_argument('notify_participants',
                          type=strict_bool,
                          location='args')
    args = strict_parse_args(g.parser, request.args)
    notify_participants = args['notify_participants']

    valid_public_id(public_id)
    try:
        event = g.db_session.query(Event).filter(
            Event.public_id == public_id,
            Event.namespace_id == g.namespace.id).one()
    except NoResultFound:
        raise NotFoundError("Couldn't find event {0}".format(public_id))
    if event.read_only:
        raise InputError('Cannot update read_only event.')
    if (isinstance(event, RecurringEvent)
            or isinstance(event, RecurringEventOverride)):
        raise InputError('Cannot update a recurring event yet.')

    data = request.get_json(force=True)
    valid_event_update(data, g.namespace, g.db_session)

    if 'participants' in data:
        for p in data['participants']:
            if 'status' not in p:
                p['status'] = 'noreply'

    # Don't update an event if we don't need to.
    if noop_event_update(event, data):
        return g.encoder.jsonify(event)

    for attr in ['title', 'description', 'location', 'when', 'participants']:
        if attr in data:
            setattr(event, attr, data[attr])

    event.sequence_number += 1
    g.db_session.commit()

    schedule_action('update_event',
                    event,
                    g.namespace.id,
                    g.db_session,
                    calendar_uid=event.calendar.uid,
                    notify_participants=notify_participants)

    return g.encoder.jsonify(event)
Exemple #4
0
def event_update_api(public_id):
    g.parser.add_argument('notify_participants', type=strict_bool,
                          location='args')
    args = strict_parse_args(g.parser, request.args)
    notify_participants = args['notify_participants']

    valid_public_id(public_id)
    try:
        event = g.db_session.query(Event).filter(
            Event.public_id == public_id,
            Event.namespace_id == g.namespace.id).one()
    except NoResultFound:
        raise NotFoundError("Couldn't find event {0}".format(public_id))
    if event.read_only:
        raise InputError('Cannot update read_only event.')
    if (isinstance(event, RecurringEvent) or
            isinstance(event, RecurringEventOverride)):
        raise InputError('Cannot update a recurring event yet.')

    data = request.get_json(force=True)
    valid_event_update(data, g.namespace, g.db_session)

    if 'participants' in data:
        for p in data['participants']:
            if 'status' not in p:
                p['status'] = 'noreply'

    # Don't update an event if we don't need to.
    if noop_event_update(event, data):
        return g.encoder.jsonify(event)

    for attr in ['title', 'description', 'location', 'when', 'participants']:
        if attr in data:
            setattr(event, attr, data[attr])

    event.sequence_number += 1
    g.db_session.commit()

    schedule_action('update_event', event, g.namespace.id, g.db_session,
                    calendar_uid=event.calendar.uid,
                    notify_participants=notify_participants)

    return g.encoder.jsonify(event)