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)
Exemple #2
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")
Exemple #3
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")
Exemple #4
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")
Exemple #5
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)
    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