Ejemplo n.º 1
0
 def test_parse_datetime(self):
     from schooltool.common import parse_datetime
     dt = datetime.datetime
     valid_dates = (
         ("2000-01-01 00:00:00", dt(2000, 1, 1, 0, 0, 0, 0)),
         ("2000-01-01 00:00:00.000000", dt(2000, 1, 1, 0, 0, 0, 0)),
         ("2000-01-01T00:00:00", dt(2000, 1, 1, 0, 0, 0, 0)),
         ("2005-12-23 11:22:33", dt(2005, 12, 23, 11, 22, 33)),
         ("2005-12-23T11:22:33", dt(2005, 12, 23, 11, 22, 33)),
         ("2005-12-23T11:22:33.4", dt(2005, 12, 23, 11, 22, 33, 400000)),
         ("2005-12-23T11:22:33.456789", dt(2005, 12, 23, 11, 22, 33,
                                           456789)),
     )
     for s, d in valid_dates:
         result = parse_datetime(s)
         self.assertEquals(result, d,
                           "parse_datetime(%r) returned %r" % (s, result))
     invalid_dates = (
         "2000/01/01",
         "2100-02-29 00:00:00",
         "2005-12-23 11:22:33 "
     )
     for s in invalid_dates:
         try:
             result = parse_datetime(s)
         except ValueError:
             pass
         else:
             self.fail("parse_datetime(%r) did not raise" % s)
Ejemplo n.º 2
0
 def test_parse_datetime(self):
     from schooltool.common import parse_datetime
     dt = datetime.datetime
     valid_dates = (
         ("2000-01-01 00:00:00", dt(2000, 1, 1, 0, 0, 0, 0)),
         ("2000-01-01 00:00:00.000000", dt(2000, 1, 1, 0, 0, 0, 0)),
         ("2000-01-01T00:00:00", dt(2000, 1, 1, 0, 0, 0, 0)),
         ("2005-12-23 11:22:33", dt(2005, 12, 23, 11, 22, 33)),
         ("2005-12-23T11:22:33", dt(2005, 12, 23, 11, 22, 33)),
         ("2005-12-23T11:22:33.4", dt(2005, 12, 23, 11, 22, 33, 400000)),
         ("2005-12-23T11:22:33.456789", dt(2005, 12, 23, 11, 22, 33,
                                           456789)),
     )
     for s, d in valid_dates:
         result = parse_datetime(s)
         self.assertEquals(result, d,
                           "parse_datetime(%r) returned %r" % (s, result))
     invalid_dates = ("2000/01/01", "2100-02-29 00:00:00",
                      "2005-12-23 11:22:33 ")
     for s in invalid_dates:
         try:
             result = parse_datetime(s)
         except ValueError:
             pass
         else:
             self.fail("parse_datetime(%r) did not raise" % s)
Ejemplo n.º 3
0
    def test_calendarRows_otherTZ(self):
        from schooltool.timetable.browser.cal import DailyTimetableCalendarRowsView
        from schooltool.app.security import Principal

        request = TestRequest()
        principal = Principal('person', 'Some person', person=self.person)
        request.setPrincipal(principal)
        view = DailyTimetableCalendarRowsView(ISchoolToolCalendar(self.person),
                                              request)

        km = timezone('Asia/Kamchatka')
        view.getPersonTimezone = lambda: km

        result = list(view.calendarRows(date(2004, 11, 5), 8, 19, events=[]))

        kmdt = lambda arg: km.localize(parse_datetime('2004-11-05 %s:00' % arg)
                                       )

        expected = [('8:00', kmdt('8:00'), timedelta(0, 3600)),
                    ('9:00', kmdt('9:00'), timedelta(0, 3600)),
                    ('10:00', kmdt('10:00'), timedelta(0, 3600)),
                    ('11:00', kmdt('11:00'), timedelta(0, 3600)),
                    ('12:00', kmdt('12:00'), timedelta(0, 3600)),
                    ('13:00', kmdt('13:00'), timedelta(0, 3600)),
                    ('14:00', kmdt('14:00'), timedelta(0, 3600)),
                    ('15:00', kmdt('15:00'), timedelta(0, 3600)),
                    ('16:00', kmdt('16:00'), timedelta(0, 3600)),
                    ('17:00', kmdt('17:00'), timedelta(0, 3600)),
                    ('18:00', kmdt('18:00'), timedelta(0, 3600)),
                    ('19:00', kmdt('19:00'), timedelta(0, 3600)),
                    ('1', kmdt("20:00"), timedelta(0, 3600)),
                    ('21:00', kmdt("21:00"), timedelta(0, 4500)),
                    ('2', kmdt("22:15"), timedelta(0, 3600)),
                    ('23:15', kmdt("23:15"), timedelta(0, 900)),
                    ('3', kmdt("23:30"), timedelta(0, 1800))]

        self.assertEquals(result, expected)
Ejemplo n.º 4
0
    def test_calendarRows_otherTZ(self):
        from schooltool.timetable.browser.cal import DailyTimetableCalendarRowsView
        from schooltool.app.security import Principal

        request = TestRequest()
        principal = Principal('person', 'Some person', person=self.person)
        request.setPrincipal(principal)
        view = DailyTimetableCalendarRowsView(ISchoolToolCalendar(self.person), request)

        km = timezone('Asia/Kamchatka')
        view.getPersonTimezone = lambda: km

        result = list(view.calendarRows(date(2004, 11, 5), 8, 19, events=[]))

        kmdt = lambda arg: km.localize(parse_datetime('2004-11-05 %s:00' %
                                                      arg))

        expected = [('8:00', kmdt('8:00'), timedelta(0, 3600)),
                    ('9:00', kmdt('9:00'), timedelta(0, 3600)),
                    ('10:00', kmdt('10:00'),timedelta(0, 3600)),
                    ('11:00', kmdt('11:00'),timedelta(0, 3600)),
                    ('12:00', kmdt('12:00'),timedelta(0, 3600)),
                    ('13:00', kmdt('13:00'),timedelta(0, 3600)),
                    ('14:00', kmdt('14:00'),timedelta(0, 3600)),
                    ('15:00', kmdt('15:00'),timedelta(0, 3600)),
                    ('16:00', kmdt('16:00'),timedelta(0, 3600)),
                    ('17:00', kmdt('17:00'),timedelta(0, 3600)),
                    ('18:00', kmdt('18:00'),timedelta(0, 3600)),
                    ('19:00', kmdt('19:00'),timedelta(0, 3600)),
                    ('1',  kmdt("20:00"), timedelta(0, 3600)),
                    ('21:00', kmdt("21:00"), timedelta(0, 4500)),
                    ('2',  kmdt("22:15"), timedelta(0, 3600)),
                    ('23:15', kmdt("23:15"), timedelta(0, 900)),
                    ('3', kmdt("23:30"), timedelta(0, 1800))]

        self.assertEquals(result, expected)