def test_init(self):
     with self.assertRaises(ValueError):
         testClient = ClientDAO(1)
     with self.assertRaises(ValueError):
         testClient = ClientDAO([])
     self.assertEqual(self.client.getName(), "Dani", 'client name got wrong')
     self.assertRaises(TypeError, lambda: self.client.getId(), 'default client id not None')
 def __loadRepo(self):
     self.__loadFileReadMode()
     for line in self.__file:
         splitLine = line.split()
         clientToAdd = ClientDAO(splitLine[1])
         clientToAdd.setClientId(int(splitLine[0]))
         super().addClientWithId(clientToAdd)
     self.__closeFile()
Exemple #3
0
 def test_undoUpdateClient(self):
     updatedClient = ClientDAO("aaa")
     updatedClient.setClientId(0)
     self.undoRunner.addCommandToUndo(["update", "0", "aaa"], self.clientController, self.stack, "client", self.commandsStack)
     self.clientController.updateClientWithId(0, updatedClient)
     self.assertEqual(self.clientController.getClientWithId(0).getName(), "aaa")
     self.undoRunner.undo(self.clientController, self.movieController, self.rentalController, self.stack)
     self.assertEqual(self.clientController.getClientWithId(0).getName(), "Dani")
Exemple #4
0
 def test_undoAddClient(self):
     self.undoRunner.addCommandToUndo(["add", "Da"], self.clientController, self.stack, "client", self.commandsStack)
     self.clientController.addClient(ClientDAO("Da"))
     self.undoRunner.addCommandToUndo(["add", "Iani"], self.clientController, self.stack, "client", self.commandsStack)
     self.clientController.addClient(ClientDAO("Iani"))  # 14
     self.assertEqual(len(self.clientController.getRepo().getList()), 14)
     self.assertEqual(self.clientController.getClientWithId(13).getName(), "Iani")
     self.undoRunner.undo(self.clientController, self.movieController, self.rentalController, self.stack)
     self.assertEqual(len(self.clientController.getRepo().getList()), 13)
     with self.assertRaises(ObjectNotInCollectionException):
         self.clientController.getClientWithId(13)
Exemple #5
0
 def setUp(self):
     self.movieRepo = MovieRepo()
     self.movieRepo.addMovie(MovieDAO("Titanic", "lovely", "Romance"))
     self.movieRepo.addMovie(MovieDAO("Avatar", "lovely1", "Romance1"))
     self.movieRepo.addMovie(MovieDAO("TestMovie", "lovely1", "Romance1"))
     self.clientRepo = ClientRepo()
     self.clientRepo.addClient(ClientDAO("dani"))
     self.clientRepo.addClient(ClientDAO("ancu"))
     self.rentalRepo = RentalRepo()
     self.rentalRepo.addRental(RentalDAO(0, 0, Date(5, 4, 2018), Date(7, 9, 2020), self.movieRepo, self.clientRepo))
     self.rentalRepo.addRental(RentalDAO(1, 1, Date(5, 4, 2018), Date(7, 9, 2020), self.movieRepo, self.clientRepo))
     self.printer = Printer()
Exemple #6
0
 def setUp(self):
     self.movieRepo = MovieRepo()
     self.movieRepo.addMovie(MovieDAO("Titanic", "lovely", "Romance"))
     self.clientRepo = ClientRepo()
     self.clientRepo.addClient(ClientDAO("dani"))
     self.rental = RentalDAO(0, 0, Date(5, 4, 2018), Date(7, 9, 2020),
                             self.movieRepo, self.clientRepo)
Exemple #7
0
 def test_sortByAttribute(self):
     client1 = ClientDAO("a")
     client1.setClientId(1)
     client2 = ClientDAO("b")
     client2.setClientId(0)
     testList = [client1, client2]
     sortListByObjectAttribute(testList, lambda a, b: True if a < b else False, lambda a: a.getId())
     self.assertEqual(testList, [client2, client1])
     sortListByObjectAttribute(testList, lambda a, b: True if a > b else False, lambda a: a.getId())
     self.assertEqual(testList, [client1, client2])
Exemple #8
0
 def test_removeClient(self):
     self.clientFileRepository.addClient(ClientDAO("damo"))
     self.clientFileRepository.addClient(ClientDAO("ancu"))
     self.clientFileRepository.removeClientWithId(1)
     self.assertEqual(len(self.clientFileRepository.getList()), 1)
     testClient = ClientDAO("damo")
     testClient.setClientId(0)
     self.assertEqual(self.clientFileRepository.getList(), [testClient])
     with self.assertRaises(ObjectNotInCollectionException):
         self.clientFileRepository.removeClientWithId(5)
 def test_removeClient(self):
     printer = Printer()
     printer.printList(self.clientRepo.getList())
     print("bbbbb")
     self.clientRepo.addClient(ClientDAO("damo"))
     self.clientRepo.addClient(ClientDAO("ancu"))
     self.clientRepo.removeClientWithId(1)
     self.assertEqual(len(self.clientRepo.getList()), 1)
     testClient = ClientDAO("damo")
     testClient.setClientId(0)
     self.assertEqual(self.clientRepo.getList(), [testClient])
     with self.assertRaises(ObjectNotInCollectionException):
         self.clientRepo.removeClientWithId(5)
Exemple #10
0
 def test_hasClientWithId(self):
     client1 = ClientDAO("aaa")
     client1.setClientId(1)
     client2 = ClientDAO("bb")
     client2.setClientId(2)
     client3 = ClientDAO("958")
     client3.setClientId(3)
     self.clientFileRepository.addClientWithId(client1)
     self.clientFileRepository.addClientWithId(client2)
     self.clientFileRepository.addClientWithId(client3)
     self.assertEqual(self.clientFileRepository.hasClientWithId(1), True)
     self.assertEqual(self.clientFileRepository.hasClientWithId(4), False)
Exemple #11
0
 def test_getList(self):
     client1 = ClientDAO("aaa")
     client1.setClientId(1)
     client2 = ClientDAO("bb")
     client2.setClientId(2)
     client3 = ClientDAO("958")
     client3.setClientId(4)
     self.clientFileRepository.addClientWithId(client1)
     self.clientFileRepository.addClientWithId(client2)
     self.clientFileRepository.addClientWithId(client3)
     self.assertEqual(self.clientFileRepository.getList(),
                      [client1, client2, client3])
Exemple #12
0
 def test_updateClient(self):
     self.clientFileRepository.addClient(ClientDAO("damo"))
     self.clientFileRepository.addClient(ClientDAO("ancu"))
     testClient1 = ClientDAO("ancu")
     testClient1.setClientId(0)
     testClient2 = ClientDAO("ancu")
     testClient2.setClientId(1)
     self.clientFileRepository.updateClientWithId(0, ClientDAO("ancu"))
     self.assertEqual(self.clientFileRepository.getList(),
                      [testClient1, testClient2])
Exemple #13
0
 def test_addClient(self):
     self.clientFileRepository.addClient(ClientDAO("damo"))
     self.assertEqual(((self.clientFileRepository.getList())[0]).getId(), 0)
     self.assertEqual(((self.clientFileRepository.getList())[0]).getName(),
                      "damo")
Exemple #14
0
 def __doUpdateClient(self, optionInputWordList):
     self.clientController.updateClientWithId(int(optionInputWordList[1]),
                                              ClientDAO(optionInputWordList[2]))
Exemple #15
0
 def __doAddClient(self, optionInputWordList):
     self.clientController.addClient(ClientDAO(optionInputWordList[1]))
 def setUp(self):
     self.client = ClientDAO("Dani")
Exemple #17
0
 def addClient(self, command, clientController):
     # return "client" "add" "client id" "client name"
     client = ClientDAO(command[3])
     client.setClientId(int(command[2]))
     clientController.addClientWithId(client)
 def populateWithMany(self):
     self.addClient(ClientDAO("Dani"))
     self.addClient(ClientDAO("Ancu"))
     self.addClient(ClientDAO("Ana"))
     self.addClient(ClientDAO("Betu"))
     self.addClient(ClientDAO("Sami"))
     self.addClient(ClientDAO("Dave"))
     self.addClient(ClientDAO("Mami"))
     self.addClient(ClientDAO("Tati"))
     self.addClient(ClientDAO("Sergiu"))
     self.addClient(ClientDAO("Adi"))
     self.addClient(ClientDAO("Cristi"))
     self.addClient(ClientDAO("Anisoara"))
     self.addClient(ClientDAO("AA"))
     self.addClient(ClientDAO("AA1"))
     self.addClient(ClientDAO("AA2"))
     self.addClient(ClientDAO("AA3"))
     self.addClient(ClientDAO("AA4"))
     self.addClient(ClientDAO("AA5"))
     self.addClient(ClientDAO("AA6"))
     self.addClient(ClientDAO("AA7"))
     self.addClient(ClientDAO("AA8"))
     self.addClient(ClientDAO("AA9"))
     self.addClient(ClientDAO("AA0"))
     self.addClient(ClientDAO("AA12"))
     self.addClient(ClientDAO("AA11"))
     self.addClient(ClientDAO("AA22"))
     self.addClient(ClientDAO("AA33"))
     self.addClient(ClientDAO("AA55"))
     self.addClient(ClientDAO("AA44"))
     self.addClient(ClientDAO("AA66"))
     self.addClient(ClientDAO("AA77"))
     self.addClient(ClientDAO("AA88"))
     self.addClient(ClientDAO("AA99"))
     self.addClient(ClientDAO("AA000"))
     self.addClient(ClientDAO("AA111"))
     self.addClient(ClientDAO("AA222"))
     self.addClient(ClientDAO("AA333"))
     self.addClient(ClientDAO("AA444"))
     self.addClient(ClientDAO("AA555"))
     self.addClient(ClientDAO("AA666"))
     self.addClient(ClientDAO("AA777"))
     self.addClient(ClientDAO("A88A"))
     self.addClient(ClientDAO("AA999"))
     self.addClient(ClientDAO("AA000"))
     self.addClient(ClientDAO("AA11111"))
     self.addClient(ClientDAO("AdAAi"))
     self.addClient(ClientDAO("CriAAsti"))
     self.addClient(ClientDAO("AnisAAoara"))
 def populateWithFew(self):
     self.addClient(ClientDAO("Dani"))
     self.addClient(ClientDAO("Ancu"))
     self.addClient(ClientDAO("Ana"))
     self.addClient(ClientDAO("Betu"))
     self.addClient(ClientDAO("Sami"))
     self.addClient(ClientDAO("Dave"))
     self.addClient(ClientDAO("Mami"))
     self.addClient(ClientDAO("Tati"))
     self.addClient(ClientDAO("Sergiu"))
     self.addClient(ClientDAO("Adi"))
     self.addClient(ClientDAO("Cristi"))
     self.addClient(ClientDAO("Anisoara"))
Exemple #20
0
 def updateClient(self, commandToRedo, clientController):
     clientController.updateClientWithId(int(commandToRedo[1]),
                                              ClientDAO(commandToRedo[2]))
Exemple #21
0
 def addClient(self, commandToRedo, clientController):
     clientController.addClient(ClientDAO(commandToRedo[1]))
 def test_updateClient(self):
     printer = Printer()
     printer.printList(self.clientRepo.getList())
     print("ccccccccccc")
     self.clientRepo.addClient(ClientDAO("damo"))
     self.clientRepo.addClient(ClientDAO("ancu"))
     testClient1 = ClientDAO("ancu")
     testClient1.setClientId(0)
     testClient2 = ClientDAO("ancu")
     testClient2.setClientId(1)
     self.clientRepo.updateClientWithId(0, ClientDAO("ancu"))
     self.assertEqual(self.clientRepo.getList(), [testClient1, testClient2])
class TestClient(TestCase):
    def setUp(self):
        self.client = ClientDAO("Dani")

    def tearDown(self):
        self.client = None

    def test_init(self):
        with self.assertRaises(ValueError):
            testClient = ClientDAO(1)
        with self.assertRaises(ValueError):
            testClient = ClientDAO([])
        self.assertEqual(self.client.getName(), "Dani", 'client name got wrong')
        self.assertRaises(TypeError, lambda: self.client.getId(), 'default client id not None')

    def test_setClientId(self):
        self.client.setClientId(5)
        self.assertEqual(self.client.getId(), 5, "client id set wrong")

    def test_setWrongId(self):
        self.assertRaises(ValueError, lambda: self.client.setClientId(-3))
        self.assertRaises(ValueError, lambda: self.client.setClientId([]))
        self.assertRaises(ValueError, lambda: self.client.setClientId("asd"))
        self.assertRaises(ValueError, lambda: self.client.setClientId(3.5))
        self.assertRaises(ValueError, lambda: self.client.setClientId({}))

    def test_setClientIdSecondTime(self):
        self.client.setClientId(6)
        with self.assertRaises(AlreadySetException):
            self.client.setClientId(9)
Exemple #24
0
 def updateClient(self, command, clientController):
     # return "client" "update" "client id" "old name"
     updatedClient = ClientDAO(command[3])
     updatedClient.setClientId(int(command[2]))
     clientController.updateClientWithId(int(command[2]), updatedClient)