Esempio n. 1
0
def test_3():
    """
    Tests for multi-day event, from 00 on 11/13 to 10 on 11/15
    Assuming working hours of 9-17, should return avail of 10 to 17 on 11/15
    """
    events = [{
        'start': "2017-11-13T00:00:00-08:00",
        'end': "2017-11-15T10:00:00-08:00",
        'summary': 'multi-day event'
    }]
    daily_avail = [
        {
            'start': "2017-11-13T09:00:00-08:00",
            'end': "2017-11-13T17:00:00-08:00"
        },
        {
            'start': "2017-11-14T09:00:00-08:00",
            'end': "2017-11-14T17:00:00-08:00"
        },
        {
            'start': "2017-11-15T09:00:00-08:00",
            'end': "2017-11-15T17:00:00-08:00"
        },
    ]
    assert avail_times.get_free_times(events, daily_avail) == [{
        'start':
        "2017-11-15T10:00:00-08:00",
        'end':
        "2017-11-15T17:00:00-08:00"
    }]
Esempio n. 2
0
def choose():
    app.logger.debug("Checking credentials for Google calendar access")
    credentials = valid_credentials()
    if not credentials:
        app.logger.debug("Redirecting to authorization")
        return flask.redirect(flask.url_for('oauth2callback'))

    gcal_service = get_gcal_service(credentials)
    app.logger.debug("Returned from get_gcal_service")
    flask.g.calendars = list_calendars(gcal_service)
    app.logger.debug(flask.g.calendars)

    if request.method == 'POST':  # if a POST from user
        selected_cals = request.form.getlist('calendar')

        flask.g.all_events = list_events(gcal_service, selected_cals)
        flask.g.daily_availability = list_daily_availability()

        app.logger.debug(flask.g.all_events)
        app.logger.debug(flask.g.daily_availability)

        flask.g.daily_availability = avail_times.get_free_times(
            flask.g.all_events, flask.g.daily_availability)

        app.logger.debug(flask.g.daily_availability)

        flask.g.all_events_formatted = organize_times(flask.g.all_events, True)
        flask.g.daily_availability_formatted = organize_times(
            flask.g.daily_availability, False)
    return render_template('index.html')
Esempio n. 3
0
def test_5():
    """
    same test as 4 but with different working hours
    tests for cases A-E in get_free_times logic
    Busy times: 4-6, 8-10, 12-14, 16-18, 20-22
    if working times are 00:00 to 23:59, resulting free times should be 0-4, 6-8, 10-12, 14-16, 18-20, 22-23:59
    """
    events = [{
        'start': "2017-11-13T04:00:00-08:00",
        'end': "2017-11-13T06:00:00-08:00",
        'summary': 'CASE A'
    }, {
        'start': "2017-11-13T08:00:00-08:00",
        'end': "2017-11-13T10:00:00-08:00",
        'summary': 'CASE B'
    }, {
        'start': "2017-11-13T12:00:00-08:00",
        'end': "2017-11-13T14:00:00-08:00",
        'summary': 'CASE C'
    }, {
        'start': "2017-11-13T16:00:00-08:00",
        'end': "2017-11-13T18:00:00-08:00",
        'summary': 'CASE D'
    }, {
        'start': "2017-11-13T20:00:00-08:00",
        'end': "2017-11-13T22:00:00-08:00",
        'summary': 'CASE E'
    }]
    daily_avail = [{
        'start': "2017-11-13T00:00:00-08:00",
        'end': "2017-11-13T23:59:00-08:00"
    }]
    assert avail_times.get_free_times(events, daily_avail) == [
        {
            'start': '2017-11-13T00:00:00-08:00',
            'end': '2017-11-13T04:00:00-08:00'
        },
        {
            'start': '2017-11-13T06:00:00-08:00',
            'end': '2017-11-13T08:00:00-08:00'
        },
        {
            'start': '2017-11-13T10:00:00-08:00',
            'end': '2017-11-13T12:00:00-08:00'
        },
        {
            'start': '2017-11-13T14:00:00-08:00',
            'end': '2017-11-13T16:00:00-08:00'
        },
        {
            'start': '2017-11-13T18:00:00-08:00',
            'end': '2017-11-13T20:00:00-08:00'
        },
        {
            'start': '2017-11-13T22:00:00-08:00',
            'end': '2017-11-13T23:59:00-08:00'
        },
    ]
Esempio n. 4
0
def test_2():
    """
    Tests for all-day event, daily_avail should not have any times
    """
    events = [{
        'start': "2017-11-13T00:00:00-08:00",
        'end': "2017-11-14T00:00:00-08:00",
        'summary': 'An all day event'
    }]
    daily_avail = [{
        'start': "2017-11-13T09:00:00-08:00",
        'end': "2017-11-13T12:00:00-08:00"
    }]
    assert avail_times.get_free_times(events, daily_avail) == []
Esempio n. 5
0
def test_1():
    """
    trivial cases: daily_avail shouldn't change if no events

    """
    events = []
    daily_avail = [{
        'start': "2017-11-01T09:00:00-07:00",
        'end': "2017-11-01T12:00:00-07:00"
    }]

    assert avail_times.get_free_times(events, daily_avail) == [{
        'start':
        "2017-11-01T09:00:00-07:00",
        'end':
        "2017-11-01T12:00:00-07:00"
    }]
Esempio n. 6
0
def test_4():
    """
    tests for cases A-E in get_free_times logic
    Busy times: 4-6, 8-10, 12-14, 16-18, 20-22
    if working times are 9 to 17, resulting free times should be 10-12 and 14-16
    """
    events = [{
        'start': "2017-11-13T04:00:00-08:00",
        'end': "2017-11-13T06:00:00-08:00",
        'summary': 'CASE A'
    }, {
        'start': "2017-11-13T08:00:00-08:00",
        'end': "2017-11-13T10:00:00-08:00",
        'summary': 'CASE B'
    }, {
        'start': "2017-11-13T12:00:00-08:00",
        'end': "2017-11-13T14:00:00-08:00",
        'summary': 'CASE C'
    }, {
        'start': "2017-11-13T16:00:00-08:00",
        'end': "2017-11-13T18:00:00-08:00",
        'summary': 'CASE D'
    }, {
        'start': "2017-11-13T20:00:00-08:00",
        'end': "2017-11-13T22:00:00-08:00",
        'summary': 'CASE E'
    }]
    daily_avail = [{
        'start': "2017-11-13T09:00:00-08:00",
        'end': "2017-11-13T17:00:00-08:00"
    }]
    assert avail_times.get_free_times(events, daily_avail) == [{
        'start':
        '2017-11-13T10:00:00-08:00',
        'end':
        '2017-11-13T12:00:00-08:00'
    }, {
        'start':
        '2017-11-13T14:00:00-08:00',
        'end':
        '2017-11-13T16:00:00-08:00'
    }]
Esempio n. 7
0
def userchoose(meeting_id):
    credentials = valid_credentials()
    if not credentials:
        return flask.redirect(flask.url_for('oauth2callback'))

    gcal_service = get_gcal_service(credentials)
    flask.g.calendars = list_calendars(gcal_service)
    app.logger.debug(flask.g.calendars)

    if request.method == 'POST':
        selected_cals = request.form.getlist('calendar')

        flask.g.all_events = list_events(gcal_service, selected_cals)
        flask.g.daily_availability = list_daily_availability()

        flask.g.daily_availability = avail_times.get_free_times(
            flask.g.all_events, flask.g.daily_availability)

        flask.g.all_events_formatted = organize_times(flask.g.all_events, True)
        flask.g.daily_availability_formatted = organize_times(
            flask.g.daily_availability, False)
    return render_template('view.html')
Esempio n. 8
0
def choose():
    """
    We'll need authorization to list calendars
    I wanted to put what follows into a function, but had
    to pull it back here because the redirect has to be a
    'return'
  """
    app.logger.debug("Checking credentials for Google calendar access")
    credentials = valid_credentials()
    if not credentials:
        app.logger.debug("Redirecting to authorization")
        return flask.redirect(flask.url_for('oauth2callback'))

    gcal_service = get_gcal_service(credentials)
    app.logger.debug("Returned from get_gcal_service")
    flask.g.calendars = list_calendars(gcal_service)

    flask.g.all_events = list_events(gcal_service, flask.g.calendars)
    flask.g.daily_availability = list_daily_availability()

    app.logger.debug("flask.g.all_events")
    app.logger.debug(flask.g.all_events)
    app.logger.debug("flask.g.daily_availability")
    app.logger.debug(flask.g.daily_availability)

    flask.g.daily_availability = avail_times.get_free_times(
        flask.g.all_events, flask.g.daily_availability)

    app.logger.debug("flask.g.daily_availability")
    app.logger.debug(flask.g.daily_availability)

    flask.g.all_events_formatted = organize_times(flask.g.all_events)
    flask.g.daily_availability_formatted = organize_times(
        flask.g.daily_availability)

    return render_template('index.html')