def test_create_with_taken_seat_raises_error(self): user_id = 1 projection_id = 2 row = 2 column = 3 with self.assertRaises(TakenSeatError): ReservationController.create(user_id, projection_id, row, column)
def test_create_with_incorrect_seat_raises_error(self): user_id = 1 projection_id = 1 row = 22 column = 33 with self.assertRaises(SeatOutOfRangeError): ReservationController.create(user_id, projection_id, row, column)
def save_seat(cls, user_id, projection_id, seat): print(seat[1:-1]) if match('\(\d{1,2},\d{1,2}\)$', seat) is None: raise SeatError('Invalid seat!') row, col = seat[1:-1].split(',') row, col = int(row), int(col) if row < 1 or row > 10 or col < 1 or col > 10: raise SeatError('Invalid seat!') ReservationController.save_seat(user_id, projection_id, row, col) return row, col
class MovieInterface: validator = CinemaValidator() movie_controller = MovieController() reservation_controller = ReservationController() def choose_movie(self): while True: try: self.show_movies() movie_id = input('Choose movie id:\n>>> ') self.validator.validate_movie_id(cast_to_int(movie_id)) except MovieDoesntExist as e: print(e) except ValueError as e: print(e) else: return movie_id def choose_movie_projection(self, movie_id): while True: try: self.show_movie_projections(movie_id) projection_id = input('Choose projection id:\n>>> ') self.validator.validate_projection_id( cast_to_int(projection_id), movie_id) except ProjectionDoesntExist as e: print(e) except ValueError as e: print(e) else: return projection_id def show_movies(self): pretty_print_movies(self.movie_controller.list_movies()) def show_movie_projections(self, id_, date=None): pretty_print_movie_projections( self.movie_controller.show_movie_projections( cast_to_int(id_), date)) def show_room_matrix_for_projection(self, proj_id, seats=None): matrix = [['.' for _ in range(MAX_ROWS)] for _ in range(MAX_COLS)] taken_seats = self.reservation_controller.get_taken_seats_for_projection( proj_id) for seat in taken_seats: matrix[seat[0] - 1][seat[1] - 1] = 'x' if seats: for seat in seats: matrix[seat[0] - 1][seat[1] - 1] = '#' print_matrix_hall(matrix)
def show_all_taken_seets_for_projection(cls, projection_id, temporaty_seets): taken_seets = ReservationController.get_all_taken_seets_for_projection( projection_id) seats = ' 1 2 3 4 5 6 7 8 9 10' for row in range(1, 11): row_string = [str(row)] for col in range(1, 11): if (row, col) in taken_seets or (row, col) in temporaty_seets: row_string.append('X') else: row_string.append('.') seats = f'{seats}\n{" ".join(row_string)}' cls.show_message(seats)
def show_projections_of_movie(cls, movie_id): from controllers.reservation_controller import ReservationController try: movie_id = int(movie_id) except Exception: return None else: if ReservationController.is_valid_id(movie_id, 'movie'): movies = session.query(Projection.id, Movie.name, Projection._type, Projection.date, Projection.time).join(Movie).filter( Movie.id == movie_id).all() else: movies = None if movies: pretty_print( movies, attributes=['id', 'movie_name', 'type', 'date', 'time']) else: print("There is no such movie")
from controllers.movie_controller import MovieController from controllers.user_controller import UserController from controllers.reservation_controller import ReservationController m = MovieController() u = UserController() r = ReservationController() def pop(): # m.add_new_movie(movie_name='LODR', movie_rating=9) # m.add_new_movie(movie_name='bbee', movie_rating=3) # m.add_new_movie(movie_name='star', movie_rating=2) # m.add_new_movie(movie_name='wars', movie_rating=5) # m.add_new_movie(movie_name='13', movie_rating=5) # u.create_new_user(user_name='Ivan', password='******') # u.create_new_user(user_name='Ivan2', password='******') # u.create_new_user(user_name='Ivan3', password='******') # u.create_new_user(user_name='Ivan4', password='******') # u.create_new_user(user_name='Ivan5', password='******') # u.create_new_user(user_name='Ivan6', password='******') # u.create_new_user(user_name='Ivan7', password='******') r.make_new_reservation(1, 2, 9, 9) r.make_new_reservation(1, 2, 9, 8) r.make_new_reservation(1, 2, 9, 7) r.make_new_reservation(1, 2, 9, 10) # p.create_new_projection(movie_id=1, type_='3D', date='2018-02-12', time='12:30:00') # p.create_new_projection(movie_id=2, type_='2D', date='2018-05-02', time='12:30:00') # p.create_new_projection(movie_id=3, type_='4D', date='2018-06-22', time='12:30:00')
def test_check_tickets_for_projection_less_than_avaliable(self): projection_id = 2 tickets = 2 self.assertTrue( ReservationController.check_tickets_for_projection( projection_id, tickets))
def make_reservation(cls, user): ReservationController.make_reservation(user)
class UserInterface: user_controller = UserController() reservation_controller = ReservationController() validator = CinemaValidator() def reg_or_log(self): while True: print('You need to log in or register first!\n' 'Enter what u want to do!\n1. ' 'Register\n2. log in?') choice = input('>>> ') try: return self.__log_or_register(choice) except ValueError as e: print(e) # self.__log_or_register(choice) except UserAlreadyExists as e: print(e) # self.__log_or_register(choice) def register(self): username = self.__get_username() password = self.__get_register_password() self.user_controller.create_new_user(username, password) print('Successful registration!') return self.user_controller.get_user_id_by_username(username) def log_in(self): username = self.__get_username() password = self.__get_login_password() self.user_controller.log_user_in(username, password) print('Successful login!') return self.user_controller.get_user_id_by_username(username) def make_reservation(self, user_id, proj_id, row, col): self.reservation_controller.make_new_reservation( user_id, proj_id, row, col) def finalize_reservation(self): self.reservation_controller.finalize_reservation() def __log_or_register(self, choice): if choice == '1': return self.register() elif choice == '2': return self.log_in() else: print('Choice not valid!') def __get_username(self): while True: try: username = input('Enter username:\n>>> ') self.validator.validate_username(username) except ValueError as e: print(e) else: return username @staticmethod def __get_login_password(): password = input('Enter password:\n>>> ') return password def __get_register_password(self): while True: try: pass_1 = input('Enter password:\n >>> ') self.validator.validate_password(pass_1) pass_2 = input('Confirm password:\n >>> ') if pass_1 != pass_2: raise ValueError('Different passwords!') except ValueError as e: print(e) else: return pass_1
def show_seat_table(cls, *args): return ReservationController.show_seat_table(*args)
def reserve_a_seat(cls, *args): return ReservationController.reserve_a_seat(*args)
def insert_new_reservation(cls, *args): ReservationController.insert_new_reservation(cls, *args)
def get_num_free_seats(cls, *args): return ReservationController.get_num_free_seats(*args)
def test_check_tickets_for_projection_great_than_avaliable(self): projection_id = 2 tickets = 99 self.assertFalse( ReservationController.check_tickets_for_projection( projection_id, tickets))
def test_get_reservation(self): data = (1, 2, 2, 3) actual = ReservationController.get(*data) self.assertEqual( (actual.user_id, actual.projection_id, actual.row, actual.column), data)
def test_get_all_reservations_for_projection_without_reservations(self): projection_id = 1 expected = [] actual = ReservationController.get_all_reservations_for_projection( projection_id) self.assertEqual(actual, expected)
def test_get_all_reservations_for_projection(self): projection_id = 2 expected = [(2, 3), (2, 4)] actual = ReservationController.get_all_reservations_for_projection( projection_id) self.assertEqual(actual, expected)
def test_get_reservation_raises_error(self): data = (2, 2, 2, 3) with self.assertRaises(ReservationDoesNotExist): ReservationController.get(*data)