示例#1
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])
示例#2
0
class TestMovie(unittest.TestCase):
    def testAdd(self):
        self.movieRepo = MovieListGenerator().chooseMovies()
        self.movieID = self.movieRepo.ID
        self.service = Service([], self.movieRepo, [])

        self.service.addMovie(["Title1", "Desc1", "Genre1"])
        self.service.addMovie(["Title2", "Desc2", "Genre2"])
        self.service.addMovie(["Title3", "Desc3", "Genre3"])
        self.service.addMovie(["Title4", "Desc4", "Genre4"])
        self.service.addMovie(["Title5", "Desc5", "Genre5"])

        self.assertEqual(len(self.movieRepo), self.movieID + 5)
        self.assertEqual(self.movieRepo.ID, self.movieID + 5)

        self.assertEqual(self.movieRepo[self.movieID + 1],
                         Movie(self.movieID + 1, "Title1", "Desc1", "Genre1"))
        self.assertEqual(self.movieRepo[self.movieID + 2],
                         Movie(self.movieID + 2, "Title2", "Desc2", "Genre2"))
        self.assertEqual(self.movieRepo[self.movieID + 3],
                         Movie(self.movieID + 3, "Title3", "Desc3", "Genre3"))
        self.assertEqual(self.movieRepo[self.movieID + 4],
                         Movie(self.movieID + 4, "Title4", "Desc4", "Genre4"))
        self.assertEqual(self.movieRepo[self.movieID + 5],
                         Movie(self.movieID + 5, "Title5", "Desc5", "Genre5"))

    def testRemove(self):
        self.movieRepo = MovieListGenerator().chooseMovies()
        self.movieCount = self.movieRepo.ID

        del self.movieRepo[1]
        del self.movieRepo[2]
        del self.movieRepo[3]

        self.assertEqual(len(self.movieRepo), self.movieCount - 3)
        self.assertEqual(self.movieRepo[4].ID, 4)
        self.assertEqual(self.movieRepo[5].ID, 5)
        self.assertEqual(self.movieRepo[6].ID, 6)

        del self.movieRepo[4]
        del self.movieRepo[5]
        del self.movieRepo[6]

        self.assertEqual(len(self.movieRepo), self.movieCount - 6)
        self.assertEqual(self.movieRepo[7].ID, 7)
        self.assertEqual(self.movieRepo[8].ID, 8)
        self.assertEqual(self.movieRepo[9].ID, 9)

    def testUpdate(self):
        self.movieRepo = MovieListGenerator().chooseMovies()
        self.movieID = self.movieRepo.ID
        self.service = Service([], self.movieRepo, [])

        self.service.updateMovie([1, "title", "Title1"])
        self.service.updateMovie([2, "title", "Title2"])
        self.service.updateMovie([3, "title", "Title3"])
        self.service.updateMovie([4, "title", "Title4"])
        self.service.updateMovie([5, "title", "Title5"])

        self.service.updateMovie([1, "description", "Desc1"])
        self.service.updateMovie([2, "description", "Desc2"])
        self.service.updateMovie([3, "description", "Desc3"])
        self.service.updateMovie([4, "description", "Desc4"])
        self.service.updateMovie([5, "description", "Desc5"])

        self.service.updateMovie([1, "genre", "Genre1"])
        self.service.updateMovie([2, "genre", "Genre2"])
        self.service.updateMovie([3, "genre", "Genre3"])
        self.service.updateMovie([4, "genre", "Genre4"])
        self.service.updateMovie([5, "genre", "Genre5"])

        self.assertEqual(len(self.movieRepo), self.movieID)
        self.assertEqual(self.movieRepo.ID, self.movieID)

        self.assertEqual(self.movieRepo[1],
                         Movie(1, "Title1", "Desc1", "Genre1"))
        self.assertEqual(self.movieRepo[2],
                         Movie(2, "Title2", "Desc2", "Genre2"))
        self.assertEqual(self.movieRepo[3],
                         Movie(3, "Title3", "Desc3", "Genre3"))
        self.assertEqual(self.movieRepo[4],
                         Movie(4, "Title4", "Desc4", "Genre4"))
        self.assertEqual(self.movieRepo[5],
                         Movie(5, "Title5", "Desc5", "Genre5"))
示例#3
0
class TestSearch(unittest.TestCase):
    def testSearchClient(self):
        self.clients = Repository()
        self.service = Service(self.clients, [], Repository())

        self.service.addClient(["John"])
        self.service.addClient(["Mike"])
        self.service.addClient(["zmaili"])
        self.service.addClient(["Johnny"])

        result = self.service.searchClients([2, True])
        self.assertEqual(result, [self.clients[2]])
        self.assertEqual(len(self.clients), 4)
        self.assertEqual(self.clients[2], Client(2, "Mike"))

        result = self.service.searchClients(["john", False])
        self.assertEqual(result, [self.clients[1], self.clients[4]])
        self.assertEqual(len(self.clients), 4)
        self.assertEqual(self.clients[1], Client(1, "John"))
        self.assertEqual(self.clients[4], Client(4, "Johnny"))

        result = self.service.searchClients(["luca", False])
        self.assertEqual(result, [])
        self.assertEqual(len(self.clients), 4)

        self.assertRaises(EmptyError, self.service.searchClients,
                          ["john", True])

        self.service.removeClient([2])
        self.assertRaises(EmptyError, self.service.searchClients, [2, True])

        result = self.service.searchClients([3, True])
        self.assertEqual(result, [self.clients[3]])
        self.assertEqual(len(self.clients), 3)
        self.assertEqual(self.clients[3], Client(3, "zmaili"))

    def testSearchMovie(self):
        self.movies = Repository()
        self.service = Service([], self.movies, Repository())

        self.service.addMovie(["title1", "desc1", "genre1"])
        self.service.addMovie(["tiitle2", "deesc2", "geenre2"])
        self.service.addMovie(["title 3", "desc 3", "genre 3"])

        result = self.service.searchMovies(["title", False])
        self.assertEqual(result, [self.movies[1], self.movies[3]])
        self.assertEqual(len(self.movies), 3)
        self.assertEqual(self.movies[1], Movie(1, "title1", "desc1", "genre1"))
        self.assertEqual(self.movies[2],
                         Movie(2, "tiitle2", "deesc2", "geenre2"))
        self.assertEqual(self.movies[3],
                         Movie(3, "title 3", "desc 3", "genre 3"))

        result = self.service.searchMovies(["taitle", False])
        self.assertEqual(result, [])
        self.assertEqual(len(self.movies), 3)

        self.service.removeMovie([2])
        self.assertRaises(EmptyError, self.service.searchMovies, [2, True])

        self.assertRaises(EmptyError, self.service.searchMovies,
                          ["john", True])

        result = self.service.searchMovies([3, True])
        self.assertEqual(result, [self.movies[3]])
        self.assertEqual(len(self.movies), 2)
        self.assertEqual(self.movies[1], Movie(1, "title1", "desc1", "genre1"))
        self.assertEqual(self.movies[3],
                         Movie(3, "title 3", "desc 3", "genre 3"))

        result = self.service.searchMovies(["tITlE", False])
        self.assertEqual(result, [self.movies[1], self.movies[3]])
        self.assertEqual(len(self.movies), 2)
        self.assertEqual(self.movies[1], Movie(1, "title1", "desc1", "genre1"))
        self.assertEqual(self.movies[3],
                         Movie(3, "title 3", "desc 3", "genre 3"))