Ejemplo n.º 1
0
 def test_AddRental2(self):
     open("testRentalsRental", 'w').close()
     open("testRentalsMovie", 'w').close()
     open("testRentalsClients", 'w').close()
     repo = Repository("testRentalsRental", "test")
     movieRepo = Repository("testRentalsMovie", "tes2")
     mc = MovieController(movieRepo)
     mc.addMovie("2", "title", "sds", "action")
     clientRepo = Repository("testRentalsClients", "test3")
     cc = ClientController(clientRepo)
     cc.addClient('2', 'Ghita')
     controller = RentalController(repo, cc, mc)
     self.assertEqual(
         controller.addRental('2', '2', '2', "2017-10-23", "2018-10-23",
                              -1), True)
Ejemplo n.º 2
0
 def test_raises(self):
     repo = Repository("testRentalsRental", "test")
     movieRepo = Repository("testRentalsMovie", "tes2")
     mc = MovieController(movieRepo)
     clientRepo = Repository("testRentalsClients", "test3")
     cc = ClientController(clientRepo)
     controller = RentalController(repo, cc, mc)
     self.controller.undo()
    def config(self):
        clientRepo = None
        movieRepo = None
        rentalRepo = None
        if self.__settings['repository'] == "text-file":
            clientRepo = FileRepository(self.__settings["clients"],
                                        "Client repo", Client.clientToFile,
                                        Client.clientFromFile)
            movieRepo = FileRepository(self.__settings["movies"], "Movie Repo",
                                       Movie.movieToFile, Movie.movieFromFile)
            rentalRepo = FileRepository(self.__settings["rentals"],
                                        "Rental repo", Rental.rentalToFile,
                                        Rental.rentalFromFile)
        if self.__settings['repository'] == "in-memory":
            clientRepo = InMemoryRepository()
            movieRepo = InMemoryRepository()
            rentalRepo = InMemoryRepository()

        if self.__settings['repository'] == "binary":
            clientRepo = PickleRepo(self.__settings["clients"], "Client repo")
            movieRepo = PickleRepo(self.__settings["movies"], "Movie Repo")
            rentalRepo = PickleRepo(self.__settings["rentals"], "Rental repo")

        if self.__settings['repository'] == 'json':
            clientRepo = JsonRepo(self.__settings["clients"], "ClientRepo",
                                  Client.clientFromJson)
            movieRepo = JsonRepo(self.__settings["movies"], "Movie Repo",
                                 Movie.movieFromJson)
            rentalRepo = JsonRepo(self.__settings["rentals"], "Rental repo",
                                  Rental.rentalFromJson)
        if self.__settings['repository'] == "sql":
            clientRepo = SqlRepo(config, Client, Client.clientToSql, "client",
                                 "(id,name)")
            movieRepo = SqlRepo(config, Movie, Movie.movieToSql, "movie",
                                "(id,title,description,genre)")
            rentalRepo = SqlRepo(
                config, Rental, Rental.rentalToSql, "rental",
                "(id,movieId,clientId,rentedDate,dueDate,returnedDate)")
        mc = MovieController(movieRepo)
        cc = ClientController(clientRepo)
        rc = RentalController(rentalRepo, cc, mc)
        if self.__settings['ui'] == "console":
            console = Console.ConsoleUI(mc, cc, rc)
            console.mainMenu()
        if self.__settings['ui'] == 'gui':
            MainApp.clientController = cc
            MainApp.rentalController = rc
            MainApp.movieController = mc
            pyforms.startApp(MainApp)
 def setUp(self):
     self.Client = Client(3, 'name')
     self.repo = Repository('testClients', 'testClients')
     self.controller = ClientController(self.repo)
     if self.controller.getClientById(77) is not False:
         self.controller.removeClient(77)
     if self.controller.getClientById(772) is not False:
         self.controller.removeClient(772)
     if self.controller.getClientById(773) is not False:
         self.controller.removeClient(773)
     if self.controller.getClientById(23) is False:
         self.controller.addClient("23", "name")
     if self.controller.getClientById('233333') is not False:
         self.controller.removeClient('233333')
     if self.controller.getClientById(20) is False:
         self.controller.addClient("20", "name")
     if self.controller.getClientById(200) is False:
         self.controller.addClient("200", "name2")
     if self.controller.getClientById(90) is False:
         self.controller.addClient("90", "name3")
     if self.controller.getClientById(123) is False:
         self.controller.addClient("123", "tion")
     if self.controller.getClientById(234) is False:
         self.controller.addClient("234", "t")
     if self.controller.getClientById(33) is False:
         self.controller.addClient("33", "tit")
     if self.controller.getClientById(90) is not False:
         self.controller.removeClient(99)
     if self.controller.getClientById(323) is False:
         self.controller.addClient("323", "tit")
     if self.controller.getClientById(929) is not False:
         self.controller.removeClient(929)
     if self.controller.getClientById(33) is False:
         self.controller.addClient("333", "tin")
     if self.controller.getClientById(939) is not False:
         self.controller.removeClient(939)
Ejemplo n.º 5
0
 def test_removeRental2(self):
     f = open("testRentalsRental", 'w')
     f.write("2, 2, 2,  2017-11-20, 2019-11-20, -1")
     f.close()
     f = open("testRentalsMovie", 'w')
     f.write("2, title, sdfs, action")
     f.close()
     f = open("testRentalsClients", 'w')
     f.write("2, title")
     f.close()
     repo = Repository("testRentalsRental", "test")
     movieRepo = Repository("testRentalsMovie", "tes2")
     mc = MovieController(movieRepo)
     clientRepo = Repository("testRentalsClients", "test3")
     cc = ClientController(clientRepo)
     controller = RentalController(repo, cc, mc)
     self.assertEqual(controller.removeRental('2'), True)
Ejemplo n.º 6
0
 def test_getRentalById2(self):
     f = open("testRentalsRental", 'w')
     f.write("2, 2, 2,  2017-11-20, 2019-11-20, -1")
     f.close()
     f = open("testRentalsMovie", 'w')
     f.write("2, title, sdfs, action")
     f.close()
     f = open("testRentalsClients", 'w')
     f.write("2, title")
     f.close()
     repo = Repository("testRentalsRental", "test")
     movieRepo = Repository("testRentalsMovie", "tes2")
     mc = MovieController(movieRepo)
     clientRepo = Repository("testRentalsClients", "test3")
     cc = ClientController(clientRepo)
     controller = RentalController(repo, cc, mc)
     rental = Rental("2", "2", "2", "2017-11-20", "2019-11-20", "-1")
     self.assertEqual(controller.getRentalById(2), rental)
Ejemplo n.º 7
0
 def test_UpdateRental(self):
     f = open("testRentalsRental", 'w')
     f.write("1, 1, 1,  2017-11-20, 2019-11-20, -1")
     f.close()
     f = open("testRentalsMovie", 'w')
     f.write("1, title, sdfs, action")
     f.close()
     f = open("testRentalsClients", 'w')
     f.write("1, title")
     f.close()
     repo = Repository("testRentalsRental", "test")
     movieRepo = Repository("testRentalsMovie", "tes2")
     mc = MovieController(movieRepo)
     clientRepo = Repository("testRentalsClients", "test3")
     cc = ClientController(clientRepo)
     controller = RentalController(repo, cc, mc)
     self.assertEqual(
         controller.updateRental('1', '1', '1', '1', '2017-01-23',
                                 '2017-11-20', -1), True)
Ejemplo n.º 8
0
 def test_returnedMovie(self):
     f = open("testRentalsRental", 'w')
     f.write("1, 2, 2,  2017-11-20, 2019-11-20, -1")
     f.close()
     f = open("testRentalsMovie", 'w')
     f.write("1, title, sdfs, action")
     f.close()
     f = open("testRentalsClients", 'w')
     f.write("1, title")
     f.close()
     repo = Repository("testRentalsRental", "test")
     movieRepo = Repository("testRentalsMovie", "tes2")
     mc = MovieController(movieRepo)
     clientRepo = Repository("testRentalsClients", "test3")
     cc = ClientController(clientRepo)
     controller = RentalController(repo, cc, mc)
     self.assertEqual(controller.returnAMovie("1"), True)
     self.assertRaises(ValueError, controller.removeAllAppOfMovie, '2s')
     self.assertRaises(ValueError, controller.removeAllAppOfClient, '2s')
     self.assertRaises(ValueError, controller.updateClientIdFromRental,
                       '2s', '2')
Ejemplo n.º 9
0
 def test_RentalSetters(self):
     r = Rental(1, 2, 3, "2017-10-20", "2017-11-20", "2018-01-20")
     r.id = 4
     r.movieId = 5
     r.clientId = 6
     r.returnedDate = "2017-12-20"
     r.dueDate = "2017-12-20"
     r.rentedDate = "2017-08-09"
     a = r.dueDate
     a = r.returnedDate
     self.assertNotEqual(
         r, Rental(4, 5, 6, "2017-12-20", "2017-12-20", "2017-08-09"))
     repo = Repository("testRentalsRental", "test")
     movieRepo = Repository("testRentalsMovie", "tes2")
     mc = MovieController(movieRepo)
     clientRepo = Repository("testRentalsClients", "test3")
     cc = ClientController(clientRepo)
     controller = RentalController(repo, cc, mc)
     self.assertEqual(controller.lateRentals(), [])
     self.assertEqual(controller.allRentedMovies(), mc.getAllMovies())
     s = mc.getAllMovies()
     self.assertEqual(controller.mostRentedMoviesByNumber(),
                      controller.mostRentedMoviesByNumber())
     self.assertEqual(controller.mostRentedMoviesByDays(),
                      controller.mostRentedMoviesByDays())
     self.assertRaises(ValueError, controller.updateClientIdFromRental, "s",
                       "2")
     self.assertRaises(ValueError, controller.updateClientIdFromRental, "2",
                       "s")
     controller.removeAllAppOfClient("1")
     controller.removeAllAppOfMovie("1")
     controller.updateMovieIdFromRental("1", "1")
     controller.updateClientIdFromRental("1", "1")
     self.assertRaises(ValueError, controller.updateClientIdFromRental, "2",
                       "s")
     self.assertRaises(ValueError, controller.updateClientIdFromRental, "s",
                       "2")
 def test_GetAllClients(self):
     repo2 = Repository('ClientUpdateTest', "test2")
     client = Client("2", "223")
     controller2 = ClientController(repo2)
     l = controller2.getAllClients()
     self.assertEqual(controller2.getAllClients(), [client])
class ClientTestCase(unittest.TestCase):
    def setUp(self):
        self.Client = Client(3, 'name')
        self.repo = Repository('testClients', 'testClients')
        self.controller = ClientController(self.repo)
        if self.controller.getClientById(77) is not False:
            self.controller.removeClient(77)
        if self.controller.getClientById(772) is not False:
            self.controller.removeClient(772)
        if self.controller.getClientById(773) is not False:
            self.controller.removeClient(773)
        if self.controller.getClientById(23) is False:
            self.controller.addClient("23", "name")
        if self.controller.getClientById('233333') is not False:
            self.controller.removeClient('233333')
        if self.controller.getClientById(20) is False:
            self.controller.addClient("20", "name")
        if self.controller.getClientById(200) is False:
            self.controller.addClient("200", "name2")
        if self.controller.getClientById(90) is False:
            self.controller.addClient("90", "name3")
        if self.controller.getClientById(123) is False:
            self.controller.addClient("123", "tion")
        if self.controller.getClientById(234) is False:
            self.controller.addClient("234", "t")
        if self.controller.getClientById(33) is False:
            self.controller.addClient("33", "tit")
        if self.controller.getClientById(90) is not False:
            self.controller.removeClient(99)
        if self.controller.getClientById(323) is False:
            self.controller.addClient("323", "tit")
        if self.controller.getClientById(929) is not False:
            self.controller.removeClient(929)
        if self.controller.getClientById(33) is False:
            self.controller.addClient("333", "tin")
        if self.controller.getClientById(939) is not False:
            self.controller.removeClient(939)

    def test_strClient(self):
        c = Client(2, "lapte")
        self.assertNotEqual(c, Client(3, "lapte"))
        self.assertEqual(str(self.Client), '3, name')

    def test_AddClient(self):
        self.assertEqual(self.controller.addClient('772', 'nume'), True)

    def test_AddClient2(self):
        self.assertEqual(self.controller.addClient('772', 'nume'), True)

    def test_AddClient3(self):
        self.assertEqual(self.controller.addClient(
            '773',
            'nume',
        ), True)

    def test_RemoveClient(self):
        self.assertEqual(self.controller.removeClient(20), True)

    def test_RemoveClient2(self):
        self.assertEqual(self.controller.removeClient(200), True)

    def test_UpdateClient(self):
        self.assertEqual(
            self.controller.updateClient('23', '233333', "action"), True)

    def test_UpdateClientName(self):
        self.assertEqual(
            self.controller.updateClientName('90', 'nuuummmeee tesr'), True)

    def test_UpdateClientName2(self):
        self.assertEqual(
            self.controller.updateClientName('90', 'nuuummmeee test2'), True)

    def test_UpdateClientName3(self):
        self.assertEqual(
            self.controller.updateClientName('90', 'nuuummmeee test3'), True)

    def test_UpdateClientId(self):
        self.assertEqual(self.controller.updateClientId("33", '99'), True)

    def test_UpdateClientId2(self):
        self.assertEqual(self.controller.updateClientId("323", '929'), True)

    def test_UpdateClientId3(self):
        self.assertEqual(self.controller.updateClientId("333", '939'), None)

    def test_GetAllClients(self):
        repo2 = Repository('ClientUpdateTest', "test2")
        client = Client("2", "223")
        controller2 = ClientController(repo2)
        l = controller2.getAllClients()
        self.assertEqual(controller2.getAllClients(), [client])

    def test_getClientById(self):
        if self.controller.getClientById('11111111') is False:
            self.controller.addClient('11111111', 'sfsdfsf')
        self.assertEqual(self.controller.getClientById('11111111'),
                         Client('11111111', 'sfsdfsf'))

    def test_getClientById2(self):
        if self.controller.getClientById('111211111') is False:
            self.controller.addClient('111211111', 'sfsdfsf')
        self.assertEqual(self.controller.getClientById('111211111'),
                         Client('111211111', 'sfsdfsf'))

    def test_ValidateClient(self):
        self.assertRaises(ValueError, ClientValidator.validate, "", "")
        self.assertRaises(ValueError, ClientValidator.validate, "", ",")