예제 #1
0
    def clientsInitialize(self):
        clientRepo = Repository()
        firstName = [
            "Bogdan", "Andrei", "Cristi", "Patrick", "Gabriel", "Laura",
            "Alexandra", "Andreea", "Robert", "Claudiu", "Mirel", "Carmen",
            "Darius", "Robert", "Macanache"
        ]
        secondName = [
            "Suciu", "Petru", "Andras", "Pop", "Cosmulei", "Micu", "Crivei",
            "Bota", "Botis", "Stejerean", "Vincze", "Somotecan", "Salvia"
        ]

        i = 0
        while i <= 100:
            clientRepo.add(
                Client((i * 4 + i % 3 + 1) // 2 + 1,
                       random.choice(firstName) + " " +
                       random.choice(secondName)))
            i += 1

        i = 0
        while i < len(clientRepo._list):
            # print(clientRepo._list[i])
            i += 1

        return clientRepo
예제 #2
0
    def moviesInitialize(self):
        movieRepo = Repository()
        movieTitles = [
            "The Godfather", "The Shawshank Redemption", "Schindler's List",
            "Raging Bull", "Casablanca", "Citizen Kane", "Gone with the Wind",
            "The Wizard of Oz ", "One Flew Over the Cuckoo's Nest"
        ]
        descriptionList = [
            "Sure! Why not?", "Yea boi", "Best movie.",
            "Don't watch it with your mother", "18+", "1/10",
            "Do not recommend", "5/10", "Cry by yourself"
        ]
        genreMovies = ["Drama", "Comedy", "Horror", "Action", "SF"]

        i = 0
        while i <= 100:
            movieRepo.add(
                Movie(
                    ((i * 5 + 1 + i % 2 + 3) // 2), random.choice(movieTitles),
                    random.choice(descriptionList),
                    random.choice(genreMovies)))
            #print(movieRepo._list[i])
            i += 1

        return movieRepo
예제 #3
0
 def setUp(self):
     self._book_validator = BookValidator()
     self._book_repository = Repository({})
     self._book_service = BookService(self._book_repository, self._book_validator)
     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')
     try:
         self._book_service.add_book('4', '4', '434')
     except BookValidatorException:
         pass
예제 #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 setUp(self):
     self._repo = Repository({})
     self._repo.save(Book('1', "The Dream", 'Jack Sparrow'))
     self._repo.save(Book('2', "Good Day", 'Salam de Sibiu'))
     self._repo.save(Book('3', "I have no Ideea", 'Someone'))
     self._repo.save(Book('4', "The legend", 'Guta'))
     self._repo.save(Book('5', "Unknown", 'Nicoae Balcescu'))
     self._repo.save(Book('6', "Cocalar", 'Dani Mocanu'))
     try:
         self._repo.save(Book('6', "Cocalar", 'Dani Mocanu'))
     except RepositoryException:
         pass
예제 #6
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
    def readFromFile(self):
        try:
            f = open(self._fileName, "r")
            line = f.readline()

            while len(line) > 0:
                parts = line.split(";")
                client = Client(int(parts[0]), parts[1])
                Repository.add(self, client)
                line = f.readline()

            f.close()
        except:
            pass
예제 #8
0
class TestBookService(unittest.TestCase):
    def setUp(self):
        self._book_validator = BookValidator()
        self._book_repository = Repository({})
        self._book_service = BookService(self._book_repository, self._book_validator)
        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')
        try:
            self._book_service.add_book('4', '4', '434')
        except BookValidatorException:
            pass

    def test_book_add(self):
        a = self._book_repository.get_entities()
        self.assertEqual(len(a), 3)
        self.assertEqual(a['1'].title, 'The Book')
        self.assertEqual(a['1'].author, 'King Arthur')
        self.assertEqual(a['2'].title, 'The Prize')
        self.assertEqual(a['2'].author, 'Im Somebody')

    def test_book_remove(self):
        self._book_service.remove_book('1')
        a = self._book_repository.get_entities()
        self.assertEqual(len(a), 2)
        self.assertEqual(self._book_repository.find_by_id('1'), None)

    def test_search_by_id(self):
        a = self._book_service.search_book_by_id('1')
        self.assertEqual(a[0].id, '1')
        self.assertEqual(a[0].author, 'King Arthur')
        self.assertEqual(a[0].title, 'The Book')

    def test_search_by_title(self):
        a = self._book_service.search_book_by_title('The')
        self.assertEqual(a[0].id, '1')
        self.assertEqual(a[0].author, 'King Arthur')
        self.assertEqual(a[0].title, 'The Book')
        self.assertEqual(len(a), 2)
        self.assertEqual(a[1].id, '2')
        self.assertEqual(a[1].author, 'Im Somebody')
        self.assertEqual(a[1].title, 'The Prize')

    def test_search_by_author(self):
        a = self._book_service.search_book_by_author('King')
        self.assertEqual(a[0].id, '1')
        self.assertEqual(a[0].author, 'King Arthur')
        self.assertEqual(a[0].title, 'The Book')
예제 #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)
    def writeToFile(self):
        try:
            f = open(self._fileName, "w")
            for client in Repository.getList(self):
                f.write(str(client.id) + ";" + client.name)

            f.close()
        except:
            pass
예제 #11
0
class TestClientService(unittest.TestCase):
    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

    def test_client_add(self):
        a = self._client_repository.get_entities()

        self.assertEqual(len(a), 3)
        self.assertEqual(a['1'].name, 'King Arthur')
        self.assertEqual(a['2'].name, 'Im Somebody')
        self.assertEqual(a['3'].name, 'Some random dude')

    def test_client_remove(self):
        self._client_service.remove_client('1')
        a = self._client_repository.get_entities()
        assert len(a) == 2
        self.assertEqual(self._client_repository.find_by_id('1'), None)

    def test_search_by_id(self):
        a = self._client_service.search_client_by_id('1')
        self.assertEqual(a[0].id, '1')
        self.assertEqual(a[0].name, 'King Arthur')

    def test_search_by_name(self):
        a = self._client_service.search_client_by_name('King')
        self.assertEqual(a[0].id, '1')
        self.assertEqual(a[0].name, 'King Arthur')
        self.assertEqual(len(a), 1)
 def __init__(self, fileName):
     Repository.__init__(self)
     self._fileName = fileName
 def update(self, position, objectt):
     Repository.update(self, position, objectt)
     self.writeToFile()
 def remove(self, idClient):
     if Repository.findByAnID(self, idClient) != -1:
         x = Repository.getList(self)
         del x[idClient]
     self.writeToFile()
 def add(self, client):
     Repository.add(self, client)
     self.writeToFile()
예제 #16
0
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()
            rental_validator = RentalValidator()

            book_repository = BooksFileRepository(config[1])
예제 #17
0
class TestRentalService(unittest.TestCase):
    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

    def test_rental_add(self):
        a = self._rental_repository.get_entities()
        self.assertEqual(len(a), 4)
        self.assertEqual(a['1'].book_id, '2')
        self.assertEqual(a['1'].client_id, '3')
        self.assertEqual(a['1'].rented_date, '10/10/2019')
        self.assertEqual(a['1'].data, 'This book is not returned yet')

    def test_rental_return(self):
        a = self._rental_repository.get_entities()
        self.assertEqual(a['1'].data, 'This book is not returned yet')

        self._rental_service.set_return_date('1', '20/10/2020')
        self.assertEqual(a['1'].data, '20/10/2020')
        self.assertEqual(a['3'].data, 'This book is not returned yet')
        try:
            self._rental_service.set_return_date('1', '20/10/2020')
        except RentalValidatorException:
            pass
        try:
            self._rental_service.set_return_date('3', '01/03/2019')
        except RentalValidatorException:
            pass
        try:
            self._rental_service.set_return_date('3', '02/02/2019')

        except RentalValidatorException:
            pass
        try:
            self._rental_service.set_return_date('3', '02/03/2018')

        except RentalValidatorException:
            pass

    def test_most_rented_books(self):
        self._rental_service.set_return_date('1', '20/10/2020')
        a, b = self._rental_service.most_rented_books()
        self.assertEqual(a[0], 'The Book')
        self.assertEqual(b[0], 2)

    def test_most_rented_authors(self):
        a, b = self._rental_service.most_rented_authors()
        self.assertEqual(a[0], 'King Arthur')
        self.assertEqual(b[0], 2)
        self.assertEqual(a[1], 'Im Somebody')
        self.assertEqual(b[1], 1)

    def test_most_active_clients(self):
        self._rental_service.set_return_date('1', '20/10/2020')
        a, b = self._rental_service.most_active_clients()
        self.assertEqual(a[0], 'Another random dude')
        self.assertEqual(b[0], 376)

    def test_rental_print(self):
        a = self._rental_service.print_rentals()
        self.assertNotEqual(len(a), 0)
예제 #18
0
class TestRepo(unittest.TestCase):
    def setUp(self):
        self._repo = Repository({})
        self._repo.save(Book('1', "The Dream", 'Jack Sparrow'))
        self._repo.save(Book('2', "Good Day", 'Salam de Sibiu'))
        self._repo.save(Book('3', "I have no Ideea", 'Someone'))
        self._repo.save(Book('4', "The legend", 'Guta'))
        self._repo.save(Book('5', "Unknown", 'Nicoae Balcescu'))
        self._repo.save(Book('6', "Cocalar", 'Dani Mocanu'))
        try:
            self._repo.save(Book('6', "Cocalar", 'Dani Mocanu'))
        except RepositoryException:
            pass

    def test_repo_save(self):
        a = self._repo.get_entities()
        self.assertNotEqual(len(a), 0)
        self.assertIn('1', a)
        self.assertIn('2', a)
        self.assertIn('3', a)
        self.assertIn('4', a)
        self.assertIn('5', a)
        self.assertIn('6', a)
        self.assertIs('Jack Sparrow', a['1'].author)
        self.assertEqual(len(a), 6)

    def test_find_by(self):
        self.assertEqual(self._repo.find_by_id('12'), None)
        self.assertNotEqual(self._repo.find_by_id('1'), None)

    def test_remove(self):
        self._repo.remove('1')
        self.assertEqual(self._repo.find_by_id('1'), None)
        try:
            self._repo.remove('1')
        except RepositoryException:
            pass