def testClientController(): """ Test ClientController """ repo = ClientsRepository() repo.add(Client(1, "a", 11111)) client = Client(2, "aa", 12121) repo.add(client) controller = ClientController(repo, RentRepository(), UnreController()) controller.removeClient(1) assert controller.getAll() == [client] controller.removeClient(2) assert controller.getAll() == [] try: controller.searchClient(23) assert False except ExceptionMess: pass
''' from Repositories.Repository import GenericRepository from Repositories.RentalRepository import RentalRepository from Controller.ClientController import ClientController from Controller.CarController import CarController from Controller.RentalController import RentalController from UI.Console import Console from Domain.Client import Client from Domain.Car import Car from Repositories.ClientRepository import ClientRepository from Repositories.CarRepository import CarRepository repo_clients = ClientRepository() repo_clients.add(Client("1", "client1")) repo_clients.add(Client("2", "client2")) repo_clients.add(Client("3", "client3")) repo_cars = CarRepository() repo_cars.add(Car("1", "car1")) repo_cars.add(Car("2", "car2")) repo_cars.add(Car("3", "car3")) repo_rentals = RentalRepository() ctrl_clients = ClientController(repo_clients) ctrl_cars = CarController(repo_cars) ctrl_rentals = RentalController(repo_clients, repo_cars, repo_rentals) ui = Console(ctrl_cars, ctrl_clients, ctrl_rentals) ui.show()
choices=[ArgType.T_CLIENT, ArgType.T_SERVER], help='Your session type (client or server).') parser.add_argument('--port', type=int, default=8000, help='Server port (Ex: 80).') parser.add_argument('--ip', type=str, default='localhost', help='Server ip (Ex: 127.0.0.1).') args = parser.parse_args() if args.type == ArgType.T_CLIENT: print('***** GAME CLIENT START *****') app = QApplication(sys.argv) client = ClientController(myWorkspace) # client = ClientController(myWorkspace) client.set_player_name(args.pseudo) print('> player created: {}'.format(args.pseudo)) client.set_connexion_info(args.ip, args.port) print('> player listen: [{}:{}]'.format(args.ip, args.port)) client.start() result = app.exec_() client.network.stop() print('***** GAME CLIENT ENDED *****') exit(result) elif args.type == ArgType.T_SERVER: print('***** GAME SERVER START *****') server = ServerController() server.set_connexion_info(args.ip, args.port)
def testUnReController(): """ Test UnReController """ client = ClientsRepository() movie = MoviesRepository() rent = RentRepository() unre = UnreController() clientC = ClientController(client, rent, unre) movieC = MovieController(movie, rent, unre) rentC = RentController(client, movie, rent, unre) #Test Client Undo clientC.addClient(Client(1, "A", 12121)) unre.Undo() try: clientC.GetClient(1) assert False except ExceptionMess: pass unre.Redo() try: clientC.GetClient(1) except ExceptionMess: assert False try: unre.Redo() assert False except ExceptionMess: pass unre.Undo() try: clientC.GetClient(1) assert False except ExceptionMess: unre.Redo() clientC.removeClient(1) unre.Undo() try: clientC.GetClient(1) except ExceptionMess: assert False unre.Redo() try: clientC.GetClient(1) assert False except ExceptionMess: pass try: unre.Undo() except ExceptionMess: assert False clientC.updateClient(Client(1, "v", 123)) unre.Undo() assert clientC.GetClient(1) == Client(1, "A", 12121) unre.Redo() assert clientC.GetClient(1) == Client(1, "v", 123) #Test Movie Undo movieC.addMovie(Movie(1, "A", "AA", "AAA")) unre.Undo() try: movieC.GetMovie(1) assert False except ExceptionMess: pass unre.Redo() try: movieC.GetMovie(1) except ExceptionMess: assert False try: unre.Redo() assert False except ExceptionMess: pass unre.Undo() try: movieC.GetMovie(1) assert False except ExceptionMess: unre.Redo() movieC.removeMovie(1) unre.Undo() try: movieC.GetMovie(1) except ExceptionMess: assert False unre.Redo() try: movieC.GetMovie(1) assert False except ExceptionMess: pass try: unre.Undo() except ExceptionMess: assert False movieC.updateMovie(Movie(1, "B", "BB", "BBB")) unre.Undo() assert movieC.GetMovie(1) == Movie(1, "A", "AA", "AAA") unre.Redo() assert movieC.GetMovie(1) == Movie(1, "B", "BB", "BBB") #Test Rent Undo rentC.rentMovie(Rent(1, 1)) unre.Undo() assert not rentC.isClient(1) unre.Redo() assert rentC.isClient(1) try: unre.Redo() assert False except ExceptionMess: pass unre.Undo() assert not rentC.isClient(1) unre.Redo() rentC.returnMovie(Rent(1,1)) unre.Undo() assert rentC.isClient(1) unre.Redo() assert not rentC.isClient(1) try: unre.Undo() except ExceptionMess: assert False