def make_reservation(cls, user):
        num_tickets = cls.choose_number_of_tickets()
        movie_id = cls.choose_a_movie()

        while (True):
            proj_id = cls.choose_projection(movie_id)
            if ProjectionController.get_num_free_seats(proj_id) < num_tickets:
                print(
                    "There are not enough free seats for this projection.Please choose a different projection\n"
                )
            else:
                print("Advancing to choosing the seats!")
                break

        reserved_seats = []
        for i in range(num_tickets):
            reserved_seats.append(cls.reserve_a_seat(proj_id, user))

        print(
            "Your tickets are ready to be reserved.Do you want to finalize the transaction?\n"
        )

        if cls.finalize():
            print(
                "Congratulations!You have just reserved your seats.We wish you happy cinema\n"
            )
        else:
            print("Changes canceled...")
 def test_get_all_with_avaliable_seats_for_movie_with_projections(self):
     expected = [(4, "2018-05-25", "21:30:00", "3D", 100),
                 (1, "2018-05-25", "21:55:00", "3D", 100),
                 (3, "2018-05-26", "15:30:00", "2D", 100),
                 (2, "2018-05-27", "21:55:00", "4DX", 98)]
     actual = ProjectionController.get_all_with_avaliable_seats(1)
     self.assertEqual(expected, actual)
 def test_get_all_by_movie_id_date_for_movie_with_projections(self):
     expected = [(4, "21:30:00", "3D"),
                 (1, "21:55:00", "3D")
                 ]
     actual = ProjectionController.get_all_by_movie_id_and_date(
         1, "2018-05-25")
     self.assertEqual(expected, actual)
    def check_id_for_projection(cls, movie_id, projection_id):
        from controllers.projection_controller import ProjectionController
        projections = ProjectionController.get_all_projections_for_movie(
            movie_id)

        return any(
            [projection.id == projection_id for projection in projections])
 def test_get_by_id(self):
     projection_id = 1
     expected = (
         "The Hunger Games: Catching Fire",
         7.5, "2018-05-25",
         "21:55:00", "3D")
     actual = ProjectionController.get_by_id(projection_id)
     self.assertEqual(expected, actual)
 def test_get_all_by_movie_id_for_movie_with_projections(self):
     expected = [(4, "2018-05-25", "21:30:00", "3D"),
                 (1, "2018-05-25", "21:55:00", "3D"),
                 (3, "2018-05-26", "15:30:00", "2D"),
                 (2, "2018-05-27", "21:55:00", "4DX")
                 ]
     actual = ProjectionController.get_all_by_movie_id(1)
     self.assertEqual(expected, actual)
Пример #7
0
    def show_movie_projections(cls, movie_id):
        try:
            movie_name = MovieController.get_movie(movie_id).name
            projections = ProjectionController.get_all_projections_for_movie(
                movie_id)
        except MovieException:
            raise Exception('Invalid movie id!')

        rows = [[p.id, p.date, p.time, p.type] for p in projections]

        cls.show_message(f'Projections for movie {movie_name}:')
        cls.show_table(rows, ['ID', 'Date', 'Time', 'type'])
    def save_seat(cls, user_id, projection_id, row, col):
        if UserController.check_id(user_id) is False:
            raise UserError('There is no user with id = {}!'.format(user_id))

        if ProjectionController.check_id(projection_id) is False:
            raise ProjectionException(
                'There is no projection with id = {}!'.format(projection_id))

        if cls.check_if_seat_is_taken(projection_id, row, col):
            raise SeatError('The seat is taken!')

        session.add(
            Reservation(user_id=user_id,
                        projection_id=projection_id,
                        row=row,
                        col=col))
    def reserve_a_seat(cls, proj_id, user):
        from view.menu import Menu

        seat_table = ProjectionController.show_seat_table(proj_id)

        while (True):
            menu = """
            1)Reserve a seat
            2)Cancel reservation
            """
            kwargs = Menu.get_input(menu, option=None)
            option = kwargs["option"]
            if option == '1':
                kwargs = Menu.get_input("enter row and col\n",
                                        row=None,
                                        col=None)
                row, col = kwargs['row'], kwargs['col']
                try:
                    row = int(row)
                    col = int(col)
                    if seat_table[row][col] == '.':
                        session.add(
                            Reservation(user_id=user.id,
                                        projection_id=proj_id,
                                        row=row,
                                        col=col))
                        print("Seat reserved!\n")
                        break
                    else:
                        print("Seat is taken!\n")
                except Exception:
                    print("Invalid input!\n")
            elif option == '2':
                raise Exception("Canceling reservation...")
            else:
                print("Invalid option!\n")
 def show_projections(cls, *args):
     return ProjectionController.show_projections(*args)
Пример #11
0
 def show_projections_of_movie(cls, *args):
     return ProjectionController.show_projections_of_movie(*args)
Пример #12
0
 def insert_new_projection(cls, *args):
     ProjectionController.insert_new_projection(cls, *args)
 def test_get_by_id_with_incorrect_id(self):
     projection_id = 42
     with self.assertRaises(ProjectionIdError):
         ProjectionController.get_by_id(projection_id)
 def test_get_all_with_avaliable_seats_for_movie_without_projections(self):
     expected = []
     actual = ProjectionController.get_all_with_avaliable_seats(2)
     self.assertEqual(expected, actual)
 def test_get_all_by_movie_id_date_for_movie_without_projections(self):
     expected = []
     actual = ProjectionController.get_all_by_movie_id_and_date(
         2, "2018-05-25")
     self.assertEqual(expected, actual)
 def test_get_all_by_movie_id_for_movie_without_projections(self):
     expected = []
     actual = ProjectionController.get_all_by_movie_id(2)
     self.assertEqual(expected, actual)