def setUp(self): self.__clientRepository = Repository(ClientValidator) self.__client1 = Client(1, "Aurel") self.__client2 = Client(2, "Viorel") self.__clientRepository.save(self.__client1) self.__clientRepository.save(self.__client2)
def setUp(self): TestCase.setUp(self) self.__clientRepository = Repository(ClientValidator) self.__clientRepository.save(Client(1, "Aurica")) self.__clientRepository.save(Client(2, "Daniel")) self.__clientControler = ClientControler(self.__clientRepository)
def testSave(self): #We need an empty repo for this test self.__clientRepository = Repository(ClientValidator) self.assertTrue(self.__clientRepository.save(self.__client1), "Could not create student") self.assertTrue(self.__clientRepository.save(self.__client2), "Could not create student") # self.assertRaises(RepositoryException, self.__clientRepository.save(self.__client1)) try: self.__clientRepository.save(self.__client1) self.fail("Duplicate ID at saving") except RepositoryException: pass try: self.__clientRepository.save(self.__client2) self.fail("Duplicate ID at saving") except RepositoryException: pass try: self.__clientRepository.save(Client("ab", "Ada")) self.fail("ID must be an integer") except RepositoryException: pass self.assertEqual(len(self.__clientRepository.get_all()), 2, "There must be 2 clients already saved") self.assertEqual(self.__clientRepository.find_by_id(1), self.__client1, "Client 1 was not save properly") self.assertEqual(self.__clientRepository.find_by_id(2), self.__client2, "Client 2 was not save properly")
def testEqual(self): self.assertFalse(self.__movie1 == self.__movie2, "Movie 1 and movie 2 are not the same") try: self.__movie1 == Client(1, "Da") self.fail("A Movie cannot be a Client") except TypeError: pass
def testEqual(self): self.assertFalse(self.__rental1 == self.__rental2, "Rental 1 and Rental 2 are not the same") try: self.__rental1 == Client(1, "Da") self.fail("A Rental cannot be a Client") except TypeError: pass
def testUpdate(self): try: self.__clientRepository.update(3, Client(3,"Aurel")) self.fail("Client with id 3 does not exist") except RepositoryException: pass try: self.__clientRepository.update(1,Client(2,"Anakin")) self.fail("Id's mismatch. You are not allowed to change the Id.") except RepositoryException: pass self.__clientRepository.update(1,Client(1,"Antoniu")) self.assertEqual(self.__clientRepository.find_by_id(1).entityName, "Antoniu", "His name must be Antoniu") self.__clientRepository.update(1,Client(1,"Aurel")) self.assertEqual(self.__clientRepository.find_by_id(1).entityName, "Aurel", "His name must be Aurel")
def setUp(self): TestCase.setUp(self) self.__rentalRepository = Repository(RentalValidator) self.__movieRepository = Repository(MovieValidator) self.__clientRepository = Repository(ClientValidator) self.__movieRepository.save(Movie(1, "Ana", "Bun", "Comedie")) self.__clientRepository.save(Client(1, "Aurica")) self.__rentalRepository.save( Rental(1, 1, 1, datetime.date(1997, 10, 20), datetime.date(1997, 11, 10), None)) self.__movieRepository.save(Movie(2, "Dana Film", "Nebun", "Drama")) self.__clientRepository.save(Client(2, "Daniel")) self.__rentalRepository.save( Rental(2, 2, 2, datetime.date(2016, 12, 15), datetime.date(2017, 1, 5), None)) self.__movieRepository.save(Movie(3, "Bolt", "D-amar", "Actiune")) self.__clientRepository.save(Client(3, "Liviu")) self.__rentalRepository.save( Rental(3, 3, 3, datetime.date(1997, 10, 20), datetime.date(1997, 11, 10), datetime.date(1997, 11, 13))) self.__movieRepository.save(Movie(4, "Flash", "Great", "Actiune")) self.__clientRepository.save(Client(4, "Radu")) self.__rentalRepository.save( Rental(4, 4, 4, datetime.date(1997, 10, 20), datetime.date(1997, 11, 10), datetime.date(1997, 11, 5))) self.__rentalRepository.save( Rental(5, 4, 4, datetime.date(1997, 10, 20), datetime.date(1997, 11, 10), datetime.date(1997, 11, 5))) self.__statisticsController = StatisticsControler( self.__rentalRepository, self.__movieRepository, self.__clientRepository)
def __loadFromFile(self, fileName): with open(fileName) as file: for line in file: line = line.strip('\n') arguments = line.split(',') if self.__validator == MovieValidator: super().save( Movie(int(arguments[0]), arguments[1], arguments[2], arguments[3])) if self.__validator == ClientValidator: super().save(Client(int(arguments[0]), arguments[1])) if self.__validator == RentalValidator: rentalDate = arguments[3].split(".") dueDate = arguments[4].split(".") if arguments[5] == "-": super().save( Rental( int(arguments[0]), int(arguments[1]), int(arguments[2]), datetime(int(rentalDate[0]), int(rentalDate[1]), int(rentalDate[2])), datetime(int(dueDate[0]), int(dueDate[1]), int(dueDate[2])), None)) else: returnedDate = arguments[5].split(".") super().save( Rental( int(arguments[0]), int(arguments[1]), int(arguments[2]), datetime(int(rentalDate[0]), int(rentalDate[1]), int(rentalDate[2])), datetime(int(dueDate[0]), int(dueDate[1]), int(dueDate[2])), datetime(int(returnedDate[0]), int(returnedDate[1]), int(returnedDate[2]))))
class ClientTest(TestCase): def setUp(self): self.__client1 = Client(1,"Lamaiel") self.__client2 = Client(2,"Mandarin") def testGettes(self): self.assertEqual(self.__client1.get_entity_id(), 1, "Client 1 id must be 1") self.assertEqual(self.__client2.get_entity_id(), 2, "Client 2 id must be 2") self.assertEqual(self.__client1.get_entity_name(), "Lamaiel", "Client 1 has name Lamaiel") self.assertEqual(self.__client2.get_entity_name(), "Mandarin", "Client 1 has name Mandarin") def testSetters(self): self.__client1.set_entity_name("Portocal") self.assertEqual(self.__client1.get_entity_name(), "Portocal", "Client 1 has name Portocal now") def testEqual(self): self.assertFalse(self.__client1 == self.__client2, "Client 1 and client 2 are not the same") try: self.__client1 == Movie(1, "Da", "Da", "Da") self.fail("A client cannot be a movie") except TypeError: pass
def update(self, clientId, clientName): self.__clientRepository.update(clientId, Client(clientId, clientName))
def add(self, clientId, clientName): self.__clientRepository.save(Client(clientId, clientName))
def setUp(self): self.__client1 = Client(1,"Lamaiel") self.__client2 = Client(2,"Mandarin")
l = MyList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) shuffle(l) print(l) # for i in range(1,len(l)): # j = i # element = l[i] # while j > 0 and element < l[j-1]: # l[j] = l[j-1] # j -= 1 # # l[j] = element # # for j in range(0,len(l)): # m = min(l[j:]) # i = l.index(m) # # l[i],l[j] = l[j],l[i] # v = sorted(l) # while True: # if l == v: # break # shuffle(l) l = MyList(Client(1, "Aurel"), Client(2, "Andrei"), Client(3, "Viorel"), Client(4, "Razvan")) l = Sorter.sort(l, lambda x: x.entityName, reverse=False) l = Sorter.filter(l, lambda x: "A" in x.entityName) for e in l: print(e)