def print_show_movie_projections_with_date(self, movie_id, movie_date):

        movie_name_date = self.cursor.execute(
            "SELECT Movies.movie_name, Projections.movie_date \
                                               FROM Movies JOIN Projections \
                                               ON Movies.movie_id = ? AND Projections.movie_date = ?",
            (
                movie_id,
                movie_date,
            ))
        m_name = ""
        m_date = ""
        for name_and_date in movie_name_date:
            m_name = name_and_date[0]
            m_date = name_and_date[1]
        print("Projections for movie '%s' on date '%s':" % (m_name, m_date))
        projections_cursor = MagicReservationSystem(
        ).show_movie_projections_with_date(movie_id, movie_date)
        if len(projections_cursor.fetchall()) == 0:
            message = "There are no projections for this movie on this date!"
            print(message)
            return
        for projections in MagicReservationSystem(
        ).show_movie_projections_with_date(movie_id, movie_date):
            print("[{}]".format(projections[0]), projections[1],
                  "({})".format(projections[2]))
    def print_show_movie_projections(self, movie_id):

        movie_name = self.cursor.execute("SELECT movie_name \
                                          FROM Movies \
                                          WHERE movie_id = ?", (movie_id,))
        title = ""
        for name in movie_name:
            title = name[0]
        projections_cursor = MagicReservationSystem().show_movie_projections(movie_id)
        if len(projections_cursor.fetchall()) == 0:
            message = "\nMovie with this id doesn't exist!"
            print(message)
            return
        print("Projections for movie '%s': " % title)
        for projections in MagicReservationSystem().show_movie_projections(movie_id):
            print("[{}]".format(projections[0]), projections[1], projections[2], "({})".format(projections[3]), projections[4], "available spots")
    def print_show_movie_projections_with_date(self, movie_id, movie_date):

        movie_name_date = self.cursor.execute("SELECT Movies.movie_name, Projections.movie_date \
                                               FROM Movies JOIN Projections \
                                               ON Movies.movie_id = ? AND Projections.movie_date = ?", (movie_id, movie_date,))
        m_name = ""
        m_date = ""
        for name_and_date in movie_name_date:
            m_name = name_and_date[0]
            m_date = name_and_date[1]
        print("Projections for movie '%s' on date '%s':" % (m_name, m_date))
        projections_cursor = MagicReservationSystem().show_movie_projections_with_date(movie_id, movie_date)
        if len(projections_cursor.fetchall()) == 0:
            message = "There are no projections for this movie on this date!"
            print(message)
            return
        for projections in MagicReservationSystem().show_movie_projections_with_date(movie_id, movie_date):
            print("[{}]".format(projections[0]), projections[1], "({})".format(projections[2]))
    def print_show_movie_projections(self, movie_id):

        movie_name = self.cursor.execute(
            "SELECT movie_name \
                                          FROM Movies \
                                          WHERE movie_id = ?", (movie_id, ))
        title = ""
        for name in movie_name:
            title = name[0]
        projections_cursor = MagicReservationSystem().show_movie_projections(
            movie_id)
        if len(projections_cursor.fetchall()) == 0:
            message = "\nMovie with this id doesn't exist!"
            print(message)
            return
        print("Projections for movie '%s': " % title)
        for projections in MagicReservationSystem().show_movie_projections(
                movie_id):
            print("[{}]".format(projections[0]), projections[1],
                  projections[2], "({})".format(projections[3]),
                  projections[4], "available spots")
    def show_available_seats(self, projection_id):

        size_of_the_hall = MagicReservationSystem().show_cinema_hall(
            projection_id)
        every_row = ""
        print("Available seats (marked with a dot):")
        print("   1 2 3 4 5 6 7 8 9 10")

        for row, rows in enumerate(size_of_the_hall):
            for col, cols in enumerate(rows):
                if col == 0 and row < 9:
                    every_row += str(row + 1) + "  "
                if col == 0 and row == 9:
                    every_row += str(row + 1) + " "
                every_row += str(cols) + " "
            print(every_row)
            every_row = ""
 def setUp(self):
     self.mrs = MagicReservationSystem()
     self.movie = Movie(name='test_movie', rating=3.5)
     self.projection = Projection(movie_id=1, type='3D', date='2014-04-01', time='19:10')
     self.projection2 = Projection(movie_id=1, type='2D', date='2014-04-02', time='23:10')
     self.reservation = Reservation(id=1, projection_id=1, username='******', row=1, col=1)
class MRSTest(unittest.TestCase):
    def setUp(self):
        self.mrs = MagicReservationSystem()
        self.movie = Movie(name='test_movie', rating=3.5)
        self.projection = Projection(movie_id=1, type='3D', date='2014-04-01', time='19:10')
        self.projection2 = Projection(movie_id=1, type='2D', date='2014-04-02', time='23:10')
        self.reservation = Reservation(id=1, projection_id=1, username='******', row=1, col=1)
        
    def tearDown(self):
        os.remove('cinema.db')

    def test_add_movie(self):
        self.mrs.add_movie('movie', 1)
        result = self.mrs.session.query(Movie.id,
                                        Movie.name,
                                        Movie.rating).all()
        self.assertIn((1, 'movie', 1.0), result)

    def test_show_movies(self):
        self.mrs.session.add(self.movie)
        self.mrs.session.commit()
        result = self.mrs.show_all_movies()
        self.assertEqual([self.movie], result)

    # def test_show_movie_name_with_id(self):
    #     self.mrs.session.add(self.movie)
    #     self.mrs.session.commit()
    #     result = self.mrs.show_movie_name(1)
    #     self.assertEqual('test_movie', result)

    def test_add_movie_projection(self):
        self.mrs.session.add(self.movie)
        self.mrs.add_movie_projection(1, '3D', '2014-04-10', '19:10')
        result = self.mrs.session.query(Projection.id, Projection.type, Projection.date, Projection.time).all()
        self.assertIn((1, '3D', '2014-04-10', '19:10'), result)

    def test_show_projections_without_date(self):
        self.mrs.session.add(self.projection)
        self.mrs.session.commit()
        result = self.mrs.show_projections(1)
        self.assertEqual([self.projection], result)

    def test_show_projections_with_date(self):
        self.mrs.session.add(self.projection)
        self.mrs.session.add(self.projection2)
        self.mrs.session.commit()
        result = self.mrs.show_projections(1, '2014-04-02')
        self.assertEqual([self.projection2], result)

    def test_show_available_seats(self):
        self.mrs.session.add(self.projection)
        self.mrs.session.commit()
        result = self.mrs.show_available_seats(1)
        self.assertEqual(100, result)

    def test_show_projection(self):
        self.mrs.session.add(self.projection)
        self.mrs.session.add(self.projection2)
        result = self.mrs.show_projection(1)
        self.assertEqual(self.projection, result)

    def test_add_reservation(self):
        self.mrs.session.add(self.projection)
        self.mrs.session.commit()
        self.mrs.add_reservation(1, 'shosh', 2, 2)
        result = self.mrs.session.query(Reservation.id, Reservation.projection_id, Reservation.username, Reservation.row, Reservation.col).all()
        # projection_id and reservation_id
        self.assertIn((1, 1, 'shosh', 2, 2), result)

        self.assertEqual(self.mrs.show_available_seats(1), 99)

    def test_check_availability(self):
        self.mrs.session.add(self.reservation)
        self.assertTrue(self.mrs.check_availability(1, 2))
        self.assertFalse(self.mrs.check_availability(1, 1))

    def test_check_validity(self):
        self.assertTrue(self.mrs.check_validity(3, 5))
        self.assertFalse(self.mrs.check_validity(-2, 1))
        self.assertFalse(self.mrs.check_validity(11, 5))
        
    def test_start(self):
        self.mrs.start()
def main():

    while True:

        print("\nWelcome to our cinema!\n")
        print("For Movies: Press 1")
        print("For Projections: Press 2")
        print("To make reservation: Press 3")
        print("For Help: Press 4")
        print("To Exit: Press 5")

        try:
            command = int(input("Please choose command>> "))

            if command < 1 or command > 5:
                print("\nWrong choice! Try again!")

            if command == 1:
                PrepareData().print_show_movies()

            elif command == 2:
                movie_id = int(input("Please choose movie id>> "))
                PrepareData().print_show_movie_projections(movie_id)

            elif command == 3:
                username = input("Choose name>> ")
                client_username = CLI().enter_name(username)

                number_of_tickets = int(input("Choose number of tickets>> "))
                client_tickets = CLI().enter_number_of_tickets(number_of_tickets)

                PrepareData().print_show_movies()

                movie_id = int(input("Please choose movie id>> "))
                client_movie = CLI().choosen_movie(movie_id)
                PrepareData().print_show_movie_projections(movie_id)

                projection_id = int(input("Please choose projection id>> "))
                if projection_id not in CLI().validate_projection(movie_id):
                    print("\nInvalid projection id!")
                    continue
                data_and_time_of_projection = CLI().choosen_date_and_time(projection_id)
                if client_tickets > MagicReservationSystem().available_spots_in_cinema(projection_id):
                    message = "\nThe tickets are more than the available spots in the cinema hall!"
                    print(message)
                    continue

                PrepareData().show_available_seats(projection_id)

                seats = ""
                while client_tickets != 0:
                    seat = tuple(int(x.strip()) for x in input("Choose seat: ").split(','))
                    #print(MagicReservationSystem().choose_seats(seat[0], seat[1], projection_id))
                    #seats += str(seat) + ","
                    #client_seats = CLI().choosen_seats(seats, projection_id)
                    print(MagicReservationSystem().choose_seats(seat[0], seat[1], projection_id))
                    MagicReservationSystem().choose_seats(seat[0], seat[1], projection_id)


                    client_tickets -= 1
                #print(client_seats)




            elif command == 4:
                print("\nFor movies - Show all movies in the cinema")
                print("For Projections - Show all projections for given movie")
                print("To make reservation - You can make reservations in our cinema")
                print("To Exit - You can exit from the system")

            elif command == 5:
                break

        except ValueError:
            print("\nPlease enter a valid value!")
    def print_show_movies(self):

        print("Current movies: ")
        for movies in MagicReservationSystem().show_movies():
            print("[{}]".format(movies[0]), movies[1],
                  "({})".format(movies[2]))