示例#1
0
class TestRent(unittest.TestCase):
    clients = ClientListGenerator().chooseClients()
    movies = MovieListGenerator().chooseMovies()

    def testRent(self):
        self.rentals = Repository()
        self.service = Service(self.clients, self.movies, self.rentals)

        self.service.rentMovie([1, 1, date(2019, 11, 12), date(2019, 11, 15)])
        self.assertTrue(self.movies[1].isRented)
        self.assertEqual(len(self.rentals), 1)
        self.assertEqual(self.rentals[1].rentDate, date(2019, 11, 12))
        self.assertEqual(self.rentals[1].dueDate, date(2019, 11, 15))
        self.assertEqual(self.rentals[1].clientID, 1)
        self.assertEqual(self.rentals[1].movieID, 1)

        self.service.rentMovie([2, 2, date(2019, 11, 12), date(2019, 11, 15)])
        self.assertTrue(self.movies[2].isRented)
        self.assertEqual(len(self.rentals), 2)
        self.assertEqual(self.rentals[2].rentDate, date(2019, 11, 12))
        self.assertEqual(self.rentals[2].dueDate, date(2019, 11, 15))
        self.assertEqual(self.rentals[2].clientID, 2)
        self.assertEqual(self.rentals[2].movieID, 2)

    def testReturn(self):
        self.rentals = Repository()
        self.service = Service(self.clients, self.movies, self.rentals)

        self.service.rentMovie([1, 1, date(2019, 11, 12), date(2019, 11, 15)])
        self.service.rentMovie([2, 2, date(2019, 11, 12), date(2019, 11, 15)])
        self.service.rentMovie([3, 3, date(2019, 11, 12), date(2019, 11, 15)])
        self.service.rentMovie([4, 4, date(2019, 11, 12), date(2019, 11, 15)])

        self.service.returnMovie([1, 1, 1])
        self.assertFalse(self.movies[1].isRented)
        self.assertEqual(len(self.rentals), 4)
        self.assertIsNotNone(self.rentals[1].returnDate)

        self.service.returnMovie([3, 3, 3])
        self.assertFalse(self.movies[3].isRented)
        self.assertEqual(len(self.rentals), 4)
        self.assertIsNotNone(self.rentals[3].returnDate)

        self.assertTrue(self.movies[2].isRented)
        self.assertTrue(self.movies[4].isRented)
示例#2
0
class RentalListGenerator(object):
    '''
    Class for the 
    Fields:
        Public:
            - None
        Private:
            - None
    Methods:
        Public:
            - None
        Private:
            - None
    Properties:
        - None
    Setters:
        - None
    '''
    def __init__(self, clients, movies):
        self.clients = clients
        self.movies = movies
        self.clientCount = len(self.clients)
        self.movieCount = len(self.movies)

        self.rentals = Repository()
        self.service = Service(self.clients, self.movies, self.rentals)
        self.val = Validator(self.clients, self.movies, self.rentals)

    def __generatePastRental(self, isLate):
        '''
        Generates a Rental that has been done and due in the past, and which is or is not returned
        '''
        #both date1 and date2 need to be 'random' days in the past, date1 < date2
        client = random.randint(1, self.clientCount)
        movie = random.randint(1, self.movieCount)
        nrOfDays = random.randint(1, 500)

        date1 = date.today() - timedelta(nrOfDays)
        date2 = date.today() - timedelta(nrOfDays - random.randint(3, 5))

        try:
            self.val.canRent(client)
            if self.movies[movie].isRented == True:
                return False
        except:
            return False

        self.service.rentMovie([client, movie, date1, date2])
        if not isLate:
            self.service.returnMovie([client, movie, self.rentals.ID])

        return True

    def __generateCurrentRental(self):
        '''
        Generates a Rental that is currently active, but not late
        '''
        client = random.randint(1, self.clientCount)
        movie = random.randint(1, self.movieCount)

        date1 = date.today() - timedelta(random.randint(1, 10))
        date2 = date.today() + timedelta(random.randint(1, 10))

        try:
            self.val.canRent(client)
            if self.movies[movie].isRented == True:
                return False
        except:
            return False

        self.service.rentMovie([client, movie, date1, date2])
        self.service.returnMovie([client, movie, self.rentals.ID])

        return True

    def generateList(self):
        for i in range(RENTAL_COUNT // 2):
            result = False
            while result == False:
                result = self.__generateCurrentRental()

        for i in range(RENTAL_COUNT // 2):
            result = False
            while result == False:
                result = self.__generatePastRental(random.randint(0, 1))

        return self.rentals
示例#3
0
class TestSorting(unittest.TestCase):

    Client1 = Client(1, "John")
    Client2 = Client(2, "Mike")
    Client3 = Client(3, "Nike")

    Movie1 = Movie(1, "Title1", "Desc1", "Genre1")
    Movie2 = Movie(2, "Title2", "Desc2", "Genre2")
    Movie3 = Movie(3, "Title3", "Desc3", "Genre3")

    def __reset(self):
        self.clients = Repository()
        self.movies = Repository()
        self.rentals = Repository()
        self.service = Service(self.clients, self.movies, self.rentals)

        self.service.addClient(["John"])
        self.service.addClient(["Mike"])
        self.service.addClient(["Nike"])

        self.service.addMovie(["Title1", "Desc1", "Genre1"])
        self.service.addMovie(["Title2", "Desc2", "Genre2"])
        self.service.addMovie(["Title3", "Desc3", "Genre3"])

    def testActiveClients(self):
        self.__reset()

        self.service.rentMovie([1, 1, date(2019, 10, 20), date(2019, 10, 29)])
        self.service.rentMovie([2, 2, date(2019, 11, 20), date(2019, 11, 30)])
        self.service.rentMovie([3, 1, date(2019, 10, 30), date(2019, 11, 12)])

        result = self.service.mostActive(["client"])
        self.assertEqual(result, [self.Client1, self.Client3, self.Client2])

    def testRentedMovies(self):
        self.__reset()

        self.service.rentMovie([1, 1, date(2019, 10, 20), date(2019, 10, 29)])
        self.service.rentMovie([2, 2, date(2019, 11, 20), date(2019, 11, 30)])
        self.service.rentMovie([3, 1, date(2019, 10, 30), date(2019, 11, 12)])

        result = self.service.mostActive(["movie"])
        self.assertEqual(result, [self.Movie1, self.Movie2, self.Movie3])

    def testLateRentals(self):
        self.__reset()

        self.service.rentMovie([1, 1, date(2019, 10, 20), date(2019, 10, 29)])
        self.service.rentMovie([2, 2, date(2019, 11, 20), date(2019, 11, 24)])
        self.service.rentMovie([3, 3, date(2018, 10, 20), date(2018, 10, 29)])

        Rental1 = Rental(1, 1, 1, date(2019, 10, 20), date(2019, 10, 29), None)
        Rental2 = Rental(2, 2, 2, date(2019, 11, 20), date(2019, 11, 24), None)
        Rental3 = Rental(3, 3, 3, date(2018, 10, 20), date(2018, 10, 29), None)

        result = self.service.lateRentals([])

        self.assertEqual(result, [Rental3, Rental1, Rental2])

        self.service.returnMovie([3, 3, 3])
        self.service.returnMovie([2, 2, 2])
        self.service.returnMovie([1, 1, 1])