Exemple #1
0
    def setUp(self):
        placefulSetUp()
        provideAdapter(getTermContainer, [Interface], ITermContainer)
        provideAdapter(getSchoolYearContainer)
        app = setup.setUpSchoolToolSite()

        schoolyear = SchoolYear("Sample", date(2004, 9, 1), date(2005, 12, 20))
        ISchoolYearContainer(app)['2004-2005'] = schoolyear

        self.term1 = term.Term('Sample', date(2004, 9, 1), date(2004, 12, 20))
        self.term2 = term.Term('Sample', date(2005, 1, 1), date(2005, 6, 1))
        terms = ITermContainer(app)
        terms['2004-fall'] = self.term1
        terms['2005-spring'] = self.term2
        self.app = app
Exemple #2
0
 def test_contains(self):
     cal = term.Term('Sample', date(2003, 9, 1), date(2003, 9, 16))
     self.assert_(date(2003, 8, 31) not in cal)
     self.assert_(date(2003, 9, 17) not in cal)
     for day in range(1, 17):
         self.assert_(date(2003, 9, day) in cal)
     self.assertRaises(TypeError, cal.__contains__, 'some string')
Exemple #3
0
    def testMarkWeekday(self):
        cal = term.Term('Sample', date(2003, 9, 1), date(2003, 9, 17))
        for day in 1, 8, 15:
            self.assert_(not cal.isSchoolday(date(2003, 9, day)))

        cal.addWeekdays(calendar.MONDAY)
        for day in 1, 8, 15:
            self.assert_(cal.isSchoolday(date(2003, 9, day)))
            self.assert_(not cal.isSchoolday(date(2003, 9, day + 1)))

        cal.removeWeekdays(calendar.MONDAY, calendar.TUESDAY)
        for day in 1, 8, 15:
            self.assert_(not cal.isSchoolday(date(2003, 9, day)))
            self.assert_(not cal.isSchoolday(date(2003, 9, day + 1)))

        cal.addWeekdays(calendar.MONDAY, calendar.TUESDAY)
        for day in 1, 8, 15:
            self.assert_(cal.isSchoolday(date(2003, 9, day)))
            self.assert_(cal.isSchoolday(date(2003, 9, day + 1)))

        cal.toggleWeekdays(calendar.TUESDAY, calendar.WEDNESDAY)
        for day in 1, 8, 15:
            self.assert_(cal.isSchoolday(date(2003, 9, day)))
            self.assert_(not cal.isSchoolday(date(2003, 9, day + 1)))
            self.assert_(cal.isSchoolday(date(2003, 9, day + 2)))
Exemple #4
0
    def generate(self, app, seed=None):
        date = datetime.date

        syc = ISchoolYearContainer(app)
        syc['2005-2006'] = SchoolYear("2005-2006",
                                      date(2005, 8, 22),
                                      date(2006, 12, 22))

        fall = term.Term('2005-fall', date(2005, 8, 22), date(2005, 12, 23))
        fall.addWeekdays(0, 1, 2, 3, 4)
        terms = ITermContainer(app)
        terms['2005-fall'] = fall

        spring = term.Term('2006-spring', date(2006, 1, 26), date(2006, 5, 31))
        spring.addWeekdays(0, 1, 2, 3, 4)
        terms['2006-spring'] = spring

        fall = term.Term('2006-fall', date(2006, 8, 21), date(2006, 12, 22))
        fall.addWeekdays(0, 1, 2, 3, 4)
        terms['2006-fall'] = fall
Exemple #5
0
    def testReset(self):
        cal = term.Term('Sample', date(2003, 9, 1), date(2003, 9, 15))
        cal.addWeekdays(1, 3, 5)

        new_first, new_last = date(2003, 8, 1), date(2003, 9, 30)
        cal.reset(new_first, new_last)

        self.assertEqual(cal.first, new_first)
        self.assertEqual(cal.last, new_last)
        for d in cal:
            self.assert_(not cal.isSchoolday(d))

        self.assertRaises(ValueError, cal.reset, new_last, new_first)
Exemple #6
0
    def testAddRemoveSchoolday(self):
        cal = term.Term('Sample', date(2003, 9, 1), date(2003, 9, 14))

        self.assert_(not cal.isSchoolday(date(2003, 9, 1)))
        self.assert_(not cal.isSchoolday(date(2003, 9, 2)))
        self.assertRaises(ValueError, cal.isSchoolday, date(2003, 9, 15))

        cal.add(date(2003, 9, 2))
        self.assert_(cal.isSchoolday(date(2003, 9, 2)))
        cal.remove(date(2003, 9, 2))
        self.assert_(not cal.isSchoolday(date(2003, 9, 2)))
        self.assertRaises(ValueError, cal.add, date(2003, 9, 15))
        self.assertRaises(ValueError, cal.remove, date(2003, 9, 15))
Exemple #7
0
 def test_getNextTermForDate(self):
     self.assert_(term.getNextTermForDate(date(2004, 8, 31)) is self.term1)
     self.assert_(term.getNextTermForDate(date(2004, 9, 1)) is self.term1)
     self.assert_(term.getNextTermForDate(date(2004, 11, 5)) is self.term1)
     self.assert_(term.getNextTermForDate(date(2004, 12, 20)) is self.term1)
     self.assert_(term.getNextTermForDate(date(2004, 12, 21)) is self.term2)
     self.assert_(term.getNextTermForDate(date(2005, 3, 17)) is self.term2)
     self.assert_(term.getNextTermForDate(date(2005, 11, 5)) is self.term2)
     self.term3 = term.Term('Sample', date(2005, 9, 1), date(2005, 12, 20))
     terms = ITermContainer(self.app)
     terms['2005-fall'] = self.term3
     self.assert_(term.getNextTermForDate(date(2005, 8, 30)) is self.term3)
     self.assert_(term.getNextTermForDate(date(2004, 8, 31)) is self.term1)
     self.assert_(term.getNextTermForDate(date(2004, 12, 22)) is self.term2)
     del terms['2004-fall']
     del terms['2005-spring']
     del terms['2005-fall']
     self.assert_(term.getNextTermForDate(date(2004, 8, 31)) is None)
Exemple #8
0
    def test_interface(self):

        cal = term.Term('Sample', date(2003, 9, 1), date(2003, 12, 24))
        verifyObject(interfaces.ITerm, cal)
        verifyObject(interfaces.ITermWrite, cal)
        verifyObject(ILocation, cal)
Exemple #9
0
def createSchoolYearWith3Terms():
    sy = SchoolYear("Sample", date(2009, 9, 1), date(2010, 05, 20))
    sy['a-term1'] = term.Term('Term 1', date(2009, 9, 1), date(2009, 12, 20))
    sy['b-term3'] = term.Term('Term 3', date(2010, 3, 16), date(2010, 5, 20))
    sy['c-term2'] = term.Term('Term 2', date(2010, 1, 1), date(2010, 3, 15))
    return sy