def test_shift(self):
     agenda = AgendaController()
     shift = agenda.add_shift(9, 14)
     shift = agenda.get_shift(shift.key)
     self.assertEqual(shift.interval, Interval(9, 14))
     shifts = list(agenda.get_shifts_itervalues())
     self.assertEqual([s.key for s in shifts], [shift.key])
     self.assertEqual([s.interval for s in shifts], [shift.interval])
     agenda.del_shift(shift.key)
     shifts = list(agenda.get_shifts_itervalues())
     self.assertEqual(shifts, [])
     agenda.destroy()
    def test_appointment(self):
        agenda = AgendaController()
        shift = agenda.add_shift(9, 14)

        with self.assertRaises(NotAvailableSlotError):
            agenda.add_appointment(8, 9)

        app1 = agenda.add_appointment(9, 10)
        app1 = agenda.get_appointment(app1.key)
        self.assertEqual(app1.interval, Interval(9, 10))

        agenda.del_appointment(app1.key)
        with self.assertRaises(KeyError):
            app1 = agenda.get_appointment(app1.key)

        app2 = agenda.add_appointment(9, 10)
        app2 = agenda.get_appointment(app2.key)
        self.assertEqual(app2.interval, Interval(9, 10))

        appos = list(agenda.get_appointments_in_shift_iteritems(shift.key))
        print appos

        with self.assertRaises(NotAvailableSlotError):
            agenda.add_appointment(9, 11)

        with self.assertRaises(NotAvailableSlotError):
            agenda.add_appointment(9, 11)

        with self.assertRaises(ShiftNotEmptyError):
            agenda.del_shift(shift.key)

        agenda.del_appointment(app2.key)
        with self.assertRaises(KeyError):
            app1 = agenda.get_appointment(app1)

        agenda.del_shift(shift.key)
        agenda.destroy()