Exemplo n.º 1
0
    def testGoogleCalendarFieldSizes(self):
        """
        Test some large field sizes (e.g. summary, description).

        If this test passes, Google Calendar supports those fields up to the
        size we're testing here, and the tests documents them.
        If it fails, it just means we have to reduce that maximum size.
        """
        calId = settings.TEST_CALENDAR_ID
        tzName = 'Europe/Berlin'

        startDt = datetime.datetime.today() - datetime.timedelta(days=28)
        startDt = datetime.datetime(startDt.year, startDt.month, startDt.day,
                9, 45)
        endDt = startDt + datetime.timedelta(minutes=30)
        attendingEmails = [testutil.Alice_email, testutil.Brad_email]

        longSummary = 'ab c' * 256
        longDescription = 'ef gh' * 1000
        longLocation = 'ij k' * 256

        tasksched.sleepForRateLimit()
        ev = calendar.createEvent(calId, False, longSummary, longDescription,
                longLocation, startDt, endDt, tzName, attendingEmails)

        self.assertEqual(ev['summary'], longSummary)
        self.assertEqual(ev['description'], longDescription)
        self.assertEqual(ev['location'], longLocation)

        tasksched.sleepForRateLimit()
        calendar.deleteEvent(calId, ev['id'])
Exemplo n.º 2
0
def processEventTask(modelId):
    evTask = EventTask.objects.get(id=modelId)
    schedReq = None
    try:
        schedules = evTask.schedules.all()
        if not schedules:
            raise Exception('EventTask to create event for 0 schedules')

        schedReq = schedules[0].schedulingRequest
        if schedReq.status != SchedulingRequest.IN_PROGRESS:
            logging.warning('Drop EventTask: SchedulingRequest status is ' +
                            schedReq.status)
            return

        rooms = evTask.locations.all()
        locTxt = ', '.join(r.name for r in rooms)
        attendingEmails = [u.email for u in evTask.attendees.all()]
        for r in rooms:
            attendingEmails.append(r.email)

        # TODO: exception handling, Google API retry logic

        schedTempl = schedules[0].template
        if not schedTempl:
            raise Exception('Drop EventTask because schedule template was ' +
                            'deleted and we can\'t find out the timezone')

        sleepForRateLimit()
        gCalJson = calendar.createEvent(schedTempl.calendar.email, True,
                                        evTask.summary, evTask.description,
                                        locTxt, evTask.startDt, evTask.endDt,
                                        schedTempl.timezone.name,
                                        attendingEmails)
        newEv = Event.objects.create(json=json.dumps(gCalJson),
                                     template=evTask.template)
        newEv.schedules.add(*schedules)
    except:
        logging.error(traceback.format_exc())
        if schedReq:
            failSchedulingRequest(schedReq.id, traceback.format_exc())
    finally:
        evTask.delete()
Exemplo n.º 3
0
    def testCreateAndDeleteEvent(self):
        calId = settings.TEST_CALENDAR_ID
        tzName = 'Europe/Berlin'

        startDt = datetime.datetime.today() - datetime.timedelta(days=28)
        startDt = datetime.datetime(startDt.year, startDt.month, startDt.day,
                9, 45)
        endDt = startDt + datetime.timedelta(minutes=30)
        attendingEmails = [testutil.Alice_email, testutil.Brad_email]

        tasksched.sleepForRateLimit()
        ev = calendar.createEvent(calId, False, 'TEST: sample event',
                'Test: create & delete a simple event', 'Reception',
                startDt, endDt, tzName, attendingEmails)

        def parseToTimezone(string, tz):
            """Parse a datetime string and convert it to timezone tz."""
            return dateutil.parser.parse(string).astimezone(tz)

        def sameLocalFields(dt1, dt2):
            """Compare year, month, day, hour, minute and second in args."""
            return (dt1.year == dt2.year and dt1.month == dt2.month
                    and dt1.day == dt2.day and dt1.hour == dt2.hour
                    and dt1.minute == dt2.minute and dt1.second == dt2.second)

        # This is a handy way to quickly see what the returned JSON looks like
        #print(json.dumps(ev, indent=2))

        # Google returns an ISO dateTime string which includes a UTC offset
        # (apparently the local offset for you). Convert to local time for the
        # timezone we requested above, and check the date&time.
        tzObj = pytz.timezone(tzName)
        self.assertTrue(sameLocalFields(startDt,
            parseToTimezone(ev['start']['dateTime'], tzObj)))
        self.assertTrue(sameLocalFields(endDt,
            parseToTimezone(ev['end']['dateTime'], tzObj)))

        self.assertTrue({x for x in attendingEmails}
                == {x['email'] for x in ev['attendees']})

        tasksched.sleepForRateLimit()
        calendar.deleteEvent(calId, ev['id'])
Exemplo n.º 4
0
    def testEmptyEventSummaryDescriptionLocation(self):
        calId = settings.TEST_CALENDAR_ID
        tzName = 'Europe/Berlin'

        startDt = datetime.datetime.today() - datetime.timedelta(days=28)
        startDt = datetime.datetime(startDt.year, startDt.month, startDt.day,
                7, 30)
        endDt = startDt + datetime.timedelta(minutes=30)
        attendingEmails = [testutil.Alice_email, testutil.Brad_email]

        tasksched.sleepForRateLimit()
        ev = calendar.createEvent(calId, False, '', '', '',
                startDt, endDt, tzName, attendingEmails)

        for fName in ('summary', 'description', 'location'):
            # The empty fields are missing from the response
            self.assertFalse(fName in ev)

        tasksched.sleepForRateLimit()
        calendar.deleteEvent(calId, ev['id'])
Exemplo n.º 5
0
def processEventTask(modelId):
    evTask = EventTask.objects.get(id=modelId)
    schedReq = None
    try:
        schedules = evTask.schedules.all()
        if not schedules:
            raise Exception('EventTask to create event for 0 schedules')

        schedReq = schedules[0].schedulingRequest
        if schedReq.status != SchedulingRequest.IN_PROGRESS:
            logging.warning('Drop EventTask: SchedulingRequest status is '
                    + schedReq.status)
            return

        rooms = evTask.locations.all()
        locTxt = ', '.join(r.name for r in rooms)
        attendingEmails = [u.email for u in evTask.attendees.all()]
        for r in rooms:
            attendingEmails.append(r.email)

        # TODO: exception handling, Google API retry logic

        schedTempl = schedules[0].template
        if not schedTempl:
            raise Exception('Drop EventTask because schedule template was ' +
                    'deleted and we can\'t find out the timezone')

        sleepForRateLimit()
        gCalJson = calendar.createEvent(schedTempl.calendar.email, True,
                evTask.summary, evTask.description,
                locTxt, evTask.startDt, evTask.endDt,
                schedTempl.timezone.name, attendingEmails)
        newEv = Event.objects.create(json=json.dumps(gCalJson),
                template=evTask.template)
        newEv.schedules.add(*schedules)
    except:
        logging.error(traceback.format_exc())
        if schedReq:
            failSchedulingRequest(schedReq.id, traceback.format_exc())
    finally:
        evTask.delete()