def readFromFile(self, fileName): f = open(fileName, "r") s = f.read() List = json.loads(s) for i in List.keys(): obj = List[i] if self._instace == client: cl = client(obj['id'], obj['name']) self.addElement(cl) elif self._instace == movie: mv = movie(obj['id'], obj['title'], obj['description'], obj['genre']) self.addElement(mv) else: rentDate = date(int(obj['rentDate'][:4]), int(obj['rentDate'][5:7]), int(obj['rentDate'][8:])) dueDate = date(int(obj['dueDate'][:4]), int(obj['dueDate'][5:7]), int(obj['dueDate'][8:])) if obj['returnDate'] == '0': rt = rental(obj['movieID'], obj['clientID'], rentDate, dueDate) else: returnDate = date(int(obj['returnDate'][:4]), int(obj['returnDate'][5:7]), int(obj['returnDate'][8:])) rt = rental(obj['movieID'], obj['clientID'], rentDate, dueDate, returnDate) self.addElement(rt)
def buildList(self): for i in self._data: if self._instance == client: self.addElement(client(i[0], i[1])) elif self._instance == movie: self.addElement(movie(i[0], i[1], i[2], i[3])) else: rentDate = date(int(i[2][:4]), int(i[2][5:7]), int(i[2][8:])) dueDate = date(int(i[3][:4]), int(i[3][5:7]), int(i[3][8:])) if i[4] == '0': rt = rental(i[1], i[0], rentDate, dueDate) else: returnDate = date(int(i[4][:4]), int(i[4][5:7]), int(i[4][8:])) rt = rental(i[1], i[0], rentDate, dueDate, returnDate) self.addElement(rt)
def testRentObject(self): mv = movie(1, "Titanic", "Nice", "Romance") cl = client(1, "Poo Mircea") rent = rental(1, 1, date(2017, 11, 11), date(2017, 11, 13)) self.assertEqual(rent.getID(), rental.ID) self.assertEqual(rent.getMovieID(), 1) self.assertEqual(rent.getClientID(), 1) self.assertEqual(rent.getRentDate(), date(2017, 11, 11)) self.assertEqual(rent.getDueDate(), date(2017, 11, 13)) self.assertEqual(rent.getReturnDate(), 0) a = str(rent) rent.updateReturnDate(date(2017, 11, 14)) self.assertEqual(rent.getReturnDate(), date(2017, 11, 14)) a = str(rent) with self.assertRaises(Exception): a = rental(1, 1, date(2017, 11, 11), date(2017, 11, 10))
def readFromFile(self, fileName): f = open(fileName, "r") n = int(f.readline().strip()) for i in range(n): new = f.readline().strip() new = new.split(',') if self._instance == client: self.addElement(client(int(new[0]), new[1])) elif self._instance == movie: self.addElement(movie(int(new[0]), new[1], new[2], new[3])) else: if new[5] == "0": rt = rental(int(new[2]), int(new[1]), self.buildDate(new[3]), self.buildDate(new[4])) else: rt = rental(int(new[2]), int(new[1]), self.buildDate(new[3]), self.buildDate(new[4]), self.buildDate(new[5])) self.addElement(rt)
def testClientObject(self): cl = client(1, "Pop Mircea") self.assertEqual(cl.getID(), 1) self.assertEqual(cl.getName(), "Pop Mircea") cl.updateName("Mircea Pop") a = str(cl) a = cl.getSearchStr() self.assertEqual(cl.getName(), "Mircea Pop") with self.assertRaises(Exception): cl = client(name="Pop Mircea") with self.assertRaises(Exception): cl = client() with self.assertRaises(Exception): cl = client(1, "A1212") with self.assertRaises(Exception): cl = client(1, "Pop mircea") with self.assertRaises(Exception): cl = client(1, "pop Mircea")
def testFunctional(self): rental.resetIDCounter() mvRepo = repo() clRepo = repo() rtRepo = repo() st = store() find = finder(clRepo, mvRepo) undoC = undoController() clc = clientController(clRepo, undoC) mvc = movieController(mvRepo, undoC) rtc = rentalController(rtRepo, clRepo, mvRepo, st, undoC) rmc = removalController(clRepo, mvRepo, rtRepo, undoC, rtc) CL = controller(clc, mvc, rtc, rmc, undoC, find) with self.assertRaises(Exception): a = CL.find("1") CL.addClient(["1", "Pop Vasile"]) with self.assertRaises(Exception): CL.removeMovie(["ds"]) CL.addMovie(["1", "Titanic", "nice", "Drama"]) a = CL.listMovies() a = CL.listClients() a = CL.listRents("") CL.rent(["1", "1", "11/11/2017", "13/11/2017"]) with self.assertRaises(Exception): CL.rent(["1", "1", "11/11/21", "12"]) with self.assertRaises(Exception): CL.rent(["1", "1", "10/11/2017", "11/11/2017"]) with self.assertRaises(Exception): CL.rent(["1", "1", "12/11/2017", "14/11/2017"]) a = CL.getAllRentals() CL.addClient(["10", "Laur"]) a = str(CL.getAllRentals()[0][0]) CL.addMovie(["2", "Titanic2", "d", "Drama"]) with self.assertRaises(Exception): CL.rent(["1", "2", "15/11/2017", "16/11/2017"]) CL.rent(["10", "2", "13/11/2017", "14/11/2017"]) CL.removeMovie(["2"]) CL.Return(["1", "14/11/2017"]) CL.rent(["10", "1", "17/11/2017", "19/11/2017"]) with self.assertRaises(Exception): CL.Return(["1", "13/11/2017"]) with self.assertRaises(Exception): CL.Return(["10", "11/11/2017"]) with self.assertRaises(Exception): CL.rent(["10", "1", "13/11/2017", "16/11/2017"]) self.assertEqual(str(CL.find("Pop")[0]), str(client("1", "Pop Vasile"))) CL.addClient(["3", "Ion"]) CL.addMovie(["2", "Titanic2", "Nice", "Drama"]) a = CL.getAllRentals() a = CL.getLateRentals(["13/11/2017"]) a = CL.getMostActive() a = CL.getMostRented() a = CL.find("1") CL.updateClient(["1", "Pop Viorel"]) CL.updateMovie(["1", "Titanic2", "nice", "Sci-Fi"]) CL.addClient(["2", "Ion"]) CL.removeClient(["1"]) CL.removeMovie(["1"]) with self.assertRaises(Exception): CL.addMovie("") with self.assertRaises(Exception): CL.removeMovie("") with self.assertRaises(Exception): CL.updateMovie("") with self.assertRaises(Exception): CL.addMovie(["c", "Titanic", "nice", "Romance"]) with self.assertRaises(Exception): CL.removeClient("") with self.assertRaises(Exception): CL.addClient("") with self.assertRaises(Exception): CL.updateClient("") with self.assertRaises(Exception): CL.addClient(["c", "Viorel"]) with self.assertRaises(Exception): CL.rent(["2", "1", "11/11/2017", "11/11/2017"]) CL.removeClient(["2"]) with self.assertRaises(Exception): CL.rent(["3", "1", "11/11/2017", "13/11/2017"]) with self.assertRaises(Exception): CL.rent(["4", "1", "11/11/2017", "13/11/2017"]) a = CL._clientController.getRepo() a = CL._movieController.getRepo() a = CL._rentalController.getRepo()