Exemple #1
0
 def delete_client(client_id):
     try:
         ClientService.get_client_by_id(int(client_id))
         ClientService.delete_client(int(client_id))
         return 'Successfully Deleted', 205
     except ResourceNotFound as r:
         return r.message, 404
    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 #3
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)