Пример #1
0
def main():
    """
    Allows the user to add movies to their cart(Rental)
    Input: The menu choice that the user would like to add (an int) or 
    Output: The string representation of a list of movies and the total cost to rent them all
    """

    movieList = Movie.display_Movies("movie_csv.txt")#Read the movies from CSV, create objects

    for item in movieList:
        print(str(item))#Display the objects to the user
        
    newCustomer = Customer("Mister", "Customer") #Create customer object

    newRental = Rental(newCustomer) #Create a new rental
        
    keepGoing = "yes"
    
    while keepGoing != "no":

        movieChoice = int(input("Enter the number of the movie to rent: "))
        daysRented = int(input("Enter the number of days to keep the movie: "))
        
        rented_movie_list = Rental.rent_movie(Movie.get_Movie_ByID(movieList, movieChoice), daysRented)
        #Get the movie by it's id property, pass the movie object and the number of days rented to the rent_movie method.
        #Rental.rent_movie adds it to a list and returns that list
    
        keepGoing = input("Would you like to rent another movie? ").lower()


    print(str(newRental)) #Display the poroperties of the Rental object
    Movie.display_Movies_Rented(rented_movie_list)#Display the movies in rented_movie_list and their relevant properties
Пример #2
0
 def testFindRentalById(self):
     '''
     Function that checks whether a rental Id is correctly found in a list
     input:-
     preconditions:-
     output:-
     postconditions: If the Id is not correctly found, an error will appear
     '''
     myListOfRentals = [
         Rental(1, 2, 3, "10.11.2018", "20.11.2018", ""),
         Rental(2, 5, 4, "9.11.2018", "19.11.2018", "14.11.2018")
     ]
     thisRental = findRentalById(1, myListOfRentals)
     myRental = Rental(1, 2, 3, "10.11.2018", "20.11.2018", "")
     self.assertEqual(thisRental._Rental__rentalId,
                      myRental._Rental__rentalId)
     self.assertEqual(thisRental._Rental__bookId, myRental._Rental__bookId)
     self.assertEqual(thisRental._Rental__clientId,
                      myRental._Rental__clientId)
     self.assertEqual(thisRental._Rental__rentedDate,
                      myRental._Rental__rentedDate)
     self.assertEqual(thisRental._Rental__dueDate,
                      myRental._Rental__dueDate)
     self.assertEqual(thisRental._Rental__returnedDate,
                      myRental._Rental__returnedDate)
Пример #3
0
 def testCompleteList(self):
     '''
     Function that checks whether a list of rented books is correctly completed from the list of books and the list of rentals
     input:-
     preconditions:-
     output:-
     postconditions: If the list is incorrectly completed, an error will appear
     '''
     myListOfRentedBooks = []
     myListOfBooks = [
         Book(1, "Enciclopedia tuturor", "Multe informatii", "Smart guy"),
         Book(2, "Romance at its finest", "For the soft-hearted",
              "Sensitive guy")
     ]
     myListOfRentals = [
         Rental(1, 2, 3, "1.4.2018", "5.4.2018", ""),
         Rental(2, 1, 5, "2.3.2018", "9.3.2018", "15.3.2018"),
         Rental(3, 2, 1, "2.1.2018", "5.1.2018", "4.1.2018")
     ]
     completeList(myListOfRentedBooks, myListOfBooks, myListOfRentals)
     self.assertEqual(myListOfRentedBooks[0][0], 1)
     self.assertEqual(myListOfRentedBooks[0][1], 1)
     self.assertEqual(myListOfRentedBooks[0][2], 13)
     self.assertEqual(myListOfRentedBooks[1][0], 2)
     self.assertEqual(myListOfRentedBooks[1][1], 2)
     date = datetime.now()
     numberOfDays = date - datetime(2018, 4, 1)
     self.assertEqual(myListOfRentedBooks[1][2], int(numberOfDays.days) + 2)
Пример #4
0
    def testCheckBookAvailability(self):
        '''
        Function that checks whether the availability of a book is correctly found
        input:-
        preconditions:-
        output:-
        postconditions: If the availabilty is incorrectly interpreted, an error will appear
        '''
        myListOfRentals = [
            Rental(1, 2, 3, "1.1.2018", "2.2.2018", ""),
            Rental(2, 4, 3, "1.2.2018", "2.3.2018", "3.3.2018")
        ]
        IdBook1 = 2
        IdBook2 = 4
        try:
            checkBookAvailability(IdBook1, myListOfRentals)
            assert False
        except ValueError:
            assert True

        try:
            checkBookAvailability(IdBook2, myListOfRentals)
            assert True
        except ValueError:
            assert False
Пример #5
0
    def test_for_rent_three_movie(self):
        # Create movie 'The Avengers'
        avengers = Movie('The Avengers', Movie.NEW_RELEASE)

        # Create movie 'Okja'
        okja = Movie('Okja', Movie.CHILDRENS)
        
        # Create movie 'Limitless'
        limitless = Movie('Limitless', Movie.REGULAR)

        # Rent avengers for 3 days
        rent_avengers_for_3_days = Rental(avengers, 3)

        # Rent okja for 3 days
        rent_okja_for_3_days = Rental(okja, 3)

        # Rent limitless for 3 days
        rent_limitless_for_3_days = Rental(limitless, 3)

        self.customer.add_rental(rent_avengers_for_3_days)
        self.customer.add_rental(rent_okja_for_3_days)
        self.customer.add_rental(rent_limitless_for_3_days)

        expected_result = 'Rental history for yunseop\n\tThe Avengers\t9\n\tOkja\t1.5\n\tLimitless\t3.5\n누적 대여료: 14.0\n적립 포인트: 4'
        self.assertEquals(self.customer.statement(), expected_result)
Пример #6
0
 def testRentBook(self):
     '''
     Function that checks whether a book is correctly rented or not
     input:-
     preconditions:-
     output:-
     postconditions: If the book is rented incorrectly, an error will appear
     '''
     myListOfRentals = [
         Rental(1, 3, 2, "1.1.2018", "2.2.2018", ""),
         Rental(2, 5, 3, "2.3.2018", "4.3.2018", "5.3.2018")
     ]
     myRental = Rental(3, 2, 4, "2.3.2018", "4.4.2018", "")
     myRental._Rental__rentBook(myListOfRentals)
     newList = [
         Rental(1, 3, 2, "1.1.2018", "2.2.2018", ""),
         Rental(2, 5, 3, "2.3.2018", "4.3.2018", "5.3.2018"),
         Rental(3, 2, 4, "2.3.2018", "4.4.2018", "")
     ]
     self.assertEqual(myListOfRentals[2]._Rental__rentalId,
                      newList[2]._Rental__rentalId)
     self.assertEqual(myListOfRentals[2]._Rental__bookId,
                      newList[2]._Rental__bookId)
     self.assertEqual(myListOfRentals[2]._Rental__clientId,
                      newList[2]._Rental__clientId)
     self.assertEqual(myListOfRentals[2]._Rental__rentedDate,
                      newList[2]._Rental__rentedDate)
     self.assertEqual(myListOfRentals[2]._Rental__dueDate,
                      newList[2]._Rental__dueDate)
     self.assertEqual(myListOfRentals[2]._Rental__returnedDate,
                      newList[2]._Rental__returnedDate)
Пример #7
0
def enterData():
    lyst2 = []
    continue_on = 'y'
    while continue_on == 'y':
        
        custName = input("Enter the name of the customer: ")
        custName = custName.capitalize()
        custName = Customer(custName)
        lyst2.append(custName)
        
        rentTime = int(input("Enter the number of days rented: "))
        movieName = input ("Enter the name of the movie: ")
        movieName = movieName.capitalize()
        rentalData1 = Rental(movieName,"")
        lyst2.append(rentalData1)
        rentalData2 = Rental("",rentTime)
        lyst2.append(rentalData2)
        
        movieMenu = int(input("Enter the movie type: \n"
                          "Enter 1 for Children's movie.\n"
                          "Enter 2 for Regular movie.\n"
                          "Enter 3 for New Release movie.\n"))
        if movieMenu == 1:
            children = "Children's"
            regular = ''
            new_release = ''
            movieType = Movie(children,regular,new_release)
            lyst2.append(movieType)
            
        if movieMenu == 2:
            children = ""
            regular = 'Regular'
            new_release = ''
            movieType = Movie(children,regular,new_release)
            lyst2.append(movieType)
        
        if movieMenu == 3:
            children = ""
            regular = ''
            new_release = 'New-Release'
            movieType = Movie(children,regular,new_release)
            lyst2.append(movieType)
        continue_on = input("Would you like to enter more data? y or n ")
        if continue_on == 'y':
            continue
        else:
            break
    print()
    for i in lyst2:
        print(i)
        
    return lyst2
Пример #8
0
    def addRental(self, movieId, clientId, rentedDate):
        '''
        :param movieId: integer
        :param clientId: integer
        :param rentedDate: datetime
        :return: None
        '''

        rental = Rental(
            len(self.rentedMovies) + 1, movieId, clientId, rentedDate)

        # mark the movie as rented
        self.movies[movieId - 1].setRented(True)
        self.movies[movieId -
                    1].setTotalRentalDays(self.movies[movieId -
                                                      1].getTotalRentalDays() +
                                          7)

        # add to client rental days
        # 7 - total rental days
        # @todo change the days so that the user says how much they want to rent the movie
        # @todo min 1 day, max 7
        self.clients[clientId - 1].setTotalRentalDays(
            self.clients[clientId - 1].getTotalRentalDays() + 7)

        self.rentedMovies.append(rental)

        #self.undoList.append(['addRental', movieId, clientId, rentedDate])
        self.undoList.append(['addRental', rental])
Пример #9
0
def test():
    c_movie = Movie("CHILDRENS", Movie.CHILDRENS)
    r_movie = Movie("REGULAR", Movie.REGULAR)
    n_movie = Movie("NEW_REALEASE", Movie.NEW_REALEASE)

    c_rental = Rental(c_movie, 20)
    r_rental = Rental(r_movie, 20)
    n_rental = Rental(n_movie, 20)

    customer = Customer("CUSTOMER")
    customer.add_rental(c_rental)
    customer.add_rental(r_rental)
    customer.add_rental(n_rental)

    result = customer.text_statement()
    assert result == """Rental Record for CUSTOMER
	def test_customer_method(self):
		"""Test method in customer class"""
		eiei = Customer("eiei")
		self.assertEqual("eiei",eiei.get_name())
		eiei.add_rental(Rental(Movie("UmuUmu", Movie.NEW_RELEASE), 5))
		self.assertEqual(eiei.all_frequent_points(), 5)
		self.assertEqual(eiei.all_amount(), 15)
Пример #11
0
def main():
    customer = sys.argv[1]
    imdbID = sys.argv[2]

    rental = Rental(customer, imdbID)

    print(rental)
Пример #12
0
 def testCompleteListOfLateRentals(self):
     '''
     Function that checks whether a list of late rentals is correctly completed or not
     input:-
     preconditions:-
     output:-
     postconditions: If the list isn't correctly completed, an error will appear
     '''
     myListOfLateRentals = []
     myListOfRentals = [
         Rental(1, 2, 3, "2.1.2018", "8.1.2018", ""),
         Rental(2, 5, 4, "2.5.2018", "4.5.2018", "5.5.2018")
     ]
     completeListOfLateRentals(myListOfLateRentals, myListOfRentals)
     self.assertEqual(myListOfLateRentals[0][0], 2)
     numberOfDays = datetime.now() - datetime(2018, 1, 8)
     self.assertEqual(myListOfLateRentals[0][1], int(numberOfDays.days))
Пример #13
0
 def testValidateRentalId(self):
     '''
     Function that checks whether a rental Id already exists in a list or not
     input:-
     preconditions:-
     output:-
     postconditions: If the id doesn't exist, an error will appear
     '''
     myListOfRentals = [
         Rental(1, 3, 2, "23.8.2018", "28.8.2018", ""),
         Rental(2, 4, 5, "12.9.2018", "22.9.2018", "")
     ]
     try:
         validateRentalId(2, myListOfRentals)
         assert True
     except ValueError:
         assert False
Пример #14
0
    def test_for_rent_two_movie(self):
        # Create movie 'The Avengers'
        avengers = Movie('The Avengers', Movie.NEW_RELEASE)

        # Create movie 'Okja'
        okja = Movie('Okja', Movie.NEW_RELEASE)

        # Rent avengers for 3 days
        rent_avengers_for_3_days = Rental(avengers, 3)

        # Rent okja for 3 days
        rent_okja_for_3_days = Rental(okja, 3)

        self.customer.add_rental(rent_avengers_for_3_days)
        self.customer.add_rental(rent_okja_for_3_days)

        expected_result = 'Rental history for yunseop\n\tThe Avengers\t9\n\tOkja\t9\n누적 대여료: 18\n적립 포인트: 4'
        self.assertEquals(self.customer.statement(), expected_result)
Пример #15
0
	def getRentalData(self, fileName):
		f = open(fileName, 'r')
		for line in f:
			splitLine = re.split('[|]', line)
			nickname = splitLine[0]
			address = splitLine[1]
			rate = 0.20
			newRental = Rental(nickname.strip(), address.strip(), rate)
			self.rentalList.append(newRental)
Пример #16
0
    def addRental(self, movieId, clientId, rentedDate):
        '''
        :param movieId: integer
        :param clientId: integer
        :param rentedDate: datetime
        :return: None
        '''

        rental = Rental(len(self.rentedMovies) + 1, movieId, clientId, rentedDate)

        # mark the movie as rented

        self.movies[movieId - 1].setRented(True)
        self.movies[movieId - 1].setTotalRentalDays(self.movies[movieId - 1].getTotalRentalDays() + 7)
        self.clients[clientId - 1].setTotalRentalDays(self.clients[clientId - 1].getTotalRentalDays() + 7)
        self.rentedMovies[rental.getRentalId()] = rental

        #self.undoList.append(['addRental', movieId, clientId, rentedDate])
        self.undoList.append(['addRental', rental])
Пример #17
0
    def test_statement_for_many_movies_and_rentals(self):
        customer1 = Customer('David')
        movie1 = Movie('Madagascar', Movie.CHILDRENS)
        rental1 = Rental(movie1, 6)  # 6 day rental
        movie2 = Movie('Star Wars', Movie.NEW_RELEASE)
        rental2 = Rental(movie2, 2)  # 2 day rental
        movie3 = Movie('Gone with the Wind', Movie.REGULAR)
        rental3 = Rental(movie3, 8)  # 8 day rental
        customer1.add_rental(rental1)
        customer1.add_rental(rental2)
        customer1.add_rental(rental3)
        expected = """Rental Record for David
\tMadagascar\t6.0
\tStar Wars\t6.0
\tGone with the Wind\t11.0
Amount owed is 23.0
You earned 4 frequent renter points"""
        statement = customer1.statement()
        self.assertEqual(expected, statement)
 def __loadRentalsFromFile(self):
     file = open(self.__fileName, "r")
     oneLine = file.readline().strip()
     while oneLine != "":
         attributes = oneLine.split(" ; ")
         rental = Rental(attributes[0], attributes[1], attributes[2],
                         attributes[3], attributes[4], attributes[5])
         self.__list.append(rental)
         oneLine = file.readline().strip()
     file.close()
Пример #19
0
 def testCompleteListOfActiveClients(self):
     '''
     Function that checks whether a list of active clients is correctly completed, relying on the list of clients and the list of rentals    
     input:-
     preconditions:-
     output:-
     postconditions: If the list is incorrectly completed, an error will appear
     '''
     myListOfActiveClients = []
     myListOfClients = [Client(1, "ABC"), Client(2, "def")]
     myListOfRentals = [
         Rental(1, 4, 2, "1.4.2018", "3.4.2018", "5.4.2018"),
         Rental(2, 3, 1, "2.1.2018", "10.1.2018", "14.1.2018")
     ]
     completeListOfActiveClients(myListOfActiveClients, myListOfClients,
                                 myListOfRentals)
     self.assertEqual(myListOfActiveClients[0][0], 1)
     self.assertEqual(myListOfActiveClients[0][1], 12)
     self.assertEqual(myListOfActiveClients[1][0], 2)
     self.assertEqual(myListOfActiveClients[1][1], 4)
Пример #20
0
    def test_for_rent_one_regular_movie(self):
        # Create movie 'The Avengers'
        avengers = Movie('The Avengers', Movie.REGULAR)

        # Rent avengers for 2 days
        rent_avengers_for_2_days = Rental(avengers, 2)

        self.customer.add_rental(rent_avengers_for_2_days)

        expected_result = 'Rental history for yunseop\n\tThe Avengers\t2\n누적 대여료: 2\n적립 포인트: 1'
        self.assertEquals(self.customer.statement(), expected_result)
Пример #21
0
    def test_for_rent_one_new_release_movie(self):
        # Create movie 'The Avengers'
        avengers = Movie('The Avengers', Movie.NEW_RELEASE)

        # Rent avengers for 3 days
        rent_avengers_for_3_days = Rental(avengers, 3)

        self.customer.add_rental(rent_avengers_for_3_days)

        expected_result = 'Rental history for yunseop\n\tThe Avengers\t9\n누적 대여료: 9\n적립 포인트: 2'
        self.assertEquals(self.customer.statement(), expected_result)
Пример #22
0
 def prompt_init():
     """
     This method calls the parent methods prompt_init(), which
     asks user to initialize appropriate instances of classes House
     and Rental.
     :return: an instance which represents house for rent - inherits
     from House and Rental.
     """
     init = House.prompt_init()
     init.update(Rental.prompt_init())
     return init
Пример #23
0
 def testCompleteListOfRentedAuthors(self):
     '''
     Function that checks whether a list of rented authors is correctly completed, based on the list of books and the list of rentals
     input:-
     preconditions:-
     output:-
     postconditions: If the list is not completed correctly, an error will appear
     '''
     myListOfRentedAuthors = []
     myListOfBooks = [Book(1, "a", "b", "c"), Book(2, "d", "e", "f")]
     myListOfRentals = [
         Rental(1, 2, 4, "2.3.2018", "16.3.2018", ""),
         Rental(2, 1, 3, "1.2.2018", "19.2.2018", "21.2.2018")
     ]
     completeListOfRentedAuthors(myListOfRentedAuthors, myListOfBooks,
                                 myListOfRentals)
     self.assertEqual(myListOfRentedAuthors[0][0], "c")
     self.assertEqual(myListOfRentedAuthors[0][1], 1)
     self.assertEqual(myListOfRentedAuthors[1][0], "f")
     self.assertEqual(myListOfRentedAuthors[1][1], 1)
Пример #24
0
 def testFindRentalIndex(self):
     '''
     Function that checks whether the index of a rental with the given Id is correctly found in a list        
     input:-
     preconditions:-
     output:-
     postconditions: If the index isn't correctly found, an error will appear
     '''
     myListOfRentals = [Rental(1, 2, 4, "12.12.2017", "12.1.2018", "")]
     index = findRentalIndex(1, myListOfRentals)
     self.assertEqual(index, 0)
Пример #25
0
def menu():
    menu_text = 'Welcome to the movie management platform!\n\n(a) Search for customer by email\n(b) Retrive all customers\n(c) Search for movie\n(d) Return movie\n(e) List all unreturned films\n(x) Exit: '
    while True:
        menu_ctrl = input(menu_text)
        customer = Customer()
        inventory = Inventory()
        rental = Rental()
        if menu_ctrl == 'a':
            searched_cust = customer.search_by_email(
                input("Please write the email you'd like to search for: "))
            if searched_cust == None:
                print('Sorry, we couldnt find that customer')
            else:
                print(
                    f'Customer found!\n_______________\nFull Name: {searched_cust.first_name} {searched_cust.last_name}\nEmail: {searched_cust.email}\nStore ID: {searched_cust.store_id}\nAddress ID: {searched_cust.address_id}\nCreated: {searched_cust.create_date}\nUpdated: {searched_cust.last_update}'
                )

        elif menu_ctrl == 'b':
            all_custs = customer.get_all()
            for cust in all_custs:
                print(
                    f'_______________\nCustomer ID: {cust.customer_id}\nFull Name: {cust.first_name} {cust.last_name}\nEmail: {cust.email}'
                )

        elif menu_ctrl == 'c':
            text = input('Please enter your search term: ')
            search_results = inventory.search_by_text(text, 1)
            for result in search_results:
                print(
                    f'Movie details:\n______________\nInventory ID: {result.inventory_id}\nFilm ID: {result.film_id}\nFilm Title: {result.title}\nFilm Description: {result.description}\nRating: {result.rating}\nRental rate: {result.rental_rate}\n\n'
                )

        elif menu_ctrl == 'd':
            return_film = int(
                input('Please enter the id for the film you are returning: '))
            rental.return_rental(return_film)

        elif menu_ctrl == 'e':
            film_list = rental.all_unreturned()
            for film in film_list:
                print(
                    f"Unreturned rental details\n_________________________\nRental ID: {film.rental_id}\nRental Date: {film.rental_date}\nCustomer Name: {film.cust_name}\nCustomer Email: {film.email}\nPostal Address: {film.postal_code}\nTotal Due: ${film.compute_owed(film.rental_id)}"
                )
            sub_menu_ctrl = input(
                'Please type in a rental ID to return or press (x) to return to main menu'
            )
            if sub_menu_ctrl != 'x':
                #write better logic to validate input
                if input('Are you certain? Y/N: ') == 'Y':
                    rental.return_rental(int(sub_menu_ctrl))
                    print('Returned successfully\n\n')

        elif menu_ctrl == 'x':
            break
Пример #26
0
 def testUniqueRentalId(self):
     '''
     Function that checks whether a function correctly validates a new Id, in order to avoid duplicates
     input:-
     preconditions:-
     output:-
     postconditions: If the Id isn't validated correctly, an error will appear
     '''
     myListOfRentals = [Rental(1, 2, 3, "1.1.1", "2.2.2", "")]
     try:
         uniqueRentalId(2, myListOfRentals)
         assert True
     except ValueError:
         assert False
Пример #27
0
def start(path):
    # initializing data
    data_from_file = {}
    cars = {}
    rentals = []

    with open(path) as f:
        data_from_file = json.load(f)

    for car in data_from_file["cars"]:
        cars[car["id"]] = Car(car["id"], car["price_per_km"],
                              car["price_per_day"])

    for rental in data_from_file["rentals"]:
        new_rental = Rental(rental["id"], rental["start_date"],
                            rental["end_date"], rental["distance"],
                            rental["car_id"])
        new_rental.compute_price(cars)
        rentals.append(new_rental.format_for_export())

    with open('data/output.json', 'w', encoding='utf-8') as file:
        to_dump = {}
        to_dump["rentals"] = rentals
        json.dump(to_dump, file, ensure_ascii=False, indent=4)
Пример #28
0
	def test_statement(self):
		stmt = self.c.statement()
		# visual testing
		print(stmt)
		# get total charges from statement using a regex
		pattern = r".*Total [Cc]harges\s+(\d+\.\d\d).*"
		matches = re.match(pattern, stmt, flags=re.DOTALL)
		self.assertIsNotNone(matches)
		self.assertEqual("0.00", matches[1])
		# add a rental
		self.c.add_rental(Rental(self.new_movie, 4)) # days
		stmt = self.c.statement()
		matches = re.match(pattern, stmt.replace('\n',''), flags=re.DOTALL)
		self.assertIsNotNone(matches)
		self.assertEqual("12.00", matches[1])
Пример #29
0
    def test_statement(self):
        customer = Customer("Jamie")
        movies = [
            Movie("Interstella", MovieCode.REGULAR),
            Movie("Arrival", MovieCode.NEW_RELEASE),
            Movie("Moana", MovieCode.CHILDREN),
            Movie("LaLaLand", MovieCode.NEW_RELEASE)
        ]

        for i in range(4):
            customer.add_rental(Rental(movies[i], i + 3))

        self.assertEqual(
            customer.statement(), "Rental record for Jamie\n" +
            "\tInterstella\t3.5\n" + "\tArrival\t12\n" + "\tMoana\t4.5\n" +
            "\tLaLaLand\t18\n" + "You owed 38.0\nYou earned 6 points\n")
Пример #30
0
    def prompt_init():
        init = House.prompt_init()
        init.update(Rental.prompt_init())
        
        return init


#Sets the prompt to set de values
#init = HouseRental.prompt_init()
#print(init)

#with the data setted, instance a object and sets
# the data(**) by the constructor 
#house = HouseRental(**init)
#print(house.__dict__, '--->')

#show data for a rental house
#house.display()