Esempio n. 1
0
    def test(self):
        now = get_utcnow()
        from datetime import timedelta
        time = now + timedelta(days=10)
        time_range = {'start': parseStr2utc(time - timedelta(days=1), self.tz_name),
                      'end': parseStr2utc(time + timedelta(days=1), self.tz_name)}
        # time = parseStr2utc('20110809T091606', self.tz_name)
        t = timer.create(time=time, title='Timer title', desc='Timer desc', user=self.owner, tlid=self.timelist.id, tzname=self.tz_name)

        # get_timer
        self.assertEqual(timer.get_timer(self.owner.id, t.id) is None, False);

        # get_timers
        self.assertEqual(len(timer.get_timers({'user': self.owner}, time_range.get('start'), time_range.get('end'))), 1)
        self.assertEqual(len(timer.get_timers({'user': self.owner, 'is_home': True}, time_range.get('start'), time_range.get('end'))), 1)
        self.assertEqual(len(timer.get_timers({'user': self.owner, 'is_own': True}, time_range.get('start'), time_range.get('end'))), 1)
        # error range
        err_time_range = {'start': parseStr2utc(time + timedelta(days=1), self.tz_name),
                          'end': parseStr2utc(time + timedelta(days=2), self.tz_name)}
        self.assertEqual(len(timer.get_timers({'user': self.owner}, err_time_range.get('start'), err_time_range.get('end'))), 0)

        # get_timelist_timers
        self.assertEqual(len(timer.get_timelist_timers(self.owner, self.timelist.id, time_range.get('start'), time_range.get('end'))), 1)
        self.assertEqual(len(timer.get_timelist_timers(self.owner, self.timelist.id, err_time_range.get('start'), err_time_range.get('end'))), 0)

        # get_crrent_timer
        self.assertEqual(timer.get_current_timer({'user': self.owner, 'is_own': True}).id, t.id)
        self.assertEqual(timer.get_current_timer({'user': self.owner, 'is_home': True}).id, t.id)
        self.assertEqual(timer.get_current_timer({'user': self.owner}).id, t.id)

        # get _timelist_current_timer
        self.assertEqual(timer.get_timelist_current_timer(self.owner, self.timelist.id).id, t.id)

        # edit
        title = 'test title edit'
        desc = 'test desc edit'
        t = timer.edit(user=self.owner, tid=t.id, time=time, title=title, desc=desc, tlid=self.timelist.id, tzname=self.tz_name, reminders=None)
        self.assertEqual(t.title, title)
        self.assertEqual(t.desc, desc)

        # delete
        timer.delete(self.owner, t.id)
        self.assertEqual(len(timer.get_timers({'user': self.owner}, time_range.get('start'), time_range.get('end'))), 0)
Esempio n. 2
0
def load_timers(request):
    """get bundle of timers from ajax request"""
    if request.is_ajax():
        try:
            reqdata = request.GET
            start = reqdata.get('start')
            end = reqdata.get('end')
            tz = reqdata.get('tz')
            tl_id = reqdata.get('tl_id')
            start = parseStr2utc(start, tz)
            end = parseStr2utc(end, tz)
            if tl_id:
                ts = timer.get_timelist_timers(request.user, int(tl_id), start, end)
            else:
                uinfo = get_user_info(request)
                ts = timer.get_timers(uinfo, start, end)
            # first is the time range info
            retts = [[start.strftime(timer.TIME_FORMAT),
                      end.strftime(timer.TIME_FORMAT)]]
            for t in ts:
                retts.append(format_timer_str(t))
            return JsonResponse(retts)
        except PermissionDenied:
            return JsonResponse({'ret':'Permission Denied'})