Example #1
0
    def test_empty_events(self):
        """
        Tests for all times possible returned when the events are in different month.
        """
        begin_time = datetime.time(9,0)
        end_time = datetime.time(17,0)
        begin_date = datetime.date(2015, 9, 2)
        end_date = datetime.date(2015, 9, 10)

        novemberAgenda = Agenda()

        for day in range(1,11):
            novemberAgenda.append(Appt(datetime.date(2015, 11, day),datetime.time(9, 0), datetime.time(10, 45),"November"))

        result = novemberAgenda.freeblocks(begin_date, end_date, begin_time, end_time)

        self.assertEqual(result.__len__(),9)
Example #2
0
    def test_all_free_time(self):
        """
        Tests that an Agenda with events that fall outside of possible meeting Hours
        returns all days in range as possible meeting times.
        """
        begin_time = datetime.time(9,0)
        end_time = datetime.time(17,0)
        begin_date = datetime.date(2015, 12, 1)
        end_date = datetime.date(2015, 12, 4)
        allFreeTimeAgenda = Agenda()
        for day in range(1,5):
            allFreeTimeAgenda.append(Appt(datetime.date(2015, 12, day),datetime.time(6, 30), datetime.time(7, 45),"Before Hours"))
            allFreeTimeAgenda.append(Appt(datetime.date(2015, 12, day),datetime.time(20, 30), datetime.time(21, 45),"After Hours"))

        expected = Agenda()
        for day in range(1,5):
            expected.append(Appt(datetime.date(2015, 12, day),datetime.time(9, 0), datetime.time(17, 0),""))

        result = allFreeTimeAgenda.freeblocks(begin_date, end_date, begin_time, end_time)
        self.assertTrue(result.__eq__(expected),msg="Agendas not equal")
Example #3
0
    def test_events_bleed_outside_hours(self):
        """
        Tests that events starting outside of hour range and/or continuing outside
        of hours range are partially factored into the possible meeting times.
        """
        begin_time = datetime.time(9,0)
        end_time = datetime.time(17,0)
        begin_date = datetime.date(2015, 9, 1)
        end_date = datetime.date(2015, 9, 28)

        continueOutsideHoursAgenda = Agenda()

        for day in range(1,29):
            continueOutsideHoursAgenda.append(Appt(datetime.date(2015, 9, day),datetime.time(6, 30), datetime.time(9, 45),"6:30-9:45am"))
            continueOutsideHoursAgenda.append(Appt(datetime.date(2015, 9, day),datetime.time(16, 30), datetime.time(20, 45),"4:30-8:45pm"))

        expected = Agenda()
        for day in range(1,29):
            expected.append(Appt(datetime.date(2015, 9, day),datetime.time(9, 45), datetime.time(16, 30),"6:30-9:45am"))

        result = continueOutsideHoursAgenda.freeblocks(begin_date, end_date, begin_time, end_time)
        self.assertTrue(result.__eq__(expected))
Example #4
0
def blocktimes():
    """
    Retrieves the events from the selected calendars using the Google Calendar API.
    Events are inserted into an Agenda as Appointements. Agenda.freeblock then returns
    an Agenda of the possible meeting times, which is then rendered on the webpage.
    """
    app.logger.debug("Entering blocktimes")

    # Get ids of selected calendars from form
    calids = request.form.getlist('calid')

    credentials = valid_credentials()
    service = get_gcal_service(credentials)
    app.logger.debug("Returned from get_gcal_service")

    # Agenda of all the events that occur within the specified date range
    busy_times = Agenda()

    # For each calendar, get the events within the specified range
    for cal in calids:
        app.logger.debug("Getting free times between "+flask.session['begin_date']+" and "+flask.session['end_date'])
        events = service.events().list(calendarId=cal,singleEvents=True,timeMin=flask.session['begin_date'],timeMax=flask.session['end_date']).execute()

        for event in events['items']:
            busy = Appt(arrow.get(event['start']['dateTime']).date(),arrow.get(event['start']['dateTime']).time(),arrow.get(event['end']['dateTime']).time(),"busy")
            busy_times.append(busy)

    begin_date = arrow.get(flask.session['begin_date'])
    end_date = arrow.get(flask.session['end_date'])

    begin_time = arrow.get(flask.session['begin_time']).time()
    end_time = arrow.get(flask.session['end_time']).time()


    # Calling normalize makes sure that overlapping events are merged
    busy_times.normalize()

    # Make a new Agenda with all the free times
    meetings = busy_times.freeblocks(begin_date, end_date, begin_time, end_time)

    # Merge overlapping free times (if they exist) as a precaution
    meetings.normalize()

    return flask.render_template('index.html',meetings=meetings)
Example #5
0
    def test_no_free_time(self):
        """
        Tests that Agendas busy during the times a person is free returns no
        possible meeting times.
        """
        begin_time = datetime.time(9,0)
        end_time = datetime.time(17,0)
        begin_date = datetime.date(2015, 9, 2)
        end_date = datetime.date(2015, 9, 10)

        noFreeTimeAgenda = Agenda()
        self.assertEqual(noFreeTimeAgenda.__len__(),0)

        for day in range(2,11):
            noFreeTimeAgenda.append(Appt(datetime.date(2015, 9, day),datetime.time(9, 0), datetime.time(17, 45),"All Hours"))
            noFreeTimeAgenda.append(Appt(datetime.date(2015, 9, day),datetime.time(0, 0), datetime.time(23, 59),"All Hours"))

        self.assertEqual(noFreeTimeAgenda.__len__(),18)

        result = noFreeTimeAgenda.freeblocks(begin_date, end_date, begin_time, end_time)

        self.assertEqual(result.__len__(),0)
Example #6
0
    def test_freeblock_longer_range(self):
        """
        Tests for full day (within hour range) return when less days have events
        than those in the freeblock range.
        """
        begin_time = datetime.time(9,0)
        end_time = datetime.time(17,0)
        begin_date = datetime.date(2015, 9, 1)
        end_date = datetime.date(2015, 9, 18)

        oneWeekAgenda = Agenda()
        for day in range(10,19):
            oneWeekAgenda.append(Appt(datetime.date(2015, 9, day),datetime.time(12, 30), datetime.time(14,20),"12:30-2:20pm"))

        expected = Agenda()
        for day in range(1,10):
            expected.append(Appt(datetime.date(2015, 9, day),datetime.time(9, 0), datetime.time(17,0),"all day"))
        for day in range(10,19):
            expected.append(Appt(datetime.date(2015, 9, day),datetime.time(9, 0), datetime.time(12, 30),"9:00-12:30am"))
            expected.append(Appt(datetime.date(2015, 9, day),datetime.time(14,20), datetime.time(17, 0),"2:20pm-5pm"))

        expected.normalize()
        result = oneWeekAgenda.freeblocks(begin_date, end_date, begin_time, end_time)

        self.assertEqual(result.__len__(),expected.__len__())
        self.assertTrue(result.__eq__(expected))