class TestReservations(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self) from repo import FileRepo from domain import ReservationValidator self.RoomsRepo = FileRepo("rooms.txt", Room.readRoom, Room.writeRoom) self.ResRepo = FileRepo("test.txt",Reservation.readReservation,Reservation.writeReservation) self.srv = Service(self.RoomsRepo,self.ResRepo,ReservationValidator) self.y = datetime.date.today().year def tearDown(self): unittest.TestCase.tearDown(self) def testCheckAvailableRoom(self): self.assertTrue(self.srv.checkAvailableRoom(3,datetime.date(self.y,3,3),datetime.date(self.y,4,4))) self.assertFalse(self.srv.checkAvailableRoom(1,datetime.date(self.y,1,2),datetime.date(self.y,1,12))) def testCreateReservation(self): self.srv.createReservation('Test',4,4,datetime.date(self.y,11,11),datetime.date(self.y,11,12)) reservations = self.srv.getReservations() lastRes = reservations[-1] self.assertEqual(lastRes.getFam(),'Test') self.srv.deleteRsv(lastRes.getID()) def testDeleteReservation(self): firstRes = self.srv.getReservations()[0] ID = firstRes.getID() self.srv.deleteRsv(ID) self.assertTrue(firstRes not in self.srv.getReservations()) self.ResRepo.add(firstRes)
def testAddRepo(self): repo = FileRepo("test.txt", Assignment.fileRead, Assignment.fileWrite) a1 = Assignment(1, 'Ass1', 'Y.O.L.O.') a2 = Assignment(2, 'Ass2', 'MarianaMaria') repo.add(a1) self.assertEqual(repo.getAll(), [a1]) repo.add(a2) self.assertEqual(repo.getAll(), [a1, a2])
def testGetNearAdr(self): repo = FileRepo("test.txt", Address.fileRead, Address.fileWrite) a1 = Address(1, 'adr1', 1, 4, 0) a2 = Address(2, 'adr2', 4, 5, 0) repo.add(a1) repo.add(a2) srv = Service(repo) fAdr = srv.getNearAdr(0, 0, 10) self.assertEqual(len(fAdr), 2) self.assertEqual(fAdr[0][0], a1) self.assertEqual(fAdr[1][0], a2)
def testSimulateNewDay(self): repo = FileRepo("test.txt", Person.fileRead, Person.fileWrite) srv = Service(repo) p1 = Person(1, 'nonvaccinated', 'ill') p2 = Person(2, 'nonvaccinated', 'healthy') p3 = Person(3, 'nonvaccinated', 'healthy') repo.add(p1) repo.add(p2) repo.add(p3) srv.simulateNewDay() self.assertEqual(p2.getStatus(), 'ill') srv.simulateNewDay() self.assertEqual(p3.getStatus(), 'ill') with self.assertRaises(AssertionError): assert p1.getStatus() == 'healthy' repo.clearRepo()
def testRepoAddStud(self): repo = FileRepo("testStuds.txt", Student.fileRead, Student.fileWrite) s1 = Student(1, "stud stud", 9, 9) repo.add(s1) self.assertEqual(repo.getAll(), [s1]) repo.clearRepo()