def __testRepository(self): students = Repository() students.store(Student(123, 'Andrei Stefan')) students.store(Student(124, 'Cosmin Iordache')) students.store(Student(125, 'Simon Claudiu')) # len of repository assert len(students) == 3 # findByName2 function tests assert students.findByName2('Andrei Stefan') == 123 assert students.findByName2('Cosmin Iordache') == 124 assert students.findByName2('Simon Claudiu') == 125 #find tests assert students.find(133) == False assert students.find(134) == False assert students.find(135) == False #store tests assert students.store(Student(123, 'Cosmin')) == False assert students.store(Student(125, 'Geanina')) == False assert students.store(Student(124, 'Mihai')) == False #update test assert students.update(Student(133, 'Cosmin')) == False assert students.update(Student(155, 'Geanina')) == False assert students.update(Student(175, 'Ionut')) == False students.store(Student(126, 'Arthur Mihai')) students.store(Student(127, 'George Ionut')) # test store and delete assert len(students) == 5 students.delete(123) assert len(students) == 4 assert students.delete(1664) == False
def undoExample(): """ An example for doing multiple undo operations. This is a bit more difficult than in Lab2-4 due to the fact that there are now several controllers, and each of them can perform operations that require undo support. Follow the code below and figure out how it works! """ undoController = UndoController() ''' Start client Controller ''' clientRepo = Repository() clientValidator = ClientValidator() clientController = ClientController(undoController, clientValidator, clientRepo) ''' Start car Controller ''' carRepo = Repository() carValidator = CarValidator() carController = CarController(undoController, carValidator, carRepo) ''' Start rental Controller ''' rentRepo = Repository() rentValidator = RentalValidator() rentController = RentalController(undoController, rentValidator, rentRepo, carRepo, clientRepo) print("---> Initial state of repositories") print(clientRepo) print(carRepo) print(rentRepo) ''' We add a client, a new car as well as a rental ''' clientController.create(103, "1900102035588", "Dale") carController.create(201, "CJ 02 ZZZ", "Dacia", "Sandero") rentStart = datetime.strptime("2015-11-26", "%Y-%m-%d") rentEnd = datetime.strptime("2015-11-30", "%Y-%m-%d") rentController.createRental(301, clientRepo.find(103), carRepo.find(201), rentStart, rentEnd) print("---> We added a client, a new car and a rental") print(clientRepo) print(carRepo) print(rentRepo) ''' Now undo the performed operations, one by one ''' undoController.undo() print("---> After 1 undo") print(clientRepo) print(carRepo) print(rentRepo) undoController.undo() print("---> After 2 undos") print(clientRepo) print(carRepo) print(rentRepo) undoController.undo() print("---> After 3 undos") print(clientRepo) print(carRepo) print(rentRepo)
def statisticsExample(): """ An example for the creation of statistics. Several cars, clients and rentals are created and then a statistics is calculated over them. Follow the code below and figure out how it works! """ undoController = UndoController() ''' Start client Controller ''' clientRepo = Repository() clientValidator = ClientValidator() clientController = ClientController(undoController, clientValidator, clientRepo) clientController.create(100, "1820203556699", "Aaron") clientController.create(101, "2750102885566", "Bob") clientController.create(102, "1820604536579", "Carol") # We name the instances so it's easier to create some test values later aaron = clientRepo.find(100) bob = clientRepo.find(101) carol = clientRepo.find(102) ''' Start car Controller ''' carRepo = Repository() carValidator = CarValidator() carController = CarController(undoController, carValidator, carRepo) carController.create(200, "CJ 01 AAA", "Audi", "A3") carController.create(201, "CJ 01 BBB", "Audi", "A4") carController.create(202, "CJ 01 CCC", "Audi", "A5") carController.create(203, "CJ 01 DDD", "Audi", "A6") audiA3 = carRepo.find(200) audiA4 = carRepo.find(201) audiA5 = carRepo.find(202) audiA6 = carRepo.find(203) ''' Start rental Controller ''' rentRepo = Repository() rentValidator = RentalValidator() rentController = RentalController(undoController, rentValidator, rentRepo, carRepo, clientRepo) rentController.createRental(300, aaron, audiA3, datetime.strptime("2015-11-20", "%Y-%m-%d"), datetime.strptime("2015-11-22", "%Y-%m-%d")) rentController.createRental(301, carol, audiA5, datetime.strptime("2015-11-24", "%Y-%m-%d"), datetime.strptime("2015-11-25", "%Y-%m-%d")) rentController.createRental(302, carol, audiA6, datetime.strptime("2015-12-10", "%Y-%m-%d"), datetime.strptime("2015-12-12", "%Y-%m-%d")) rentController.createRental(303, aaron, audiA4, datetime.strptime("2015-11-21", "%Y-%m-%d"), datetime.strptime("2015-11-25", "%Y-%m-%d")) rentController.createRental(304, aaron, audiA3, datetime.strptime("2015-11-24", "%Y-%m-%d"), datetime.strptime("2015-11-27", "%Y-%m-%d")) rentController.createRental(305, bob, audiA5, datetime.strptime("2015-11-26", "%Y-%m-%d"), datetime.strptime("2015-11-27", "%Y-%m-%d")) rentController.createRental(306, carol, audiA6, datetime.strptime("2015-12-15", "%Y-%m-%d"), datetime.strptime("2015-12-20", "%Y-%m-%d")) rentController.createRental(307, bob, audiA4, datetime.strptime("2015-12-01", "%Y-%m-%d"), datetime.strptime("2015-12-10", "%Y-%m-%d")) rentController.createRental(308, carol, audiA4, datetime.strptime("2015-12-11", "%Y-%m-%d"), datetime.strptime("2015-12-15", "%Y-%m-%d")) rentController.createRental(309, aaron, audiA5, datetime.strptime("2015-11-28", "%Y-%m-%d"), datetime.strptime("2015-12-02", "%Y-%m-%d")) for cr in rentController.mostRentedCars(): print (cr)
def undoExample(): """ An example for doing multiple undo operations. This is a bit more difficult than in Lab2-4 due to the fact that there are now several controllers, and each of them can perform operations that require undo support. Follow the code below and figure out how it works! """ undoController = UndoController() ''' Start client Controller ''' clientRepo = Repository() clientValidator = ClientValidator() clientController = ClientController(undoController, clientValidator, clientRepo) ''' Start car Controller ''' carRepo = Repository() carValidator = CarValidator() carController = CarController(undoController, carValidator, carRepo) ''' Start rental Controller ''' rentRepo = Repository() rentValidator = RentalValidator() rentController = RentalController(undoController, rentValidator, rentRepo, carRepo, clientRepo) print("---> Initial state of repositories") print(clientRepo) print(carRepo) print(rentRepo) ''' We add a client, a new car as well as a rental ''' clientController.create(103, "1900102035588", "Dale") carController.create(201, "CJ 02 ZZZ", "Dacia", "Sandero") rentStart = datetime.strptime("2015-11-26", "%Y-%m-%d") rentEnd = datetime.strptime("2015-11-30", "%Y-%m-%d") rentController.createRental(301, clientRepo.find(103), carRepo.find(201), rentStart, rentEnd) print("---> We added a client, a new car and a rental") print(clientRepo) print(carRepo) print(rentRepo) ''' Now undo the performed operations, one by one ''' undoController.undo() print("---> After 1 undo") print(clientRepo) print(carRepo) print(rentRepo) undoController.undo() print("---> After 2 undos") print(clientRepo) print(carRepo) print(rentRepo) undoController.undo() print("---> After 3 undos") print(clientRepo) print(carRepo) print(rentRepo)
def statisticsExample(): """ An example for the creation of statistics. Several cars, clients and rentals are created and then a statistics is calculated over them. Follow the code below and figure out how it works! """ undoController = UndoController() ''' Start client Controller ''' clientRepo = Repository() clientValidator = ClientValidator() clientController = ClientController(undoController, clientValidator, clientRepo) clientController.create(100, "1820203556699", "Aaron") clientController.create(101, "2750102885566", "Bob") clientController.create(102, "1820604536579", "Carol") # We name the instances so it's easier to create some test values later aaron = clientRepo.find(100) bob = clientRepo.find(101) carol = clientRepo.find(102) ''' Start car Controller ''' carRepo = Repository() carValidator = CarValidator() carController = CarController(undoController, carValidator, carRepo) carController.create(200, "CJ 01 AAA", "Audi", "A3") carController.create(201, "CJ 01 BBB", "Audi", "A4") carController.create(202, "CJ 01 CCC", "Audi", "A5") carController.create(203, "CJ 01 DDD", "Audi", "A6") audiA3 = carRepo.find(200) audiA4 = carRepo.find(201) audiA5 = carRepo.find(202) audiA6 = carRepo.find(203) ''' Start rental Controller ''' rentRepo = Repository() rentValidator = RentalValidator() rentController = RentalController(undoController, rentValidator, rentRepo, carRepo, clientRepo) rentController.createRental(300, aaron, audiA3, datetime.strptime("2015-11-20", "%Y-%m-%d"), datetime.strptime("2015-11-22", "%Y-%m-%d")) rentController.createRental(301, carol, audiA5, datetime.strptime("2015-11-24", "%Y-%m-%d"), datetime.strptime("2015-11-25", "%Y-%m-%d")) rentController.createRental(302, carol, audiA6, datetime.strptime("2015-12-10", "%Y-%m-%d"), datetime.strptime("2015-12-12", "%Y-%m-%d")) rentController.createRental(303, aaron, audiA4, datetime.strptime("2015-11-21", "%Y-%m-%d"), datetime.strptime("2015-11-25", "%Y-%m-%d")) rentController.createRental(304, aaron, audiA3, datetime.strptime("2015-11-24", "%Y-%m-%d"), datetime.strptime("2015-11-27", "%Y-%m-%d")) rentController.createRental(305, bob, audiA5, datetime.strptime("2015-11-26", "%Y-%m-%d"), datetime.strptime("2015-11-27", "%Y-%m-%d")) rentController.createRental(306, carol, audiA6, datetime.strptime("2015-12-15", "%Y-%m-%d"), datetime.strptime("2015-12-20", "%Y-%m-%d")) rentController.createRental(307, bob, audiA4, datetime.strptime("2015-12-01", "%Y-%m-%d"), datetime.strptime("2015-12-10", "%Y-%m-%d")) rentController.createRental(308, carol, audiA4, datetime.strptime("2015-12-11", "%Y-%m-%d"), datetime.strptime("2015-12-15", "%Y-%m-%d")) rentController.createRental(309, aaron, audiA5, datetime.strptime("2015-11-28", "%Y-%m-%d"), datetime.strptime("2015-12-02", "%Y-%m-%d")) for cr in rentController.mostRentedCars(): print(cr)
class Test(unittest.TestCase): def setUp(self): self.undoController = UndoController() self.studentRepo = Repository() self.studentValidator = StudentValidator() self.studentController = StudentController(self.studentValidator, self.studentRepo, self.undoController) self.disciplineRepo = Repository() self.disciplineValidator = DisciplineValidator() self.disciplineController = DisciplineController( self.disciplineValidator, self.disciplineRepo, self.undoController) self.gradeRepo = Repository() self.gradeValidator = GradeValidator() self.gradeController = GradeController(self.gradeValidator, self.gradeRepo, self.disciplineRepo, self.studentRepo, self.undoController) def test_student(self): stud = Student(1, "Ancau") self.assertTrue(stud.id == 1 and stud.name == "Ancau") self.assertTrue(len(self.studentRepo) == 0) anca = self.studentController.create(1, "Ancau Adrian") popa = self.studentController.create(2, "Popa Cristian") self.assertRaises(StudentException, self.studentController.create, 2, "Niganinga") self.assertTrue(self.studentController.find(1) == anca) self.assertTrue(self.studentRepo.find(2) == popa) self.assertEqual(len(self.studentRepo), 2) cascade_remove(self.studentController, self.gradeController, self.undoController, 2) self.assertTrue(len(self.studentRepo), 1) self.undoController.undo() self.assertTrue(len(self.studentRepo), 2) self.undoController.redo() self.assertTrue(len(self.studentRepo), 1) def test_discipline(self): math = self.disciplineController.create(1, "Math") engl = self.disciplineController.create(2, "English") self.assertEqual(len(self.disciplineRepo), 2) self.assertEqual(self.disciplineRepo.find(1), math) self.assertEqual(self.disciplineController.find(2), engl) self.disciplineController.update(2, 'History') self.assertEqual(self.disciplineController.find(2), Discipline(2, 'History')) def test_grade(self): first = self.gradeController.create(1, 1, 10) second = self.gradeController.create(2, 1, 7) self.assertRaises(GradeException, self.gradeController.create, 1, 1, 12) self.gradeController.remove_single_grade(1, 1, 10) self.assertNotIn(first, self.gradeController.all_students(1)) def undo_test(self): self.disciplineController.create(3, "Undo test") self.undoController.undo() self.assertNotIn(Discipline(3, "Undo test"), self.disciplineRepo.get_all()) self.undoController.redo() self.assertIn(Discipline(3, "Undo test"), self.disciplineRepo.get_all())