def test_update_then_list(self):
        rda = ActivityReservationDataAccess("test.ini")
        rda.load()
        r = ActivityReservation()
        r.set_id("id1")
        r.set_start_time(2015, 1, 1, 1)
        r.set_end_time(2015, 1, 1, 3)
        r.set_activity_id("room0")
        r.set_user_id("reserver0")
        rda.update_reservation(r)
        rlist = rda.list_all_reservations()
        
        self.assertEqual(len(rlist), 3)

        rsv = rlist[0]
        self.assertEqual(rsv.get_id(), "id1")
        self.assertEqual(rsv.get_user_id(), "reserver0")
        self.assertEqual(rsv.get_activity_id(), "room0")
        self.assertEqual(rsv.get_start_time(), datetime.datetime(2015, 1, 1, 1))
        self.assertEqual(rsv.get_end_time(), datetime.datetime(2015, 1, 1, 3))        

        rsv = rlist[1]
        self.assertEqual(rsv.get_id(), "id2")
        self.assertEqual(rsv.get_user_id(), "reserver2")
        self.assertEqual(rsv.get_activity_id(), "room2")
        self.assertEqual(rsv.get_start_time(), datetime.datetime(2015, 6, 10, 12))
        self.assertEqual(rsv.get_end_time(), datetime.datetime(2015, 6, 10, 16))

        rsv = rlist[2]
        self.assertEqual(rsv.get_id(), "id3")
        self.assertEqual(rsv.get_user_id(), "reserver3")
        self.assertEqual(rsv.get_activity_id(), "room3")
        self.assertEqual(rsv.get_start_time(), datetime.datetime(2015, 6, 11, 12))
        self.assertEqual(rsv.get_end_time(), datetime.datetime(2015, 6, 12, 16))
    def test_add_save(self):
        rda = ActivityReservationDataAccess("test.ini")
        r = ActivityReservation()
        r.set_id("id3")
        r.set_user_id("reserver3")
        r.set_activity_id("room3")
        r.set_start_time(2015, 6, 11, 12)
        r.set_end_time(2015, 6, 12, 16)
        self.assertTrue(rda.add_reservation(r))
        rda.save()

        with open("test.ini", "rt") as f:
            self.assertEqual(f.readline(), "[id3]\n")
            self.assertEqual(f.readline(), "start time = 06/11/15 12:00:00\n")
            self.assertEqual(f.readline(), "end time = 06/12/15 16:00:00\n")
            self.assertEqual(f.readline(), "user id = reserver3\n")
            self.assertEqual(f.readline(), "activity id = room3\n")
    def test_add_then_list(self):
        rda = ActivityReservationDataAccess("test.ini")
        rda.load()
        r = ActivityReservation()
        r.set_id("id4")
        r.set_user_id("reserver4")
        r.set_activity_id("room3")
        r.set_start_time(2015, 6, 12, 16)
        r.set_end_time(2015, 6, 12, 18)
        self.assertTrue(rda.add_reservation(r))

        allRsv = rda.list_all_reservations()
        self.assertEqual(len(allRsv), 4)
        
        lastRsv = allRsv[3]
        self.assertFalse(lastRsv is r)

        self.assertEqual(lastRsv.get_id(), "id4")
        self.assertEqual(lastRsv.get_user_id(), "reserver4")
        self.assertEqual(lastRsv.get_activity_id(), "room3")
        self.assertEqual(lastRsv.get_start_time_as_str(), "06/12/15 16:00:00")
        self.assertEqual(lastRsv.get_end_time_as_str(), "06/12/15 18:00:00")
    def test_update_then_save(self):
        rda = ActivityReservationDataAccess("test.ini")
        rda.load()
        r = ActivityReservation()
        r.set_id("id1")
        r.set_start_time(2015, 1, 1, 1)
        r.set_end_time(2015, 1, 1, 3)
        r.set_activity_id("room0")
        r.set_user_id("reserver0")
        self.assertTrue(rda.update_reservation(r))
        rda.save()

        with open("test.ini", "rt") as f:
            self.assertEqual(f.readline(), "[id1]\n")
            self.assertEqual(f.readline(), "start time = 01/01/15 01:00:00\n")
            self.assertEqual(f.readline(), "end time = 01/01/15 03:00:00\n")
            self.assertEqual(f.readline(), "user id = reserver0\n")
            self.assertEqual(f.readline(), "activity id = room0\n")

            self.assertEqual(f.readline(), "\n")

            self.assertEqual(f.readline(), "[id2]\n")
            self.assertEqual(f.readline(), "start time = 06/10/15 12:00:00\n")
            self.assertEqual(f.readline(), "end time = 06/10/15 16:00:00\n")
            self.assertEqual(f.readline(), "user id = reserver2\n")
            self.assertEqual(f.readline(), "activity id = room2\n")

            self.assertEqual(f.readline(), "\n")

            self.assertEqual(f.readline(), "[id3]\n")
            self.assertEqual(f.readline(), "start time = 06/11/15 12:00:00\n")
            self.assertEqual(f.readline(), "end time = 06/12/15 16:00:00\n")
            self.assertEqual(f.readline(), "user id = reserver3\n")
            self.assertEqual(f.readline(), "activity id = room3\n")

            self.assertEqual(f.readline(), "\n")
            self.assertEqual(f.readline(), "")
 def test_id(self):
     r = ActivityReservation()
     r.set_id("1")
     self.assertEqual(r.get_id(), "1")
     r.set_id("2")
     self.assertEqual(r.get_id(), "2")