Example #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'])
Example #2
0
    def testCallsOneSecondApart(self):
        # If this test fails, set minDelta to 0.8 seconds or so.
        minDelta = datetime.timedelta(seconds=1)

        tasksched.sleepForRateLimit()
        lastDt = datetime.datetime.utcnow()
        lastDb = models.LastApiCall.objects.get().dt

        for i in range(1):
            tasksched.sleepForRateLimit()
            nowDt = datetime.datetime.utcnow()
            nowDb = models.LastApiCall.objects.get().dt

            self.assertTrue(nowDt-lastDt >= minDelta)
            self.assertTrue(nowDb-lastDb >= minDelta)

            lastDt, lastDb = nowDt, nowDb
Example #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'])
Example #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'])