示例#1
0
    def test_delete_rentals(self):
        repoRentals = Repository()
        repoClient = Repository()
        repoMovie = Repository()
        undo_service = UndoService()
        serviceC = ClientService(repoClient, undo_service)
        serviceM = MovieService(repoMovie, undo_service)
        serviceC.add_client(2, "Ana", False)
        serviceC.add_client(5, "Ion", False)
        serviceC.add_client(1, "Paula", False)
        serviceM.add_movie(6, "Frozen", "Ice and songs", "Animation", False)
        serviceM.add_movie(2, "Titanic", "a", "Romance", False)

        service = RentalService(repoRentals, repoClient, repoMovie, undo_service)
        service.rent_a_movie(2, 6, "2019-05-15", "2019-05-26", None)
        service.rent_a_movie(5, 2, "2019-05-15", "2019-05-26", "2019-05-25")

        serviceC.delete_client(2, False)
    # Remove rental by client id
        service.remove_rental_by_client(2, False)
        self.assertEqual(len(service.list_rentals()), 1)

        serviceM.delete_movie(2, False)
    # Remove rental by movie id
        service.remove_rental_by_movie(2, False)
        self.assertEqual(len(service.list_rentals()), 0)
示例#2
0
 def test_init_list(self):
     repo = Repository()
     repo_client = Repository()
     repo_movie = Repository()
     undo_service = UndoService()
     Rs = RentalService(repo, repo_client, repo_movie, undo_service)
     Rs.init_list_rentals()
     self.assertEqual(len(Rs.list_rentals()), 9)
示例#3
0
    def test_late_rentals(self):
        repoR = Repository()
        repoC = Repository()
        repoM = Repository()
        undo_service = UndoService()
        service_client = ClientService(repoC, undo_service)
        service_client.init_list_clients()

        service_movie = MovieService(repoM, undo_service)
        service_movie.init_list_movies()

        service = RentalService(repoR, repoC, repoM, undo_service)
        service.init_list_rentals()

        statistics = StatisticsService(repoC, repoM, repoR)
        late_rentals = statistics.late_rentals()
        self.assertEqual(len(late_rentals), 7)
示例#4
0
 def test_update_client(self):
     repo = Repository()
     undo_service = UndoService()
     client_service = ClientService(repo, undo_service)
     client_service.add_client(1, "Popescu Alin")
     client_service.update_client(1, "Ionescu George")
     list_clients = client_service.list_clients()
     self.assertEqual(len(list_clients), 1)
     with self.assertRaises(IdError):        # client does not exist
         client_service.update_client(2, "Mara")
示例#5
0
    def test_add_rentals(self):
        repoRentals = Repository()
        repoClient = Repository()
        repoMovie = Repository()
        undo_service = UndoService()
        serviceC = ClientService(repoClient, undo_service)
        serviceM = MovieService(repoMovie,undo_service)
        serviceC.add_client(2, "Ana",False)
        serviceC.add_client(5, "Ion", False)
        serviceC.add_client(1, "Paula",False)
        serviceM.add_movie(6, "Frozen", "Ice and songs", "Animation", False)
        serviceM.add_movie(2, "Titanic", "a", "Romance", False)

        service = RentalService(repoRentals, repoClient, repoMovie, undo_service)
        service.rent_a_movie(2, 6, "2019-05-15", "2019-05-26", None)
        service.rent_a_movie(5, 2, "2019-05-15", "2019-05-26", "2019-05-25")

    # Rent a movie
        with self.assertRaises(IdError):  # client does not exist
            service.rent_a_movie(3, 6, "2019-05-20", "2019-06-07", None)

        with self.assertRaises(ServiceError):   # client eligible
            service.rent_a_movie(2, 2, "2019-05-29", "2019-06-15", None)

        with self.assertRaises(ServiceError):       # movie not available
            service.rent_a_movie(5, 6, "2019-05-20", "2019-06-07", None)

        with self.assertRaises(ServiceError):       # rental already added
            service.rent_a_movie(5, 2, "2019-05-15", "2019-05-26", "2019-05-25")

        with self.assertRaises(ValueError):     # invalid due date
            Rv.validate_due_date("2019-11-26", "2019-10-02")

    # Return a movie
        with self.assertRaises(IdError):      # client does not exist
            service.return_a_movie(3, 6, "2019-05-26")

        with self.assertRaises(IdError):      # movie does not exist
            service.return_a_movie(2, 1, "2019-05-26")

        service.return_a_movie(2, 6, "2019-05-25") # return a movie
        self.assertEqual(len(serviceM.list_movies()), 2)       # 2 valid rentals
示例#6
0
    def test_delete_movie(self):
        repo = Repository()
        undo_service = UndoService()
        movie_service = MovieService(repo, undo_service)

        movie_service.add_movie(1, "Interstelar", "Physics real facts", "SF")
        movie_service.add_movie(2, "Notebook", "You will definitely cry", "Romantic")
        movie_service.delete_movie(1)
        list_m = movie_service.list_movies()

        self.assertEqual(len(list_m), 1)
示例#7
0
 def test_delete_client(self):
     repo = Repository()
     undo_service = UndoService()
     client_service = ClientService(repo, undo_service)
     client_service.add_client(1, "Popescu Alin")
     client_service.add_client(2, "Ionescu Maria")
     client_service.add_client(3, "Trifan Ion")
     client_service.delete_client(2)
     list_clients = client_service.list_clients()
     self.assertEqual(len(list_clients), 2)
     with self.assertRaises(IdError):    # client does not exist
         client_service.delete_client(4)
示例#8
0
    def test_add_client(self):
        the_id = 1
        name = "Popescu Alin"
        repo = Repository()
        undo_service = UndoService()
        client_service = ClientService(repo, undo_service)
        client_service.add_client(the_id, name)
        list_clients = client_service.list_clients()
        self.assertEqual(len(list_clients), 1)

        with self.assertRaises(IdError):       # client already added
            client_service.add_client(1, "Mara Pop")
示例#9
0
    def test_most_rented_movies(self):
        repoR = Repository()
        repoC = Repository()
        repoM = Repository()
        undo_service = UndoService()
        service_client = ClientService(repoC, undo_service)
        service_client.init_list_clients()

        service_movie = MovieService(repoM, undo_service)
        service_movie.init_list_movies()

        service = RentalService(repoR, repoC, repoM, undo_service)
        service.init_list_rentals()

        statistics = StatisticsService(repoC, repoM, repoR)
        most_rented_list = statistics.most_rented_movies()
        most_rented_list = sorted(most_rented_list, key=lambda rental: rental.days, reverse=True)

        rental_days = most_rented_list[0]
        owner = service_movie.search_by_id(3)
        self.assertEqual(rental_days.owner, owner)
        self.assertEqual(rental_days.days, 56)
示例#10
0
    def test_update_movie(self):
        repo = Repository()
        undo_service = UndoService()
        movie_service = MovieService(repo, undo_service)

        the_id1 = 1
        title1 = "Titanic"
        description1 = "Leonardo DiCaprio"
        genre1 = "Drama"
        movie_service.add_movie(the_id1, title1, description1, genre1)

        the_id = 1
        title = "Frozen"
        description = "Elsa"
        genre = "Animation"
        movie_service.update_movie(the_id, title, description, genre)
        self.assertEqual(len(movie_service.list_movies()), 1)
示例#11
0
    def test_search(self):
        repo = Repository()
        undo_service = UndoService()
        client_service = ClientService(repo, undo_service)
        client_service.add_client(1, "Popescu Alin")
        client_service.add_client(2, "Ionescu Maria")
        client_service.add_client(3, "Trifan Ion")
        client_service.add_client(4, "Muresan Alina")

        # by id
        match = client_service.search_by_id(1)
        self.assertEqual(match.id, 1)

        # by name
        match = client_service.search_by_name("alin")
        self.assertEqual(match[0].name, "Popescu Alin")
        self.assertEqual(match[1].name, "Muresan Alina")
示例#12
0
    def test_search(self):
        repo = Repository()
        undo_service = UndoService()
        movie_service = MovieService(repo, undo_service)

        movie_service.add_movie(1, "Interstelar", "Physics real facts", "SF")
        movie_service.add_movie(2, "Notebook", "You will definitely cry", "Romantic")
        movie_service.add_movie(3, "Now you see me", "Magic", "Mistery")
        movie_service.add_movie(4, "Always be my maybe", "", "Romance")
    # by id
        match = movie_service.search_by_id(2)
        self.assertEqual(match.title, "Notebook")
    # by title
        matches = movie_service.search_by_title("no")
        self.assertEqual(matches[0].id, 2)
        self.assertEqual(matches[1].id, 3)
    # by description
        matches = movie_service.search_by_description("cry")
        self.assertEqual(matches[0].id, 2)
    # by genre
        matches = movie_service.search_by_genre("roman")
        self.assertEqual(matches[0].id, 2)
        self.assertEqual(matches[1].id, 4)
示例#13
0
 def test_init_list(self):
     repo = Repository()
     undo_service = UndoService()
     Ms = MovieService(repo, undo_service)
     Ms.init_list_movies()
     self.assertEqual(len(Ms.list_movies()), 10)
示例#14
0
        'inmemory': Repository,
        'textfiles': FileRepository,
        'binaryfiles': BinaryRepository,
        'jsonfiles': JSONRepository,
        'database': DatabaseRepository
    }
    return repositories[settings_dict["repository"]]


if __name__ == '__main__':
    try:
        settings = read_settings()
        repository_type = set_classes(settings)

        if repository_type == Repository:
            client_repository = Repository()
            movie_repository = Repository()
            rental_repository = Repository()
        elif repository_type == DatabaseRepository:
            database = mysql.connector.connect(host="127.0.0.1",
                                               user="******",
                                               passwd="juneAd@^^2019",
                                               database="mydatabase")
            cursor = database.cursor()
            client_repository = DatabaseRepository(database, cursor, 'clients',
                                                   ["idClient", "name"])
            movie_repository = DatabaseRepository(
                database, cursor, 'movies',
                ["id_movie", "title", "description", "genre"])
            rental_repository = DatabaseRepository(
                database, cursor, 'rentals', [
示例#15
0
 def test_init_list(self):
     repo = Repository()
     undo_service = UndoService()
     Cs = ClientService(repo, undo_service)
     Cs.init_list_clients()
     self.assertEqual(len(repo), 10)