예제 #1
0
    def testRentBook(self):
        client1 = Client(1, "Name1")
        client2 = Client(2, "Name2")

        book1 = Book(1, "Title", "Description", "Author")
        book2 = Book(2, "Title1", "Description1", "Author1")

        clientRepo = Repository()
        bookRepo = Repository()
        functions = ClientController(clientRepo, Statistics(clientRepo))
        functiom = BookController(bookRepo, Statistics(bookRepo))

        functions.addClient(client2.getId(), client2.getName())
        functions.addClient(client1.getId(), client1.getName())

        functiom.addBook(book1.getId(), book1.getTitle(), book1.getDescription(), book1.getAuthor())
        functiom.addBook(book2.getId(), book2.getTitle(), book2.getDescription(), book2.getAuthor())
        rentalRepo = Repository()
        functionsr = RentalController(bookRepo, clientRepo, rentalRepo, Statistics(rentalRepo))

        msg1 = functionsr.rentBook(book1.getId(), client1.getId(), createDateFromString("23.11.2017"), "30.11.2017")

        self.assertTrue(len(msg1) == 0)
        self.assertTrue(functionsr.getRentals()[0].getBookId() == book1.getId())
        self.assertTrue(functionsr.getRentals()[0].getClientId() == client1.getId())

        msg2 = functionsr.rentBook(book2.getId, client2.getId(), createDateFromString("20.11.2017"), "19.11.2017")
        self.assertTrue(msg2 == "Inconsistent dates")
예제 #2
0
    def testAddClient(self):
        client1 = Client(1, "Name1")
        client2 = Client(1, "Name2")
        repo = Repository()
        functions = ClientController(repo, Statistics(repo))

        msg1 = functions.addClient(client1.getId(), client1.getName())
        self.assertTrue(len(msg1) == 0)
        self.assertTrue(functions.getClients()[0].getId() == 1)

        msg2 = functions.addClient(client2.getId(), client2.getName())
        self.assertTrue(msg2 == "Cannot add an existing element")

        self.assertTrue(functions.getClients()[0].getId() == 1)
예제 #3
0
    def testClientController(self):
        repo = Repository()
        contr = ClientController(repo)
        undoController = Undo()
        contr.addUndoController(undoController)

        self.assertEqual( contr.addClient(Client(1, "alice", 1111111111111)) ,  True )
예제 #4
0
    def testClientController(self):
        repo = Repository()
        contr = ClientController(repo)
        undoController = Undo()
        contr.addUndoController(undoController)

        self.assertEqual(contr.addClient(Client(1, "alice", 1111111111111)),
                         True)
예제 #5
0
def testClientController():
    repo = Repository()
    contr = ClientController(repo)
    undoController = Undo()
    contr.addUndoController(undoController)

    assert contr.addClient(Client(1, "alice", 1111111111111)) == True

    print("ClientController tests ran successfully!")
예제 #6
0
파일: tests.py 프로젝트: p0licat/university
def testClientController():
    repo = Repository()
    contr = ClientController(repo)
    undoController = Undo()
    contr.addUndoController(undoController)

    assert contr.addClient(Client(1, "alice", 1111111111111)) == True


    print ("ClientController tests ran successfully!")
예제 #7
0
    def testRemoveClient(self):
        client1 = Client(1, "Name1")
        client2 = Client(2, "Name2")
        repo = Repository()
        functions = ClientController(repo, Statistics(repo))

        functions.addClient(client1.getId(), client1.getName())
        functions.addClient(client2.getId(), client2.getName())

        msg1 = functions.removeClient(1)

        self.assertTrue(len(msg1) == 0)
        self.assertTrue(functions.getClients()[0].getId() == client2.getId())
        self.assertTrue(functions.getClients()[0].getName() == client2.getName())

        msg2 = functions.removeClient(1)

        self.assertTrue(msg2 == "The provided ID does not exist")
        self.assertTrue(functions.getClients()[0].getId() == client2.getId())
        self.assertTrue(functions.getClients()[0].getName() == client2.getName())
예제 #8
0
class TestClientController(unittest.TestCase):
    def setUp(self):
        self.repo = Repository()
        self.rentalRepo = Repository()
        self.Ucontroller = UndoController()
        self.client = Client(11, 'alex')
        self.client2 = Client(12, 'ana')
        self.controller = ClientController(self.repo, self.Ucontroller,
                                           self.rentalRepo)

    def test_something(self):
        self.assertRaises(Exception, self.Ucontroller.undo)
        self.assertRaises(Exception, self.Ucontroller.redo)
        self.Ucontroller.newOperation()
        self.controller.addClient(self.client)
        self.assertEqual(len(self.repo), 1)
        self.Ucontroller.newOperation()
        self.controller.removeClient(11)
        self.assertEqual(len(self.repo), 0)
        self.Ucontroller.newOperation()
        self.controller.addClient(self.client)
        self.Ucontroller.newOperation()
        self.controller.updateClient(self.client)
        self.Ucontroller.newOperation()
        self.controller.addClient(self.client2)
        self.assertEqual(len(self.controller.getAllClients()), 2)
        self.assertRaises(ControllerException, self.controller.searchClient,
                          'nu')
        self.assertRaises(ControllerException, self.controller.searchClient,
                          '')
        self.assertEqual(len(self.controller.searchClient('a')), 2)
        self.Ucontroller.newOperation()
        self.controller.removeClient(12)
        self.Ucontroller.undo()
        self.assertEqual(len(self.controller.getAllClients()), 2)
        self.Ucontroller.redo()
        self.assertEqual(len(self.controller.getAllClients()), 1)