Exemple #1
0
def test_google_to_event_time_reverse():
    end = {"dateTime": "2012-10-15T17:00:00-07:00", "timeZone": "America/Los_Angeles"}
    start = {"dateTime": "2012-10-15T17:25:00-07:00", "timeZone": "America/Los_Angeles"}
    event_time = google_to_event_time(start, end)
    assert event_time.start == arrow.get(2012, 10, 16, 0, 0, 0)
    assert event_time.end == arrow.get(2012, 10, 16, 0, 25, 0)
    assert event_time.all_day is False

    start = {"date": "2012-10-15"}
    end = {"date": "2012-10-16"}
    event_time = google_to_event_time(start, end)
    assert event_time.start == arrow.get(2012, 10, 15)
    assert event_time.end == arrow.get(2012, 10, 15)
    assert event_time.all_day is True
Exemple #2
0
def test_google_to_event_time_reverse():
    end = {"dateTime": "2012-10-15T17:00:00-07:00", "timeZone": "America/Los_Angeles"}
    start = {"dateTime": "2012-10-15T17:25:00-07:00", "timeZone": "America/Los_Angeles"}
    event_time = google_to_event_time(start, end)
    assert event_time.start == arrow.get(2012, 10, 16, 00, 00, 00)
    assert event_time.end == arrow.get(2012, 10, 16, 00, 25, 00)
    assert event_time.all_day is False

    start = {"date": "2012-10-15"}
    end = {"date": "2012-10-16"}
    event_time = google_to_event_time(start, end)
    assert event_time.start == arrow.get(2012, 10, 15)
    assert event_time.end == arrow.get(2012, 10, 15)
    assert event_time.all_day is True
def test_google_to_event_time():
    start = {'dateTime': '2012-10-15T17:00:00-07:00',
             'timeZone': 'America/Los_Angeles'}
    end = {'dateTime': '2012-10-15T17:25:00-07:00',
           'timeZone': 'America/Los_Angeles'}
    event_time = google_to_event_time(start, end)
    assert event_time.start == arrow.get(2012, 10, 16, 00, 00, 00)
    assert event_time.end == arrow.get(2012, 10, 16, 00, 25, 00)
    assert event_time.all_day is False

    start = {'date': '2012-10-15'}
    end = {'date': '2012-10-16'}
    event_time = google_to_event_time(start, end)
    assert event_time.start == arrow.get(2012, 10, 15)
    assert event_time.end == arrow.get(2012, 10, 15)
    assert event_time.all_day is True
def test_google_to_event_time_reverse():
    end = {
        'dateTime': '2012-10-15T17:00:00-07:00',
        'timeZone': 'America/Los_Angeles'
    }
    start = {
        'dateTime': '2012-10-15T17:25:00-07:00',
        'timeZone': 'America/Los_Angeles'
    }
    event_time = google_to_event_time(start, end)
    assert event_time.start == arrow.get(2012, 10, 16, 00, 00, 00)
    assert event_time.end == arrow.get(2012, 10, 16, 00, 25, 00)
    assert event_time.all_day is False

    start = {'date': '2012-10-15'}
    end = {'date': '2012-10-16'}
    event_time = google_to_event_time(start, end)
    assert event_time.start == arrow.get(2012, 10, 15)
    assert event_time.end == arrow.get(2012, 10, 15)
    assert event_time.all_day is True
def parse_event_response(event):
    """
    Constructs an Event object from a Google event resource (a dictionary).
    See https://developers.google.com/google-apps/calendar/v3/reference/events

    Parameters
    ----------
    event: dict

    Returns
    -------
    A corresponding Event instance. This instance is not committed or added to
    a session.
    """
    uid = str(event['id'])
    # The entirety of the raw event data in json representation.
    raw_data = json.dumps(event)
    title = event.get('summary', '')

    # Timing data
    _start = event['start']
    _end = event['end']
    _original = event.get('originalStartTime', {})

    event_time = google_to_event_time(_start, _end)
    original_start = parse_google_time(_original)
    start_tz = _start.get('timeZone')

    last_modified = parse_datetime(event.get('updated'))

    description = event.get('description')
    location = event.get('location')
    busy = event.get('transparency') != 'transparent'

    # We're lucky because event statuses follow the icalendar
    # spec.
    event_status = event.get('status', 'confirmed')
    assert event_status in EVENT_STATUSES

    # Ownership, read_only information
    creator = event.get('creator')

    if creator:
        owner = u'{} <{}>'.format(
            creator.get('displayName', ''), creator.get('email', ''))
    else:
        owner = ''

    is_owner = bool(creator and creator.get('self'))
    read_only = not (is_owner or event.get('guestsCanModify'))

    participants = []
    attendees = event.get('attendees', [])
    for attendee in attendees:
        status = STATUS_MAP[attendee.get('responseStatus')]
        participants.append({
            'email': attendee.get('email'),
            'name': attendee.get('displayName'),
            'status': status,
            'notes': attendee.get('comment')
        })

    # Recurring master or override info
    recurrence = event.get('recurrence')
    master_uid = event.get('recurringEventId')
    cancelled = (event.get('status') == 'cancelled')

    return Event(uid=uid,
                 raw_data=raw_data,
                 title=title,
                 description=description,
                 location=location,
                 busy=busy,
                 start=event_time.start,
                 end=event_time.end,
                 all_day=event_time.all_day,
                 owner=owner,
                 is_owner=is_owner,
                 read_only=read_only,
                 participants=participants,
                 recurrence=recurrence,
                 last_modified=last_modified,
                 original_start_tz=start_tz,
                 original_start_time=original_start,
                 master_event_uid=master_uid,
                 cancelled=cancelled,
                 status=event_status,
                 # TODO(emfree): remove after data cleanup
                 source='local')
Exemple #6
0
def parse_event_response(event, read_only_calendar):
    """
    Constructs an Event object from a Google event resource (a dictionary).
    See https://developers.google.com/google-apps/calendar/v3/reference/events

    Parameters
    ----------
    event: dict

    Returns
    -------
    A corresponding Event instance. This instance is not committed or added to
    a session.
    """
    uid = str(event['id'])
    # The entirety of the raw event data in json representation.
    raw_data = json.dumps(event)
    title = event.get('summary', '')

    # Timing data
    _start = event['start']
    _end = event['end']
    _original = event.get('originalStartTime', {})

    event_time = google_to_event_time(_start, _end)
    original_start = parse_google_time(_original)
    start_tz = _start.get('timeZone')

    last_modified = parse_datetime(event.get('updated'))

    description = event.get('description')
    location = event.get('location')
    busy = event.get('transparency') != 'transparent'
    sequence = event.get('sequence', 0)

    # We're lucky because event statuses follow the icalendar
    # spec.
    event_status = event.get('status', 'confirmed')
    assert event_status in EVENT_STATUSES

    # Ownership, read_only information
    creator = event.get('creator')

    if creator:
        owner = u'{} <{}>'.format(creator.get('displayName', ''),
                                  creator.get('email', ''))
    else:
        owner = ''

    participants = []
    attendees = event.get('attendees', [])
    for attendee in attendees:
        status = STATUS_MAP[attendee.get('responseStatus')]
        participants.append({
            'email': attendee.get('email'),
            'name': attendee.get('displayName'),
            'status': status,
            'notes': attendee.get('comment')
        })

    organizer = event.get('organizer')
    is_owner = bool(organizer and organizer.get('self'))

    # FIXME @karim: The right thing here would be to use Google's ACL API.
    # There's some obscure cases, like an autoimported event which guests can
    # edit that can't be modified.
    read_only = True
    if not read_only_calendar:
        read_only = False

    # Recurring master or override info
    recurrence = event.get('recurrence')
    master_uid = event.get('recurringEventId')
    cancelled = (event.get('status') == 'cancelled')

    return Event(uid=uid,
                 raw_data=raw_data,
                 title=title,
                 description=description,
                 location=location,
                 busy=busy,
                 start=event_time.start,
                 end=event_time.end,
                 all_day=event_time.all_day,
                 owner=owner,
                 is_owner=is_owner,
                 read_only=read_only,
                 participants=participants,
                 recurrence=recurrence,
                 last_modified=last_modified,
                 original_start_tz=start_tz,
                 original_start_time=original_start,
                 master_event_uid=master_uid,
                 cancelled=cancelled,
                 status=event_status,
                 sequence_number=sequence,
                 source='local')
Exemple #7
0
def parse_event_response(event):
    """
    Constructs an Event object from a Google event resource (a dictionary).
    See https://developers.google.com/google-apps/calendar/v3/reference/events

    Parameters
    ----------
    event: dict

    Returns
    -------
    A corresponding Event instance. This instance is not committed or added to
    a session.
    """
    uid = str(event['id'])
    # The entirety of the raw event data in json representation.
    raw_data = json.dumps(event)
    title = event.get('summary', '')

    # Timing data
    _start = event['start']
    _end = event['end']
    _original = event.get('originalStartTime', {})

    event_time = google_to_event_time(_start, _end)
    original_start = parse_google_time(_original)
    start_tz = _start.get('timeZone')

    last_modified = parse_datetime(event.get('updated'))

    description = event.get('description')
    location = event.get('location')
    busy = event.get('transparency') != 'transparent'

    # We're lucky because an event statuses follow the icalendar
    # spec.
    event_status = event.get('status', 'confirmed')
    assert event_status in EVENT_STATUSES

    # Ownership, read_only information
    creator = event.get('creator')

    if creator:
        owner = u'{} <{}>'.format(creator.get('displayName', ''),
                                  creator.get('email', ''))
    else:
        owner = ''

    is_owner = bool(creator and creator.get('self'))
    read_only = not (is_owner or event.get('guestsCanModify'))

    participants = []
    attendees = event.get('attendees', [])
    for attendee in attendees:
        status = STATUS_MAP[attendee.get('responseStatus')]
        participants.append({
            'email': attendee.get('email'),
            'name': attendee.get('displayName'),
            'status': status,
            'notes': attendee.get('comment')
        })

    # Recurring master or override info
    recurrence = event.get('recurrence')
    master_uid = event.get('recurringEventId')
    cancelled = (event.get('status') == 'cancelled')

    return Event(
        uid=uid,
        raw_data=raw_data,
        title=title,
        description=description,
        location=location,
        busy=busy,
        start=event_time.start,
        end=event_time.end,
        all_day=event_time.all_day,
        owner=owner,
        is_owner=is_owner,
        read_only=read_only,
        participants=participants,
        recurrence=recurrence,
        last_modified=last_modified,
        original_start_tz=start_tz,
        original_start_time=original_start,
        master_event_uid=master_uid,
        cancelled=cancelled,
        status=event_status,
        # TODO(emfree): remove after data cleanup
        source='local')
Exemple #8
0
def parse_event_response(event, read_only_calendar):
    """
    Constructs an Event object from a Google event resource (a dictionary).
    See https://developers.google.com/google-apps/calendar/v3/reference/events

    Parameters
    ----------
    event: dict

    Returns
    -------
    A corresponding Event instance. This instance is not committed or added to
    a session.
    """
    uid = str(event["id"])
    # The entirety of the raw event data in json representation.
    raw_data = json.dumps(event)
    title = event.get("summary", "")

    # Timing data
    _start = event["start"]
    _end = event["end"]
    _original = event.get("originalStartTime", {})

    event_time = google_to_event_time(_start, _end)
    original_start = parse_google_time(_original)
    start_tz = _start.get("timeZone")

    last_modified = parse_datetime(event.get("updated"))

    description = event.get("description")
    location = event.get("location")
    busy = event.get("transparency") != "transparent"
    sequence = event.get("sequence", 0)

    # We're lucky because event statuses follow the icalendar
    # spec.
    event_status = event.get("status", "confirmed")
    assert event_status in EVENT_STATUSES

    # Ownership, read_only information
    creator = event.get("creator")

    if creator:
        owner = u"{} <{}>".format(creator.get("displayName", ""),
                                  creator.get("email", ""))
    else:
        owner = ""

    participants = []
    attendees = event.get("attendees", [])
    for attendee in attendees:
        status = STATUS_MAP[attendee.get("responseStatus")]
        participants.append({
            "email": attendee.get("email"),
            "name": attendee.get("displayName"),
            "status": status,
            "notes": attendee.get("comment"),
        })

    organizer = event.get("organizer")
    is_owner = bool(organizer and organizer.get("self"))

    # FIXME @karim: The right thing here would be to use Google's ACL API.
    # There's some obscure cases, like an autoimported event which guests can
    # edit that can't be modified.
    read_only = True
    if not read_only_calendar:
        read_only = False

    # Recurring master or override info
    recurrence = event.get("recurrence")
    master_uid = event.get("recurringEventId")
    cancelled = event.get("status") == "cancelled"

    visibility = event.get("visibility")

    # Rewrite some values documented in
    # https://developers.google.com/calendar/v3/reference/events
    if visibility == "default":
        visibility = None
    elif visibility == "confidential":
        visibility = "private"

    return Event(
        uid=uid,
        raw_data=raw_data,
        title=title,
        description=description,
        location=location,
        busy=busy,
        start=event_time.start,
        end=event_time.end,
        all_day=event_time.all_day,
        owner=owner,
        is_owner=is_owner,
        read_only=read_only,
        participants=participants,
        recurrence=recurrence,
        last_modified=last_modified,
        original_start_tz=start_tz,
        original_start_time=original_start,
        master_event_uid=master_uid,
        cancelled=cancelled,
        status=event_status,
        sequence_number=sequence,
        source="local",
        visibility=visibility,
    )