예제 #1
0
class TestCinema(unittest.TestCase):
    def setUp(self):
        self.my_cinema = Cinema(session)

    def test_add_movie(self):
        #self.my_cinema.add_movie() add new movie
        movie = session.query(Movie.name, Movie.rating,
                              Movie.id).filter(Movie.name == "Bad boys")
        self.assertEqual(movie[0][0], "Bad boys")
        self.assertEqual(movie[0][1], 7.1)
        self.assertEqual(movie[0][2], 3)

    def test_show_movies(self):
        #self.my_cinema.show_movies()
        movies = session.query(Movie.name).all()
        self.assertEqual(movies, [('The Hunger Games', ), ('Die Hard', ),
                                  ('Bad boys', )])

    #def test_what_movie(self):
    #movie = self.my_cinema.what_movie()
    #self.assertEqual(movie, ['Wtf', '5.5'])

    def test_add_projections(self):
        #self.my_cinema.add_projections() #add one new projection
        projection = session.query(
            Projection.movie_type, Projection.date_time,
            Projection.movie_id).filter(Projection.movie_id == 3)
        self.assertEqual(projection[0][0], "3D")
        self.assertEqual(projection[0][1], datetime(2014, 11, 24, 21, 30))
        self.assertEqual(projection[0][2], 3)

    def test_select_title(self):
        self.assertEqual(self.my_cinema.select_title(2),
                         "Projections for Die Hard")

    #def test_select_projections(self): # samo printva projekciite
    #    self.my_cinema.select_projections(2)

    #def test_show_projections(self): # samo printva projekciite
    #    self.my_cinema.show_movie_projections(2)

    def test_take_spots(self):
        self.assertEqual(self.my_cinema.take_spots(2), 97)

    def test_seats_for_out_if_index(self):
        self.assertFalse(self.my_cinema.check_seats_for_out_index('(2, 44)'))
        self.assertTrue(self.my_cinema.check_seats_for_out_index('(2, 3)'))

    def test_seats_if_are_available(self):
        self.my_cinema.take_spots(2)
        self.my_cinema.show_seats(2)
        self.assertTrue(self.my_cinema.check_seats_if_available("(1, 2)"))
        self.assertFalse(self.my_cinema.check_seats_if_available("(7, 7)"))

    def test_cancel_reservation(self):  #works only once !
        #old_reservation = session.query(Reservation).all()
        #self.assertEqual(len(old_reservation), 6)
        self.my_cinema.cancel_reservation("Ivo")
        new_reservation = session.query(Reservation).all()
        self.assertEqual(len(new_reservation), 5)
예제 #2
0
class TestCinema(unittest.TestCase):
    def setUp(self):
        self.my_cinema = Cinema(session)

    def test_add_movie(self):
        #self.my_cinema.add_movie() add new movie
        movie = session.query(
            Movie.name, Movie.rating, Movie.id).filter(
            Movie.name == "Bad boys")
        self.assertEqual(movie[0][0], "Bad boys")
        self.assertEqual(movie[0][1], 7.1)
        self.assertEqual(movie[0][2], 3)

    def test_show_movies(self):
        #self.my_cinema.show_movies()
        movies = session.query(Movie.name).all()
        self.assertEqual(movies, [('The Hunger Games',), ('Die Hard',), ('Bad boys',)])

    #def test_what_movie(self): 
        #movie = self.my_cinema.what_movie()
        #self.assertEqual(movie, ['Wtf', '5.5'])

    def test_add_projections(self):
        #self.my_cinema.add_projections() #add one new projection
        projection = session.query(
            Projection.movie_type, Projection.date_time, Projection.movie_id).filter(
            Projection.movie_id == 3)
        self.assertEqual(projection[0][0], "3D")
        self.assertEqual(projection[0][1], datetime(2014, 11, 24, 21, 30))
        self.assertEqual(projection[0][2], 3)

    def test_select_title(self):
        self.assertEqual(self.my_cinema.select_title(2), "Projections for Die Hard")

    #def test_select_projections(self): # samo printva projekciite
    #    self.my_cinema.select_projections(2)

    #def test_show_projections(self): # samo printva projekciite
    #    self.my_cinema.show_movie_projections(2)

    def test_take_spots(self):
        self.assertEqual(self.my_cinema.take_spots(2), 97)

    def test_seats_for_out_if_index(self):
        self.assertFalse(self.my_cinema.check_seats_for_out_index('(2, 44)'))
        self.assertTrue(self.my_cinema.check_seats_for_out_index('(2, 3)'))

    def test_seats_if_are_available(self):
        self.my_cinema.take_spots(2)
        self.my_cinema.show_seats(2)
        self.assertTrue(self.my_cinema.check_seats_if_available("(1, 2)"))
        self.assertFalse(self.my_cinema.check_seats_if_available("(7, 7)"))

    def test_cancel_reservation(self): #works only once !
        #old_reservation = session.query(Reservation).all()
        #self.assertEqual(len(old_reservation), 6)
        self.my_cinema.cancel_reservation("Ivo")
        new_reservation = session.query(Reservation).all()
        self.assertEqual(len(new_reservation), 5)
예제 #3
0
def main():
    engine = create_engine("sqlite:///cinema.db")
    base.Base.metadata.create_all(engine)

    session = Session(bind=engine)

    cinema = Cinema(session)

    print_menu()
    command = input("Enter your choice: ")
    put = command.split(" ")

    while put[0] != "end":
        if put[0] == "add_movie" or put[0] == '1':
            cinema.add_movie()
        if put[0] == "show_movies" or put[0] == '2':
            cinema.show_movies()
        if put[0] == "add_projection" or put[0] == '3':
            cinema.add_projections()
        if put[0] == "show_movie_projections":
            cinema.show_movie_projections(put[1])
        if put[0] == "make_reservation" or put[0] == '5':
            #ENTER INFORMATION FOR USER
            try:
                #USER INFORMATION
                user_info = step_one(cinema)
                #CHOOSING MOVIE
                movie_choice = step_two(cinema)
                # CHOOSING PROJECTIONS
                projection_choice = step_three(cinema)
                # CHOOSING SEATS
                step_four(cinema, user_info, projection_choice, movie_choice)
                # FINALIZE
                step_five(cinema, user_info, projection_choice)
            except GiveUpError:
                print("You just give up the reservation!")
                print_menu()

        if put[0] == "cancel_reservation":
            cinema.cancel_reservation(put[1])
        if put[0] == "exit":
            break
        if put[0] == "help":
            cinema.print_menu()
        command = input("Enter your choice: ")
        put = command.split(" ")
예제 #4
0
def main():
    engine = create_engine("sqlite:///cinema.db")
    base.Base.metadata.create_all(engine)

    session = Session(bind=engine)

    cinema = Cinema(session)

    print_menu()
    command = input("Enter your choice: ")
    put = command.split(" ")

    while put[0] != "end":
        if put[0] == "add_movie" or put[0] == '1':
            cinema.add_movie()
        if put[0] == "show_movies" or put[0] == '2':
            cinema.show_movies()
        if put[0] == "add_projection" or put[0] == '3':
            cinema.add_projections()
        if put[0] == "show_movie_projections":
            cinema.show_movie_projections(put[1])
        if put[0] == "make_reservation" or put[0] == '5':
            #ENTER INFORMATION FOR USER
            try:
                #USER INFORMATION
                user_info = step_one(cinema)
                #CHOOSING MOVIE
                movie_choice = step_two(cinema)
                # CHOOSING PROJECTIONS
                projection_choice = step_three(cinema)
                # CHOOSING SEATS
                step_four(cinema, user_info, projection_choice, movie_choice)
                # FINALIZE
                step_five(cinema, user_info, projection_choice)
            except GiveUpError:
                print("You just give up the reservation!")
                print_menu()

        if put[0] == "cancel_reservation":
            cinema.cancel_reservation(put[1])
        if put[0] == "exit":
            break
        if put[0] == "help":
            cinema.print_menu()
        command = input("Enter your choice: ")
        put = command.split(" ")
예제 #5
0
class MyTests(unittest.TestCase):
	def setUp(self):
		self.cinema = Cinema("test1.db")

	def tearDown(self):
	 	self.cinema.exit()
	 	os.remove("test1.db")

	def test_add_movie(self):
		self.cinema.add_movie('The Hunger Games: Catching Fire', 7.9)
		self.cinema.cursor.execute('SELECT * FROM Movies')
		movie = self.cinema.cursor.fetchall()[0]
		self.assertTrue(movie[0] == 1)
		self.assertEqual(movie[1], "The Hunger Games: Catching Fire")
		self.assertEqual(movie[2], 7.9)

	def test_add_proj(self):
		proj = (1, 1, '3D',  '2014-04-01', '19:10')
		self.cinema.add_projection(1, '3D',  '2014-04-01', '19:10')
		self.cinema.cursor.execute('SELECT * FROM Projections')
		projection_from_db = self.cinema.cursor.fetchall()[0]
		self.assertEqual(proj, projection_from_db)

	def test_add_reservation(self):
		reservation = (1, 'RadoRado', 1, 2, 1)
		self.cinema.add_reservation('RadoRado', 1, 2, 1)
		self.cinema.cursor.execute('SELECT * FROM Reservations')
		reservation_from_db = self.cinema.cursor.fetchall()[0]
		self.assertEqual(reservation, reservation_from_db)

	def test_cancel_reservation(self):
		self.cinema.add_reservation('RadoRado', 1, 2, 1)
		self.cinema.add_reservation('RadoRado', 1, 3, 5)
		self.cinema.add_reservation('RadoRado', 1, 7, 8)
		self.cinema.add_reservation('Ivo', 3, 1, 1)
		self.cinema.add_reservation('Ivo', 3, 1, 2)
		self.cinema.add_reservation('Mysterious', 5, 2, 3)
		self.cinema.add_reservation('Mysterious', 5, 2, 4)
		self.cinema.cancel_reservation("a")
		self.cinema.cancel_reservation("RadoRado")
		testing_value = self.cinema.free_place_for_projection(1)
		self.assertEqual(testing_value, 100)
예제 #6
0
def main():
    engine = create_engine("sqlite:///EmilCinema.db")
    Base.metadata.create_all(engine)
    session = Session(bind=engine)
    EmilCinema = Cinema(session)
    print_main_menu()
    print("asda")
    command = input("Enter your choice: ")
    parsed_command = command.split()
    while parsed_command[0] != "end":
        if parsed_command[0] == "add_movie" or parsed_command[0] == '1':
            EmilCinema.add_movie()
        if parsed_command[0] == "show_movies" or parsed_command[0] == '2':
            EmilCinema.show_movies()
        if parsed_command[0] == "add_projection" or parsed_command[0] == '3':
            EmilCinema.add_projection()
        if parsed_command[0] == "show_movie_projections" or parsed_command[0] == '4':
            EmilCinema.show_projections_available_spots(parsed_command[1])
        if parsed_command[0] == "make_reservation" or parsed_command[0] == '5':

            try:
                user_info = personal_info(EmilCinema)
                movie_id = choosing_movie(EmilCinema)
                projection_id = choosing_projection(EmilCinema)
                choosing_seats(EmilCinema, user_info, projection_id, movie_id)
                finalize_reservation(EmilCinema, user_info, projection_id)

            except GiveUpError:
                print("You just give up the reservation!")
                print_main_menu()
            if parsed_command[0] == "cancel_reservation":
                EmilCinema.cancel_reservation(parsed_command[1])
            if parsed_command[0] == "exit":
                break
            if parsed_command[0] == "help":
                EmilCinema.print_main_menu()
        command = input("Enter your choice: ")
        parsed_command = command.split()
예제 #7
0
class Spells():
	#db_name = "cinema.db"
	def __init__(self, db_name):
		self.cinema = Cinema(db_name)

	def show_movie(self, movie_id):
		movie = self.cinema.fetch_movie(movie_id)
		print("%s (%f)" % movie)
		return ("%s (%f)" % movie)

	def show_movies(self):
		output = []
		movies =self.cinema.fetch_movies()
		print("Current movies:")
		for movie in movies:
			print("[%d] - %s (%f)" % movie)
			output.append("[%d] - %s (%f)" % movie)
		return output

	def show_movie_projections(self, commands):
		if len(commands) == 2:
			return(self.show_pojections_by_id(commands[1]))
		elif len(commands) == 3:
			return(self.show_pojections_by_id_and_date(commands[1], commands[2]))

	def show_pojections_by_id(self, movie_id):
		output = []
		movie = self.cinema.fetch_movie_name(movie_id)
		print("Projections for movie '%s'" % movie[0])
		projections = self.cinema.fetch_projections_by_id(movie_id)
		for projection in projections:
			print("[%d] - %s %s (%s)" % projection)
			output.append("[%d] - %s %s (%s)" % projection)
		return output
		
	def show_pojections_by_id_and_date(self, movie_id, date):
		print("Projections for movie '%s' on %s:" % 
				(self.cinema.fetch_movie_name(movie_id)[0][0], date))
		output = []
		projections = self.cinema.fetch_projections_by_id_and_date(movie_id, date)
		for projection in projections:
			print("[%d] - %s (%s)" % projection)
			output.append("[%d] - %s (%s)" % projection)
		return output

	def show_places_map(self, taken_seats):
		map_seats = [
				[' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
				['1', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'],
				['2', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'],
				['3', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'],
				['4', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'],
				['5', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'],
				['6', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'],
				['7', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'],
				['8', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'],
				['9', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.'],
				['10', '.', '.', '.', '.', '.', '.', '.', '.', '.', '.']
			]

		for seat in taken_seats:
			map_seats[seat[0]][seat[1]] = 'X'

		return map_seats

	def show_projection(self, projection_id):
		projection = self.cinema.fetch_projection(projection_id)
		projection = projection[0]
		print(len(projection))
		print("Date and Time: %s %s (%s)" % (projection[0], projection[1], projection[2]))

	def show_projection_reservertion(self, movie_id):
		output = ["Projections for movie '%s' :" % self.cinema.fetch_movie_name(movie_id)[0][0],]
		print("Projections for movie '%s' :" % self.cinema.fetch_movie_name(movie_id)[0][0])

		projections = self.cinema.fetch_projections_by_id(movie_id)

		for projection in projections:
			print("[%d] - %s %s (%s) - %d spots available" % 
						(projection[0], projection[1], projection[2], projection[3],
							self.cinema.free_place_for_projection(projection[0])))
			output.append("[%d] - %s %s (%s) - %d spots available" % 
						(projection[0], projection[1], projection[2], projection[3],
							self.cinema.free_place_for_projection(projection[0])))

		return output

	def show_reservation_info(self, movie_id, projection_id, seats):
		print("This is your reservation:")
		self.show_movie(movie_id)
		self.show_projection(projection_id)
		print(seats)
		fin = input("Step 5 (Confirm - type 'finalize')>")
		return fin

	def cancel_reservation(self, username):
		self.cinema.cancel_reservation(username)

	def get_user_info_prompt(self):
		name = input("Step 1 (User): Choose name>")
		if name == "give_up":
			return "give_up"
			
		while True:
			tickets_number = input("Step 1 (User): Choose number of tickets>")
			if tickets_number == "give_up":
				return "give_up"
			elif tickets_number.isdigit():
				break
			else:
				print("wrong input")

		return (name, tickets_number)		

	def choose_movie_prompt(self):
		while True:
			movie_id = input("Step 2 (Movie): Choose a movie>")
			if movie_id == "give_up":
				return "give_up"
			elif movie_id.isdigit(): 
				return movie_id

	def choose_projection_prompt(self, movie_id):

		projections = self.cinema.fetch_projections_id(movie_id)

		while True:
			projection = input("Step 3 (Projection): Choose a projection>")
			if projection == "give_up":
				return "give_up"
			elif projection.isdigit():#projection in projections:
				return projection 

	def str_to_tupul(self, string):
		string = string[1:].replace(")", "")
		result_list = string.split(",")
		return (int(result_list[0]), int(result_list[1]))


	def chose_seats(self, tickets_number, projection):
		not_free_seats = self.cinema.fetch_taken_seats(projection)
		choosen_seats = []
		print("Available seats (marked with a dot):")
		#print(self.show_places_map(not_free_seats))
		seat_map = []
		for line in self.show_places_map(not_free_seats):
			#print(line)
			seat_map.append(" ".join(line))

		print("\n".join(seat_map))

		while len(choosen_seats) < tickets_number:
			
			seat = input("Step 4 (Seats): Choose seat %s>" % str(len(choosen_seats)+1))
			if seat == "give_up":
				return "give_up"
			seat = self.str_to_tupul(seat)
			if seat in not_free_seats or seat in choosen_seats:
				print("This seat is already taken!")
			elif seat[0] > 10 or seat[1] > 10:
				print("Lol...NO!")
			else:
				choosen_seats.append(seat)
			#print(choosen_seats)

		return choosen_seats


	def reservation_prompt(self):
		user_info = self.get_user_info_prompt()
		if user_info == "give_up":
			return "give_up"

		(name, tickets_number) = user_info
		tickets_number = int(tickets_number)
		self.show_movies()

		movie_id = self.choose_movie_prompt()
		if movie_id == "give_up":
			return "give_up"

		self.show_pojections_by_id(movie_id)

		while True:
			projection = self.choose_projection_prompt(movie_id)
			if projection == "give_up":
				return "give_up"
			elif tickets_number <= self.cinema.free_place_for_projection(projection):
				break

		seats = self.chose_seats(tickets_number, projection)

		if seats == "give_up":
			return "give_up"

		fin = self.show_reservation_info(movie_id, projection, seats)

		if fin == "finalize":
			for seat in seats:
				self.make_reservation(name, projection_id, seat[0], seat[1])
			print("Thanks.")

		elif fin == "give_up":
			return "give_up"

	def exit(self):
		self.cinema.exit()