Ejemplo 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')
Ejemplo n.º 2
0
 def test_ServiceAdd_invalidMovie_throwsException(self):
     undo_stack = Stack()
     redo_stack = Stack()
     self.__movie_validator = ValidMovie()
     self.__movie_repository = Repository()
     self.__rental_repository = Repository
     self.__movie_service = ServiceMovies(self.__movie_repository,
                                          self.__movie_validator,
                                          undo_stack, redo_stack,
                                          self.__rental_repository)
     with self.assertRaises(ValidationError):
         self.__movie_service.add_movie(-1, '', '-', '-')
Ejemplo n.º 3
0
 def test_ServiceRemove_inexistentMovie_throwsException(self):
     undo_stack = Stack()
     redo_stack = Stack()
     self.__movie_validator = ValidMovie()
     self.__movie_repository = Repository()
     rental_repository = Repository()
     self.__movie_service = ServiceMovies(self.__movie_repository,
                                          self.__movie_validator,
                                          undo_stack, redo_stack,
                                          rental_repository)
     self.__movie_service.add_movie(1, '-', '-', '-')
     with self.assertRaises(RepositoryError):
         self.__movie_service.remove_movie(2)
Ejemplo n.º 4
0
 def test_ServiceRemove_existingMovie_isRemoved(self):
     undo_stack = Stack()
     redo_stack = Stack()
     self.__rental_repository = Repository()
     self.__movie_validator = ValidMovie()
     self.__movie_repository = Repository()
     self.__movie_service = ServiceMovies(self.__movie_repository,
                                          self.__movie_validator,
                                          undo_stack, redo_stack,
                                          self.__rental_repository)
     self.__movie_service.add_movie(1, '-', '-', '-')
     self.__movie_service.remove_movie(1)
     self.assertEqual(self.__movie_service.get_number(), 0)
Ejemplo n.º 5
0
 def test_ServiceUpdate_inexistentId_throwsException(self):
     undo_stack = Stack()
     redo_stack = Stack()
     self.__movie_validator = ValidMovie()
     self.__movie_repository = Repository()
     self.__rental_repository = Repository
     self.__movie_service = ServiceMovies(self.__movie_repository,
                                          self.__movie_validator,
                                          undo_stack, redo_stack,
                                          self.__rental_repository)
     self.__movie_service.add_movie(1, 'Harry Potter', 'Witchcraft',
                                    'Adventure')
     with self.assertRaises(RepositoryError):
         self.__movie_service.update_movie(2, '', '', '')
Ejemplo n.º 6
0
 def test_ServiceUpdate_movieWith1emptyField_thatFieldIsUnchanged(self):
     undo_stack = Stack()
     redo_stack = Stack()
     self.__movie_validator = ValidMovie()
     self.__movie_repository = Repository()
     self.__rental_repository = Repository
     self.__movie_service = ServiceMovies(self.__movie_repository,
                                          self.__movie_validator,
                                          undo_stack, redo_stack,
                                          self.__rental_repository)
     self.__movie_service.add_movie(1, 'Harry Potter', 'Witchcraft',
                                    'Adventure')
     self.__movie_service.update_movie(1, '', '-', '-')
     expected = Movie(1, 'Harry Potter', '-', '-')
     self.assertTrue(
         self.__movie_service.get_movies()[0].identical(expected))
Ejemplo n.º 7
0
 def test_ServiceUpdate_movieWithAllFields_allFieldsUpdated(self):
     undo_stack = Stack()
     redo_stack = Stack()
     self.__movie_validator = ValidMovie()
     self.__movie_repository = Repository()
     self.__rental_repository = Repository
     self.__movie_service = ServiceMovies(self.__movie_repository,
                                          self.__movie_validator,
                                          undo_stack, redo_stack,
                                          self.__rental_repository)
     self.__movie_service.add_movie(1, 'Harry Potter', 'Witchcraft',
                                    'Adventure')
     self.__movie_service.update_movie(1, 'Harry Potter 2', 'Wizardry',
                                       'Action')
     expected = Movie(1, 'Harry Potter 2', 'Wizardry', 'Action')
     self.assertTrue(
         self.__movie_service.get_movies()[0].identical(expected))
Ejemplo n.º 8
0
 def test_ServiceAdd_validMovie_isAdded(self):
     undo_stack = Stack()
     redo_stack = Stack()
     self.__movie_validator = ValidMovie()
     self.__movie_repository = Repository()
     self.__rental_repository = Repository
     self.__movie_service = ServiceMovies(self.__movie_repository,
                                          self.__movie_validator,
                                          undo_stack, redo_stack,
                                          self.__rental_repository)
     self.__valid_movie = Movie(1, 'Frozen',
                                'Ice queen with magical powers',
                                'Animation')
     self.__movie_service.add_movie(1, 'Frozen',
                                    'Ice queen with magical powers',
                                    'Animation')
     self.assertEqual(
         self.__movie_service.get_movies()[
             self.__movie_service.get_number() - 1], self.__valid_movie)
Ejemplo n.º 9
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'))
Ejemplo n.º 10
0
 def test_validate_invalidMovie_throwsException(self):
     validator = ValidMovie()
     self.__invalid_movie = Movie(-2, '', '-', 'Drama')
     with self.assertRaises(ValidationError):
         validator.validate_movie(self.__invalid_movie)
Ejemplo n.º 11
0
 def test_validate_invalidTitle_throwsException(self):
     validator = ValidMovie()
     self.__movie_invalidTitle = Movie(1, '', 'No description', 'Horror')
     with self.assertRaises(ValidationError):
         validator.validate_movie(self.__movie_invalidTitle)
Ejemplo n.º 12
0
 def test_validate_invalidID_throwsException(self):
     validator = ValidMovie()
     self.__movie_invalidID = Movie(-2, 'Lion King', 'Hamlet for kids',
                                    'Animation')
     with self.assertRaises(ValidationError):
         validator.validate_movie(self.__movie_invalidID)
Ejemplo n.º 13
0
 def test_validate_validMovie_None(self):
     self.__valid_movie = Movie(1, 'a', 'a', 'a')
     validator = ValidMovie()
     validator.validate_movie(self.__valid_movie)
Ejemplo n.º 14
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))
Ejemplo n.º 15
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,