def test_api_override_serialization(db, api_client, default_namespace, recurring_event): event = recurring_event override = Event(original_start_time=event.start, master_event_uid=event.uid, namespace_id=default_namespace.id, calendar_id=event.calendar_id) override.update(event) override.uid = event.uid + "_" + event.start.strftime("%Y%m%dT%H%M%SZ") override.master = event override.master_event_uid = event.uid override.cancelled = True db.session.add(override) db.session.commit() filter = 'starts_after={}&ends_before={}'.format( urlsafe(event.start.replace(hours=-1)), urlsafe(event.start.replace(weeks=+1))) events = api_client.get_data('/events?' + filter) # We should have the base event and the override back, but no extras; # this allows clients to do their own expansion, should they ever desire # to experience the joy that is RFC 2445 section 4.8.5.4. assert len(events) == 2 assert events[0].get('object') == 'event' assert events[0].get('recurrence') is not None assert events[1].get('object') == 'event' assert events[1].get('status') == 'cancelled'
def noop_event_update(event, data): # Check whether the update is actually updating fields. # We do this by cloning the event, updating the fields and # comparing them. This is less cumbersome than having to think # about the multiple values of the `when` field. e = Event() e.update(event) e.namespace = event.namespace for attr in Event.API_MODIFIABLE_FIELDS: if attr in data: setattr(e, attr, data[attr]) e1 = encode(event) e2 = encode(e) for attr in Event.API_MODIFIABLE_FIELDS: # We have to handle participants a bit differently because # it's a list which can be permuted. if attr == 'participants': continue event_value = e1.get(attr) e_value = e2.get(attr) if event_value != e_value: return False e_participants = {p['email']: p for p in e.participants} event_participants = {p['email']: p for p in event.participants} if len(e_participants.keys()) != len(event_participants.keys()): return False for email in e_participants: if email not in event_participants: return False p1 = e_participants[email] p2 = event_participants[email] p1_status = p1.get('status') p2_status = p2.get('status') if p1_status != p2_status: return False p1_comment = p1.get('comment') p2_comment = p2.get('comment') if p1_comment != p2_comment: return False return True
def noop_event_update(event, data): # Check whether the update is actually updating fields. # We do this by cloning the event, updating the fields and # comparing them. This is less cumbersome than having to think # about the multiple values of the `when` field. e = Event() e.update(event) for attr in ['title', 'description', 'location', 'when', 'participants']: if attr in data: setattr(e, attr, data[attr]) for attr in ['title', 'description', 'location']: event_value = getattr(event, attr) e_value = getattr(e, attr) if event_value != e_value: return False for attr in ['start', 'end']: # This code can get datetimes and Arrow datetimes # so we convert everything to Arrow datetimes. event_value = arrow.get(getattr(event, attr)) e_value = arrow.get(getattr(e, attr)) if event_value != e_value: return False e_participants = {p['email']: p for p in e.participants} event_participants = {p['email']: p for p in event.participants} if len(e_participants.keys()) != len(event_participants.keys()): return False for email in e_participants: if email not in event_participants: return False p1 = e_participants[email] p2 = event_participants[email] p1_status = p1.get('status') p2_status = p2.get('status') if p1_status != p2_status: return False p1_comment = p1.get('comment') p2_comment = p2.get('comment') if p1_comment != p2_comment: return False return True