示例#1
0
class TestClient(unittest.TestCase):
    
    def setUp(self):
        self.__ID = 13
        self.__firstName = "Silviu"
        self.__lastName = "Anton"
        self.__CNP = 1990722170051
        self.__client = Client(self.__ID, self.__firstName, self.__lastName, self.__CNP)
        self.__validator = ClientValidator()
        self.__badID = 5
        self.__badFirstName = ""
        self.__badLastName = ""
        self.__badCNP = 12654
        self.__badClient = Client(self.__badID, self.__badFirstName, self.__badLastName, self.__badCNP)
        self.__repo = FileRepository("testClient.txt", Client)
        self.__service = ClientService(self.__repo, self.__validator)
        
    def testEntity(self):
        self.assertEqual(self.__client.getID(), self.__ID)
        
    def testValidator(self):
        
        self.__validator.validate(self.__client)
            
        self.assertRaises(ValidError, self.__validator.validate, self.__badClient)
        
    def testRepository(self):
        self.assertEqual(self.__repo.size(), 0) 
        self.__repo.store(self.__client)
        self.assertEqual(self.__repo.size(), 1) 
        
        self.assertRaises(DuplicateError, self.__repo.store, self.__client)
        
        self.assertEqual(len(self.__repo.get_all()), 1)
        
        self.assertEqual(self.__repo.size(), 1)
           
        self.__repo.delete(self.__ID)
        self.assertEqual(self.__repo.size(), 0)
        
        self.__repo.clearFile()
        
    def testService(self):
        self.__service.add_client("Silviu", "Anton", 1990722170051)
        self.assertEqual(len(self.__service.get_all()), 1)
        
        self.__service.modify_client(1, "Constantin", "Anton", 1990722170052)
        self.assertEqual(self.__service.findByID(1).getCNP(), 1990722170052)
    
        self.__service.modify_client_name(1, "Anton", "Constantin")
        self.assertEqual(self.__service.findByID(1).getName(), "Anton Constantin")
        
        self.__service.generate_clients(4)
        self.assertEqual(self.__service.number_of_clients(), 5)
        
        self.__repo.clearFile()
        
        self.assertEqual(self.__service.number_of_clients(), 0)       
示例#2
0
 def setUp(self):
     self.__ID = 13
     self.__firstName = "Silviu"
     self.__lastName = "Anton"
     self.__CNP = 1990722170051
     self.__client = Client(self.__ID, self.__firstName, self.__lastName, self.__CNP)
     self.__validator = ClientValidator()
     self.__badID = 5
     self.__badFirstName = ""
     self.__badLastName = ""
     self.__badCNP = 12654
     self.__badClient = Client(self.__badID, self.__badFirstName, self.__badLastName, self.__badCNP)
     self.__repo = FileRepository("testClient.txt", Client)
     self.__service = ClientService(self.__repo, self.__validator)
示例#3
0
def test_add_client_serv():
    cl_val = ClientValidator()
    cl_repo = ClientRepository(cl_val)
    cl_serv = ClientService(cl_repo)
    cl_serv.add_cl_srv(1, "Geo", "Valcea")
    assert len(cl_repo.get_all_clients()) == 1
    assert cl_repo.get_all_clients()[0].get_cl_name() == "Geo"
示例#4
0
 def setUp(self):
     self._client_validator = ClientValidator()
     self._client_repository = Repository({})
     self._client_service = ClientService(self._client_repository, self._client_validator)
     self._client_service.add_client('1', 'King Arthur')
     self._client_service.add_client('2', 'Im Somebody')
     self._client_service.add_client('3', 'Some random dude')
     try:
         self._client_service.add_client('4', '43')
     except ClientValidatorException:
         pass
示例#5
0
def test_find_client():
    cl1 = Client(1, "Badita", "Olanu")
    cl2 = Client(2, "Alexandru", "Georgia")
    cl_val = ClientValidator()
    repo = ClientRepository(cl_val)
    repo.store_client(cl1)
    assert len(repo.get_all_clients()) == 1
    repo.store_client(cl2)
    assert len(repo.get_all_clients()) == 2
    assert repo.find_client(1) == cl1
    assert repo.find_client(2) == cl2
    assert repo.find_client(3) is None
示例#6
0
 def setUp(self):
     self.__ID = 13
     self.__client = Client(1, "Silviu", "Anton", 1990722170051)
     self.__movie = Movie(1, "Saw", "a movie about a psycho", "Horror")
     self.__date = date.today()
     self.__rent = Rent(self.__ID, self.__client, self.__movie, self.__date)
     self.__validator = RentValidator()
     self.__repo = RentFileRepository("testRent.txt")
     self.__movieRepo = FileRepository("testMovie.txt", Movie)
     self.__clientRepo = FileRepository("testClient.txt", Client)
     self.__service = RentService(self.__repo, self.__validator, self.__clientRepo, self.__movieRepo)
     self.__clientService = ClientService(self.__clientRepo, ClientValidator())
     self.__movieService = MovieService(self.__movieRepo, MovieValidator())
示例#7
0
    def setUp(self):
        self._book_validator = BookValidator()
        self._book_repository = Repository({})
        self._book_service = BookService(self._book_repository, self._book_validator)
        self._client_validator = ClientValidator()
        self._client_repository = Repository({})
        self._client_service = ClientService(self._client_repository, self._client_validator)
        self._rental_validator = RentalValidator()
        self._rental_repository = Repository({})
        self._rental_service = RentalService(self._rental_repository, self._rental_validator, self._book_repository,self._client_repository)

        self._book_service.add_book('1', 'The Book', 'King Arthur')
        self._book_service.add_book('2', 'The Prize', 'Im Somebody')
        self._book_service.add_book('3', 'Im Out Of Ideeas', 'Some random dude')

        self._client_service.add_client('1', 'Raiu Madalin')
        self._client_service.add_client('2', 'Ristei Elena')
        self._client_service.add_client('3', 'Another random dude')

        self._rental_service.add_rental('1', '2', '3', '10/10/2019')
        self._rental_service.add_rental('2', '1', '2', '02/03/2019')
        try:
            self._rental_service.add_rental('2', '1', '2', '02/03/2019')
        except RentalValidatorException as ve:
            pass
        except RepositoryException:
            pass
        self._rental_service.set_return_date('2', '02/03/2020')
        self._rental_service.add_rental('3', '1', '3', '02/03/2019')
        try:
            self._rental_service.add_rental('4', '3', '1223', '02/03/2019')
        except RentalValidatorException:
            pass
        try:
            self._rental_service.add_rental('134', '444', '1223', '02/03/2019')

        except RentalValidatorException:
            pass
        try:
            self._rental_service.add_rental('134', '3', '2', '02/03/2019')
            self._rental_service.add_rental('134', '3', '2', '02/03/2019')
        except RentalValidatorException:
            pass
        except RepositoryException:
            pass

        try:
            self._rental_service.add_rental('134', '3', '2', '0d/s3/2019')

        except RentalValidatorException:
            pass
示例#8
0
def test_store_client():
    cl1 = Client(1, "Badita", "Olanu")
    cl2 = Client(2, "Alexandru", "Georgia")
    cl3 = Client(1, "Istvan", "Algeria")
    cl_val = ClientValidator()
    repo = ClientRepository(cl_val)
    repo.store_client(cl1)
    assert len(repo.get_all_clients()) == 1
    repo.store_client(cl2)
    assert len(repo.get_all_clients()) == 2

    try:
        repo.store_client(cl3)
        assert False
    except RepositoryException:
        assert True
示例#9
0
 def setUp(self):
     """
     Prepare tests
     """
     self.rental_repository = Repository({})
     self.validator2 = RentalValidator()
     self.book_repository = Repository({})
     self.validator = BookValidator()
     self.client_repository = Repository({})
     self.validatorc = ClientValidator()
     self.undo_service = UndoService()
     self.redo_service = RedoService()
     self.book_service = BookService(self.book_repository, self.validator)
     self.client_service = ClientService(self.client_repository, self.validatorc)
     self.rental_service = RentalService(self.rental_repository, self.validator2, self.book_repository,
                                         self.client_repository)
示例#10
0
def test_cleint_validator():
    cl = Client("", "", "")
    cl_val = ClientValidator()
    try:
        cl_val.validate(cl)
        assert False
    except ValidatorException as errs:
        assert len(errs.get_errs()) == 3
    cl = Client(1, "", "")
    try:
        cl_val.validate(cl)
        assert False
    except ValidatorException as errs:
        assert len(errs.get_errs()) == 2

    cl = Client(1, "Badita", "Valcea")
    try:
        cl_val.validate(cl)
        assert True
    except ValidatorException:
        assert False
示例#11
0
    def test_create_client(self):
        c1 = Client(1, "Popescu Alin")
        self.assertEqual(c1.id, 1)
        self.assertEqual(c1.name, "Popescu Alin")

        c1.id = 2
        c1.name = "Ana"
        self.assertEqual(c1.id, 2)
        self.assertEqual(c1.name, "Ana")

        the_id = -2
        name = "Maria"
        with self.assertRaises(ValueError):
            Cv.validate_id(the_id)
            Cv.validate_name(name)

        the_id2 = 2
        name2 = "A"
        with self.assertRaises(ValueError):
            Cv.validate_id(the_id2)
            Cv.validate_name(name2)
示例#12
0
from domain.validators import ClientValidator, CarValidator, RentalValidator
from repository.car_file_repo import CarFileRepository
from repository.car_repository import CarRepository
from repository.client_file_repo import ClientFileRepository
from repository.client_repository import ClientRepository
from repository.rental_repository import RentalRepository
from services.car_service import CarService
from services.client_service import ClientService
from services.rental_service import RentalService
from ui.user_interface import UI

'''
The module where our application will start
'''

cl_val = ClientValidator()
car_val = CarValidator()
rt_val = RentalValidator()

#cl_rep = ClientRepository(cl_val)
cl_rep_file = ClientFileRepository("clients.txt")
#car_rep = CarRepository(car_val)
car_rep_file = CarFileRepository("cars.txt")
car_rep_file.remove_all()
rt_rep = RentalRepository(rt_val)


cl_serv = ClientService(cl_rep_file)
car_serv = CarService(car_rep_file)
rt_serv = RentalService(rt_rep, cl_rep_file, car_rep_file)
示例#13
0
'''
Created on Nov 6, 2018

Modulul principal al aplicatiei

@author: Silviu Anton
'''
from services.client_service import ClientService
from services.movie_service import MovieService
from infrastructure.repository import FileRepository, RentFileRepository
from domain.validators import ClientValidator, MovieValidator, RentValidator
from ui.console import Console
from services.rent_service import RentService
from domain.entities import Client, Movie

if __name__ == '__main__':

    clientRepository = FileRepository('clienti.txt', Client)
    clientService = ClientService(clientRepository, ClientValidator())

    movieRepository = FileRepository('filme.txt', Movie)
    movieService = MovieService(movieRepository, MovieValidator())

    rentRepository = RentFileRepository('inchirieri.txt')
    rentService = RentService(rentRepository, RentValidator(),
                              clientRepository, movieRepository)

    console = Console(clientService, movieService, rentService)

    console.run()
示例#14
0
from Repositories.repository import Repository
from domain.validators import BookValidator, ClientValidator, RentalValidator
from services.BookService import BookService
from services.ClientService import ClientService
from services.RentalService import RentalService
from settings.settings import Settings

from ui.console import Console

if __name__ == '__main__':
    settings = Settings("../settings.properties")
    config = settings.get_the_settings()
    try:
        if config[0] == "inmemory":
            book_validator = BookValidator()
            client_validator = ClientValidator()
            rental_validator = RentalValidator()

            book_repository = Repository({})
            client_repository = Repository({})
            rental_repository = Repository({})

            book_service = BookService(book_repository, book_validator)
            client_service = ClientService(client_repository, client_validator)
            rental_service = RentalService(rental_repository, rental_validator, book_repository, client_repository)

            console = Console(book_service, client_service, rental_service)
            console.run_console()
        elif config[0] == "filerepository":
            book_validator = BookValidator()
            client_validator = ClientValidator()