Esempio n. 1
0
    def initialize(self):
        undoStack = Stack()
        redoStack = Stack()
        self.__valid_movie = ValidMovie()
        self.__valid_client = ValidClient()
        self.__valid_rental = ValidRental()
        self.__movies_repository = Repository()
        self.__clients_repository = Repository()
        self.__rentals_repository = Repository()
        self.__service_movies = ServiceMovies(self.__movies_repository,
                                              self.__valid_movie, undoStack,
                                              redoStack,
                                              self.__rentals_repository)
        self.__service_clients = ServiceClients(self.__clients_repository,
                                                self.__valid_client, undoStack,
                                                redoStack,
                                                self.__rentals_repository)
        self.__service_rentals = ServiceRentals(self.__movies_repository,
                                                self.__clients_repository,
                                                self.__rentals_repository,
                                                self.__valid_rental, undoStack,
                                                redoStack)
        self.__service_movies.generate_movies()
        self.__service_clients.generate_client()

        self.__service_rentals.rent_movie(1, 1, 1, '1/1/1', '2/1/1')
        self.__service_rentals.return_movie(1, '3/1/1')
        self.__service_rentals.rent_movie(3, 1, 1, '5/1/1', '10/1/1')
        self.__service_rentals.return_movie(3, '15/1/1')
        self.__service_rentals.rent_movie(2, 2, 2, '2/2/2', '3/3/3')
        self.__service_rentals.return_movie(2, '7/2/2')
        self.__service_rentals.rent_movie(4, 3, 4, '1/1/1', '2/1/1')
        self.__service_rentals.return_movie(4, '2/1/1')
Esempio n. 2
0
 def test_ServiceAdd_invalidClient_throwsException(self):
     undo_stack = Stack()
     redo_stack = Stack()
     self.__rental_repository = Repository()
     self.__client_validator = ValidClient()
     self.__client_repository = Repository()
     self.__client_service = ServiceClients(self.__client_repository,
                                            self.__client_validator,
                                            undo_stack, redo_stack,
                                            self.__rental_repository)
     with self.assertRaises(ValidationError):
         self.__client_service.add_client(-1, '')
Esempio n. 3
0
 def test_ServiceUpdate_inexistentClientId_throwsException(self):
     undo_stack = Stack()
     redo_stack = Stack()
     self.__rental_repository = Repository()
     self.__client_validator = ValidClient()
     self.__client_repository = Repository()
     self.__client_service = ServiceClients(self.__client_repository,
                                            self.__client_validator,
                                            undo_stack, redo_stack,
                                            self.__rental_repository)
     self.__client_service.add_client(1, 'Bob')
     with self.assertRaises(RepositoryError):
         self.__client_service.update_client(2, '-')
Esempio n. 4
0
    def test_ServiceRemove_existingClient_isRemoved(self):
        undo_stack = Stack()
        redo_stack = Stack()
        self.__rental_repository = Repository()
        self.__client_validator = ValidClient()
        self.__client_repository = Repository()
        self.__client_service = ServiceClients(self.__client_repository,
                                               self.__client_validator,
                                               undo_stack, redo_stack,
                                               self.__rental_repository)
        self.__client_service.add_client(1, '-')

        self.__client_service.remove_client(1)
        self.assertEqual(self.__client_service.get_number(), 0)
Esempio n. 5
0
 def test_ServiceAdd_validClient_isAdded(self):
     undo_stack = Stack()
     redo_stack = Stack()
     self.__rental_repository = Repository()
     self.__client_validator = ValidClient()
     self.__client_repository = Repository()
     self.__client_service = ServiceClients(self.__client_repository,
                                            self.__client_validator,
                                            undo_stack, redo_stack,
                                            self.__rental_repository)
     self.__client_service.add_client(1, 'John Doe')
     self.assertEqual(
         self.__client_service.get_clients()[
             self.__client_service.get_number() - 1], Client(1, 'John Doe'))
Esempio n. 6
0
    def test_ServiceUpdate_client_isUpdated(self):
        undo_stack = Stack()
        redo_stack = Stack()
        self.__rental_repository = Repository()
        self.__client_validator = ValidClient()
        self.__client_repository = Repository()
        self.__client_service = ServiceClients(self.__client_repository,
                                               self.__client_validator,
                                               undo_stack, redo_stack,
                                               self.__rental_repository)
        self.__client_service.add_client(1, 'Bob')

        self.__client_service.update_client(1, 'Billy')
        self.assertEqual(self.__client_service.get_clients()[0].get_name(),
                         'Billy')
Esempio n. 7
0
    def initialize(self):
        self.__valid_movie = ValidMovie()
        self.__valid_client = ValidClient()
        self.__movies_repository = Repository()
        self.__clients_repository = Repository()
        self.__rentals_repository = Repository()
        undoStack = Stack()
        redoStack = Stack()
        self.__service_movies = ServiceMovies(self.__movies_repository,
                                              self.__valid_movie, undoStack,
                                              redoStack,
                                              self.__rentals_repository)
        self.__service_clients = ServiceClients(self.__clients_repository,
                                                self.__valid_client, undoStack,
                                                redoStack,
                                                self.__rentals_repository)

        self.__movies_repository.add(Movie(1, 'Frozen', 'Ice', 'Animation'))
        self.__movies_repository.add(
            Movie(2, 'Harry Potter', 'Wizard', 'Adventure'))
        self.__clients_repository.add(Client(1, 'John Doe'))
        self.__clients_repository.add(Client(2, 'Jane Doe'))
Esempio n. 8
0
    def test(self):

        valid_movie = ValidMovie()
        valid_client = ValidClient()
        valid_rental = ValidRental()
        repository_movie = Repository()
        repository_client = Repository()
        repository_rental = Repository()
        undo_stack = Stack()
        redo_stack = Stack()
        service_movie = ServiceMovies(repository_movie, valid_movie,
                                      undo_stack, redo_stack,
                                      repository_rental)
        service_client = ServiceClients(repository_client, valid_client,
                                        undo_stack, redo_stack,
                                        repository_rental)
        service_rental = ServiceRentals(repository_movie, repository_client,
                                        repository_rental, valid_rental,
                                        undo_stack, redo_stack)
        service_undo = ServiceUndo(undo_stack, redo_stack)
        service_undo.clear()

        service_movie.add_movie(1, 'a', 'a', 'a')
        service_undo.undo()
        self.assertEqual(0, service_movie.get_number())
        service_undo.redo()
        self.assertEqual(service_movie.get_movies()[0],
                         Movie(1, 'a', 'a', 'a'))

        service_client.add_client(1, 'a')
        service_undo.undo()
        self.assertEqual(0, service_client.get_number())
        service_undo.redo()
        self.assertEqual(service_client.get_clients()[0], Client(1, 'a'))
        with self.assertRaises(UndoError):
            service_undo.redo()

        service_client.update_client(1, 'b')
        service_undo.undo()
        self.assertEqual(service_client.get_clients()[0].get_name(), 'a')
        service_undo.redo()
        self.assertEqual(service_client.get_clients()[0].get_name(), 'b')

        service_rental.rent_movie(1, 1, 1, '1/1/1', '2/2/2')
        service_client.remove_client(1)
        self.assertEqual(service_rental.get_number(), 0)
        self.assertEqual(service_client.get_number(), 0)
        service_undo.undo()
        self.assertEqual(service_rental.get_number(), 1)
        self.assertEqual(service_client.get_number(), 1)
        service_undo.redo()
        self.assertEqual(service_rental.get_number(), 0)
        self.assertEqual(service_client.get_number(), 0)

        service_client.add_client(1, 'a')
        service_rental.rent_movie(1, 1, 1, '1/1/1', '2/2/2')
        service_undo.undo()
        self.assertEqual(service_rental.get_number(), 0)
        service_undo.redo()
        self.assertEqual(
            service_rental.get_rentals()[0],
            Rental(1, 1, 1, Date(1, 1, 1), Date(2, 2, 2), Date(0, 0, 0)))

        service_rental.return_movie(1, '3/3/3')
        service_undo.undo()
        self.assertEqual(service_rental.get_rentals()[0].get_returnDate(),
                         Date(0, 0, 0))
        service_undo.redo()
        self.assertEqual(service_rental.get_rentals()[0].get_returnDate(),
                         Date(3, 3, 3))
Esempio n. 9
0
 def test_validate_invalidClient_throwsException(self):
     validator = ValidClient()
     self.__invalid_client = Client(-2, '')
     with self.assertRaises(ValidationError):
         validator.validate_client(self.__invalid_client)
Esempio n. 10
0
 def test_validate_invalidClientID_throwsException(self):
     validator = ValidClient()
     self.__client_invalidID = Client(-2, 'Elsa')
     with self.assertRaises(ValidationError):
         validator.validate_client(self.__client_invalidID)
Esempio n. 11
0
 def test_validate_validClient_None(self):
     validator = ValidClient()
     self.__valid_client = Client(1, 'a')
     validator.validate_client(self.__valid_client)
Esempio n. 12
0
from entities import Client, Rental, Movie
from valid import ValidMovie, ValidClient, ValidRental
from repository import Repository, Stack
from service import ServiceMovies, ServiceClients, ServiceRentals
from undo import ServiceUndo
from ui import Console
''' Validators '''
valid_movie = ValidMovie()
valid_client = ValidClient()
valid_rental = ValidRental()
''' Undo Controller '''
undo_stack = Stack()
redo_stack = Stack()
''' Repositories '''
# loading settings.properties

filepath = "settings_binary.properties"

try:
    file = open(filepath, "r")
    line = file.readline().strip()  # reading repository = ...
    line = line.split(" ")
    if line[2] == "inmemory":
        repository_movie = Repository()
        repository_client = Repository()
        repository_rental = Repository()
        ''' Services '''
        service_movie = ServiceMovies(repository_movie, valid_movie,
                                      undo_stack, redo_stack,
                                      repository_rental)
        service_client = ServiceClients(repository_client, valid_client,