コード例 #1
0
def create_cinema_db():
    cinema = Cinema(10, 10)
    movies = [
        {"name": 'The Hunger Games: Catching Fire',
         "rating": 7.9},
        {'name': 'Wreck-It Ralph',
         'rating': 7.8},
        {'name': 'Her',
         'rating': 8.3}
    ]

    projections = [
        {'movie_id': 1, 'type': '3D',
            'date': '2014-04-01', 'time': '19:10'},
        {'movie_id': 1, 'type': '2D',
            'date': '2014-04-01', 'time': '19:00'},
        {'movie_id': 1, 'type': '4DX',
            'date': '2014-04-02', 'time': '21:00'},
        {'movie_id': 3, 'type': '2D',
         'date': '2014-04-05', 'time': '20:20'},
        {'movie_id': 2, 'type': '3D',
            'date': '2014-04-02', 'time': '22:00'},
        {'movie_id': 2, 'type': '2D',
         'date': '2014-04-02', 'time': '19:30'}
    ]

    reservations = [
        {'username': '******', 'projection_id': 1,
         'row': 2, 'col': 1},
        {'username': '******', 'projection_id': 1,
         'row': 3, 'col': 5},
        {'username': '******', 'projection_id': 1,
         'row': 7, 'col': 8},
        {'username': '******', 'projection_id': 3,
         'row': 1, 'col': 1},
        {'username': '******', 'projection_id': 3,
         'row': 1, 'col': 2},
        {'username': '******', 'projection_id': 5,
         'row': 2, 'col': 3},
        {'username': '******', 'projection_id': 5,
         'row': 2, 'col': 4},
    ]

    for movie in movies:
        cinema.add_movie(**movie)
    for projection in projections:
        cinema.add_projection(**projection)
    for reservation in reservations:
        cinema.add_reservation(**reservation)
コード例 #2
0
def main():
    Base.metadata.create_all(engine)
    arena = Cinema()

    while True:
        command = input(">>>")
        if command == 'add_movie':
            arena.add_movie()
        elif command == 'add_projection':
            arena.add_projection()
        elif command == 'add_reservation':
            arena.add_reservation()
        elif command == 'show_movies':
            arena.show_movies()
        elif command == 'show_movie_projections':
            arena.show_movie_projections(1, '2014-03-22')
コード例 #3
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)
コード例 #4
0
ファイル: start.py プロジェクト: emilenovv/HackBulgaria
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()
コード例 #5
0
class MyTests(unittest.TestCase):
    def setUp(self):
        self.cinema = Cinema("test1.db")

    def test_a(self):
        self.cinema = Cinema("test1.db")

        self.cinema.add_movie('The Hunger Games: Catching Fire', 7.9)
        self.cinema.add_movie('Wreck-It Ralph', 7.8)
        self.cinema.add_movie('Her', 8.3)

        self.cinema.add_projection(1, '3D', '2014-04-01', '19:10')
        self.cinema.add_projection(1, '2D', '2014-04-01', '19:00')
        self.cinema.add_projection(1, '4DX', '2014-04-02', '21:00')
        self.cinema.add_projection(3, '2D', '2014-04-05', '20:20')
        self.cinema.add_projection(2, '3D', '2014-04-02', '22:00')
        self.cinema.add_projection(2, '2D', '2014-04-02', '19:30')

        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)

    def test_fetch_movie(self):
        movie = self.cinema.fetch_movie(3)
        self.assertEqual(movie[0], "Her")
        self.assertEqual(movie[1], 8.3)

    def test_fetch_fetch_movies(self):
        movies = self.cinema.fetch_movies()
        self.assertTrue((1, 'The Hunger Games: Catching Fire', 7.9) in movies)
        self.assertTrue((2, 'Wreck-It Ralph', 7.8) in movies)
        self.assertTrue((3, 'Her', 8.3) in movies)

    def test_fetch_projections_by_id(self):
        proj = self.cinema.fetch_projections_by_id(2)
        self.assertTrue((6, '2014-04-02', '19:30', '2D') in proj)
        self.assertTrue((5, '2014-04-02', '22:00', '3D') in proj)

    def test_fetch_projections_by_id_and_date(self):
        proj = self.cinema.fetch_projections_by_id_and_date(1, '2014-04-01')
        self.assertTrue((2, '19:00', '2D') in proj)
        self.assertTrue((1, '19:10', '3D') in proj)

    def test_fetch_taken_seats(self):
        taken = self.cinema.fetch_taken_seats(4)
        self.assertEqual(taken, [])
        taken = self.cinema.fetch_taken_seats(5)
        self.assertTrue((2, 3) in taken)
        self.assertTrue((2, 4) in taken)

    def test_free_place_for_projection(self):
        testing_value = self.cinema.free_place_for_projection(1)
        self.assertEqual(testing_value, 97)
        testing_value = self.cinema.free_place_for_projection(2)
        self.assertEqual(testing_value, 100)

    def test_fetch_projection(self):
        proj = self.cinema.fetch_projection(2)
        self.assertEqual(proj[0], ('2014-04-01', '19:00', '2D'))

    def test_z(self):
        os.remove("test1.db")