예제 #1
0
 def test_search_book_title(self):
     repoBooks = RepositoryBooks("Repobooks:")
     repoBooks.add(Book(1, "Title1", "Title2"))
     repoBooks.add(Book(12, "Title121", "Title122"))
     
     assert(len(repoBooks.searchBookTitle("tLe")) == 2)
     self.assertRaises(RepositoryError, lambda : repoBooks.searchBookTitle("zz"))
예제 #2
0
 def test_rental_remove_book(self):
     repoRental = RepositoryRentals("Reporentals:")
     repoRental.add(Rental(1, Book(1, "Title1", "Author1"), Client(1, "Name1"), datetime.date(2019, 10, 5), None))
     repoRental.add(Rental(2, Book(2, "Title2", "Author2"), Client(2, "Name2"), datetime.date(2019, 10, 6), None))
     
     repoRental.remove_book(2)
     assert(repoRental.size() == 1)
예제 #3
0
 def test_search_book_author(self):
     repoBooks = RepositoryBooks("Repobooks:")
     repoBooks.add(Book(1, "Title1", "Title2"))
     repoBooks.add(Book(12, "Title121", "Title122"))
     
     assert(len(repoBooks.searchBookAuthor("iTl")) == 2)
     self.assertRaises(RepositoryError, lambda : repoBooks.searchBookAuthor("aa"))
예제 #4
0
 def test_search_unique(self):
     repoRental = RepositoryRentals("Reporentals:")
     repoRental.add(Rental(1, Book(1, "Title1", "Author1"), Client(1, "Name1"), datetime.date(2019, 10, 5), None))
     repoRental.add(Rental(2, Book(2, "Title2", "Author2"), Client(2, "Name2"), datetime.date(2019, 10, 6), None))
     
     self.assertRaises(RepositoryError, lambda : repoRental.search_unique(Rental(1, Book(2, "Title1", "Author1"), Client(1, "Name1"), datetime.date(2019, 10, 5), None)))
     self.assertRaises(RepositoryError, lambda : repoRental.search_unique(Rental(12, Book(1, "Title1", "Author1"), Client(1, "Name1"), datetime.date(2019, 10, 5), None)))
예제 #5
0
def initialBookList(repoBook):
    b1 = Book(100, "2666", "psyhoogy", "Roberto Bolaño")
    b2 = Book(101, "All About Love", "love", "Bell Hooks")
    b3 = Book(102, "Desert Solitaire", "action", "Desert Solitaire")
    b4 = Book(103, "Geek Love", "drama", "Katherine Dunn")
    b5 = Book(104, "If on a Winter's Night a Traveler", "action",
              "Italo Calvino")
    b6 = Book(105, "The Left Hand of Darkness", "adventure",
              "Ursula K. Le Guin")
    b7 = Book(106, "To Kill a Mockingbird", "action/police", "Harper Lee")
    b8 = Book(107, "Half of a Yellow Sun", "phylosophy",
              "Chimamanda Ngozi Adichie")
    b9 = Book(108, "Invisible Cities", "history", "Italo Calvino")
    b10 = Book(109, "Hopscotch", "drama", "Julio Cortázar")

    repoBook.addBook(b1)
    repoBook.addBook(b2)
    repoBook.addBook(b3)
    repoBook.addBook(b4)
    repoBook.addBook(b5)
    repoBook.addBook(b6)
    repoBook.addBook(b7)
    repoBook.addBook(b8)
    repoBook.addBook(b9)
    repoBook.addBook(b10)
예제 #6
0
    def initialisebooks(self):
        b = Book('ion', 'liviu rebreanu')
        self._books.append(b)
        b = Book('ion', 'aaa')
        self._books.append(b)

        b = Book('ursul', 'mihail sadoveanu')
        self._books.append(b)

        b = Book('Amintiri din copilarie', 'Ion Creanga')
        self._books.append(b)

        b = Book('Colt Alb', 'Jack P.')
        self._books.append(b)

        b = Book('Colt Alb', 'Jack P.')
        self._books.append(b)

        b = Book('Carte de bucate', 'Cristina Stamate')
        self._books.append(b)

        b = Book('Another one', 'unknown')
        self._books.append(b)

        b = Book('Tinkerbell', 'Peter Pan')
        self._books.append(b)

        b = Book('Lala', 'ding-dong')
        self._books.append(b)
예제 #7
0
 def test_get_all_authors(self):
     repoBooks = RepositoryBooks("Repobooks:")
     repoBooks.add(Book(1, "Title1", "Title2"))
     repoBooks.add(Book(2, "Title1", "Title2"))
     repoBooks.add(Book(12, "Title121", "Title122"))
     
     assert(len(repoBooks.get_all_authors()) == 2)
예제 #8
0
 def test_search_book(self):
     repoBooks = Repo("Repobooks:")
     repoBooks.add(Book(1, "Title11", "Title12"))
     repoBooks.add(Book(2, "Title21", "Title22"))
     
     self.assertRaises(RepositoryError, lambda:repoBooks.search(Book(4, None, None)))
     b = repoBooks.search(Book(1, None, None))
     assert(b.bookTitle == "Title11")
     assert(b.bookAuthor == "Title12")
예제 #9
0
 def test_update_book(self):
     repoBooks = Repo("Repobooks:")
     repoBooks.add(Book(1, "The Secret Crusade", "Oliver Bowden"))
     repoBooks.add(Book(2, "The Illustrated Man", "Ray Bradbury"))
     
     repoBooks.update(Book(1, "New", "New2"))
     assert(repoBooks.get_all()[0].bookTitle == "New")
     assert(repoBooks.get_all()[0].bookAuthor == "New2")
     
     self.assertRaises(RepositoryError, lambda : repoBooks.update(Book(20, None, None)))
예제 #10
0
 def test_validate_book(self):
     validatorBooks = ValidateBook()
     b = Book(-50, "One", "Author")
     self.assertRaises(ValidationError, lambda:validatorBooks.validate_book(b))
     
     b = Book(50, "", "Author")
     self.assertRaises(ValidationError, lambda:validatorBooks.validate_book(b))
     
     b = Book(50, "One", "")
     self.assertRaises(ValidationError, lambda:validatorBooks.validate_book(b))
예제 #11
0
def test_addBook():
    book1 = Book('0xffffff', 'The Cat', 'Meow')
    s = Service()
    try:
        s.addBook(book1)
        assert False
    except ValueError:
        assert True
    book2 = Book('1', 'The Dog', 'Meow')
    s.addBook(book2)
    assert len(s.Library) == 12
예제 #12
0
 def test_remove_book(self):
     repoBooks = Repo("Repobooks:")
     repoBooks.add(Book(1, "The Secret Crusade", "Oliver Bowden"))
     repoBooks.add(Book(2, "The Illustrated Man", "Ray Bradbury"))
     
     repoBooks.remove(Book(1, None, None))
     assert(repoBooks.size() == 1)
     assert(repoBooks.get_all()[0].bookID == 2)
     
     with self.assertRaises(RepositoryError) as context:
         repoBooks.remove(Book(22, None, None))
     self.assertTrue("\n[REPOSITORY ERROR] -> Repobooks: Inexistend ID!\n" in str(context.exception))
예제 #13
0
 def test_most_clients(self):
     repoClients = RepositoryClients("Repoclients:")
     repoRental = RepositoryRentals("Reporentals:")
     
     repoClients.add(Client(1, "Name1"))
     repoClients.add(Client(2, "Name2"))
     repoRental.add(Rental(1, Book(1, "Title1", "Author1"), Client(1, "Name1"), datetime.date(2019, 10, 5), None))
     repoRental.add(Rental(2, Book(2, "Title2", "Author2"), Client(2, "Name2"), datetime.date(2019, 10, 6), datetime.date(2019, 10, 15)))
     
     c = repoClients.get_all()
     clist = repoRental.most_clients(c)
     assert(len(c) == len(clist))
예제 #14
0
 def test_most_authors(self):
     repoBooks = RepositoryBooks("Repobooks:")
     repoRental = RepositoryRentals("Reporentals:")
     
     repoBooks.add(Book(1, "Title1", "Author1"))
     repoBooks.add(Book(2, "Title2", "Author2"))
     repoRental.add(Rental(1, Book(1, "Title1", "Author1"), Client(1, "Name1"), datetime.date(2019, 10, 5), None))
     repoRental.add(Rental(2, Book(2, "Title2", "Author2"), Client(2, "Name2"), datetime.date(2019, 10, 6), None))
     
     a = repoBooks.get_all_authors()
     alist = repoRental.most_authors(a)
     assert(len(a) == len(alist))
예제 #15
0
 def __init__(self):
     self._books = []
     self._history = []
     self.addBook(Book("100", "Mircea Eliade", "Nunta in cer"))
     self.addBook(
         Book("101", "Gabriel García Márquez", "Un veac de singuratate"))
     self.addBook(Book("102", "Alexandre Dumas", "Dama cu camelii"))
     self.addBook(Book("103", "James Clavell", "Shogun"))
     self.addBook(Book("104", "Lesley Downer", "Puntea viselor"))
     self.addBook(Book("105", "Karl May", "Winnetou"))
     self.addBook(Book("106", "Emil cioran", "Tratat de descompunere"))
     self.addBook(
         Book("107", "Gabriel Liiceanu", "Nebunia de a gandi cu mintea ta"))
     self.addBook(Book("108", "Mircea Eliade", "Noaptea de sanziene"))
     self.addBook(Book("109", "Paulo Coelho", "Jurnalul unui mag"))
    def _loadFile(self):
        '''
        loads the repo file
        '''
        try:

            f = open(self._filename, "r")

            line = f.readline()
            while len(line) > 2:
                tok = line.split(",")
                date = datetime.strptime(tok[3], '%Y-%m-%d %H:%M:%S')
                '''
                yeah, month, day = map(int, tok[3].split("-"))
                date = datetime.date(yeah, month, day)
                '''
                book = Book(int(tok[1]), "", "", "")
                client = Client(int(tok[0]), "")
                ret = tok[4].strip()
                RentalRepository.rent_book(self, client, book, date)
                if str(ret) != "None":
                    '''
                    yeah, month, day = map(int, ret.split("/"))
                    date = datetime.date(yeah, month, day)
                    '''
                    date = datetime.strptime(ret, '%Y-%m-%d %H:%M:%S')
                    RentalRepository.return_book(self, client, book, date)
                line = f.readline()
        except IOError:
            raise Exception("Invalid file... :(")
        finally:
            f.close()
예제 #17
0
 def test_validate_rental(self):
     validatorRental = ValidateRental()
     with self.assertRaises(ValidationError) as context:
         validatorRental.validate_rental(Rental(-2, Book(2, "Title2", "Author2"), Client(2, "Name2"), datetime.date(2019, 10, 6), datetime.date(2018, 10, 5)))
     self.assertTrue("\n[VALIDATION ERROR] -> Invalid Rental ID! Invalid returned Date!" in str(context.exception))
 
     self.assertRaises(ValidationError, lambda : validatorRental.validate_rental(Rental(-2, Book(2, "Title2", "Author2"), Client(2, "Name2"), datetime.date(2019, 10, 6), datetime.date(2018, 10, 5))))
예제 #18
0
 def addBook(self):
     isbn = input('ISBN: ')
     author = input('Author: ')
     title = input('Title: ')
     self._history.append(self._service.Library[:])
     newBook = Book(isbn, author, title)
     self._service.addBook(newBook)
예제 #19
0
def test_book_repo():
    book1 = Book(0, "Persona 3", "3rd entry in the series", "Shuji Sogabe")
    book2 = Book(1, "Persona 5", "5th entry in the series", "Atlus")

    repo = BookRepository()
    repo.add(book1)
    listBooks = repo.getAll()

    assert len(listBooks) == 1
    assert listBooks[0].get_title() == "Persona 3"
    assert listBooks[0].get_author() == "Shuji Sogabe"
    assert listBooks[0].get_desc() == "3rd entry in the series"
    assert listBooks[0].get_id() == 0
    repo.add(book2)

    repo.remove(book1)
    listBooks = repo.getAll()
    assert len(listBooks) == 1
    assert listBooks[0].get_title() == "Persona 5"
    assert listBooks[0].get_author() == "Atlus"
    assert listBooks[0].get_desc() == "5th entry in the series"
    assert listBooks[0].get_id() == 1
    try:
        repo.remove(Book(34, "til", "de", "dw"))
        assert True
    except IndexError:
        pass
    except ValueError:
        pass

    assert repo.find(book1) == False
    assert repo.find(book2) == True

    repo.update(
        Book(1, "P3", "third entry in the series, manga", "Shuji Sogabe"))
    listBooks = repo.getAll()

    assert listBooks[0].get_title() == "P3"
    assert listBooks[0].get_author() == "Shuji Sogabe"
    assert listBooks[0].get_desc() == "third entry in the series, manga"
    assert listBooks[0].get_id() == 1
    try:
        repo.update(book1)
        assert False
    except IndexError:
        pass
예제 #20
0
    def test_add_book(self):
        repoBooks = Repo("Repobooks:")
        repoBooks.add(Book(1, "The Secret Crusade", "Oliver Bowden"))
        repoBooks.add(Book(2, "The Illustrated Man", "Ray Bradbury"))

        self.assertRaises(RepositoryError, lambda:repoBooks.add(Book(1, None, None)))
        
        assert(repoBooks.size() == 2)
        
        assert(repoBooks.get_all()[0].bookID == 1)
        assert(repoBooks.get_all()[1].bookID == 2)
        
        assert(repoBooks.get_all()[0].bookTitle == "The Secret Crusade")
        assert(repoBooks.get_all()[1].bookTitle == "The Illustrated Man")
        
        assert(repoBooks.get_all()[0].bookAuthor == "Oliver Bowden")
        assert(repoBooks.get_all()[1].bookAuthor == "Ray Bradbury")
 def generateBooks(self, dimension, idBasis, authorsNr):
     result = []
     authors = random.sample(self.generateNames(), authorsNr)
     for i in range(dimension):
         b = Book(idBasis + i, self.generateTitle(), random.choice(authors),
                  self.generateDescription())
         result.append(b)
     return result
예제 #22
0
 def add_book(self, name, author):
     '''
     adds a new book to the list ok books
     :param name: name of book
     :param author: author of book
     :return: nothing, appends to the list
     '''
     b = Book(name, author)
     self._books.append(b)
예제 #23
0
 def add_book(self, bookId, bookName, bookAuthor, u):
     #adds a new book to the list of books
     #bookId = (str) the book ID, bookName = (str) the name of the book, bookAuthor = (str) the Author of the book
     book = Book(bookId, bookName, bookAuthor)
     self._validator.validate_book(book)
     self._booksList.add(book)
     if u == True:
         UndoManager.register_operation(self, UndoHandler.ADD_BOOK,
                                        int(bookId), bookName, bookAuthor)
예제 #24
0
 def read_data(self):
     #reads all the data from the sql table
     self._entities = DynamicArray()
     cmd = 'SELECT * FROM ' + self._table_name
     self._cursor.execute(cmd)
     line = self._cursor.fetchone()
     while line is not None:
         obj = Book(int(line[0]), line[1], line[2])
         self._entities.append(obj)
         line = self._cursor.fetchone()
예제 #25
0
    def test_create_book(self):
        bookId = 20
        bookTitle = "Here I am"
        bookAuthor = "John Smith"
        b = Book(bookId, bookTitle, bookAuthor)
        

        assert(b.bookID == 20)
        assert(b.bookTitle == "Here I am")
        assert(b.bookAuthor == "John Smith")
        
        b.bookTitle = "New Title"
        assert(b.bookTitle == "New Title")
        
        b.bookAuthor = "New Author"
        assert(b.bookAuthor == "New Author")
        
        b2 = Book(20, "2nd Title", "2nd Author")
        assert(b == b2)
def test_repo():
    client1 = Client(1, "Scott Fitzgerald")
    book1 = Book(1, "Persona 3", "3rd entry in the series", "Shuji Sogabe")
    book2 = Book(2, "Persona 5", "5th entry in the series", "Atlus")

    repo = RentalRepository()

    repo.rent_book(client1, book1, datetime(2018, 11, 3))
    listRent = repo.getAll()

    assert len(listRent) == 1
    assert listRent[0].get_clientID() == 1
    assert listRent[0].get_bookID() == 1
    assert listRent[0].get_rentalID() == 0
    assert str(listRent[0].get_rented_date()) == "2018-11-03 00:00:00"
    assert str(listRent[0].get_due_date()) == "2018-11-17 00:00:00"
    assert str(listRent[0].get_return_date()) == "None"

    repo.return_book(client1, book1, datetime(2018, 11, 10))
    listRent = repo.getAll()
예제 #27
0
 def search(self, keyobj):
     #returns an object with a specific key (keyobj) from the repo
     #raises a RepositoryError if the id is not in the repo
     #print(str(keyobj.bookID))
     cmd = "SELECT * FROM " + self._table_name + " WHERE Id=" + str(
         keyobj.bookID) + ";"
     self._cursor.execute(cmd)
     line = self._cursor.fetchone()
     if line is None:
         raise RepositoryError(self._name + " Inexistent ID!\n")
     return Book(int(line[0]), line[1], line[2])
예제 #28
0
 def remove_book(self, bookId, u):
     #removes a book from the list of books
     #bookId = (str) the book ID which has to be removed
     book = Book(int(bookId), None, None)
     book = self._booksList.search(book)
     self._booksList.remove(book)
     #self._repoRental.remove_book(int(bookId))
     blist = self._repoRental.remove_book(int(bookId))
     if u == True:
         UndoManager.register_operation(self, UndoHandler.REMOVE_BOOK,
                                        int(bookId), book.bookTitle,
                                        book.bookAuthor, blist)
예제 #29
0
 def read_data(self):
     #reads all the data from the sql table
     self._entities = []
     cmd = 'SELECT * FROM ' + self._table_name
     self._cursor.execute(cmd)
     line = self._cursor.fetchone()
     while line is not None:
         if line[4] is not None:
             obj = Rental(
                 int(line[0]), Book(int(line[1]), None, None),
                 Client(int(line[2]), None),
                 datetime.datetime.strptime(line[3], '%Y-%m-%d').date(),
                 datetime.datetime.strptime(line[4], '%Y-%m-%d').date())
         else:
             obj = Rental(
                 int(line[0]), Book(int(line[1]), None, None),
                 Client(int(line[2]), None),
                 datetime.datetime.strptime(line[3], '%Y-%m-%d').date(),
                 None)
         self._entities.append(obj)
         line = self._cursor.fetchone()
예제 #30
0
 def initFromMemory(self):
     self.listOfBooks.extend([
         Book("1", "B", "E"),
         Book("2", "E", "x"),
         Book("5", "po", "k"),
         Book("4", "T", "J"),
         Book("3", "z", "E"),
         Book("7", "Iz", "Pzz")
     ])
     self.listOfClients.extend([
         Client("1", "jo"),
         Client("2", "Richy"),
         Client("3", "Iu"),
         Client("4", "Jaz"),
         Client("5", "Qwe")
     ])
     self.listOfRentedBooks.extend([
         Rental("1", "1", "1", datetime.datetime(2012, 12, 5),
                datetime.datetime(2012, 12, 10)),
         Rental("2", "1", "4", datetime.datetime(2012, 12, 22),
                datetime.datetime(2013, 1, 22)),
         Rental("3", "1", "2", datetime.datetime(2012, 12, 29),
                datetime.datetime(2013, 12, 10)),
         Rental("3", "2", "5", datetime.datetime(2010, 9, 20),
                datetime.datetime(2011, 1, 1))
     ])
     self.mostRentedBooks = {}
     self.mostRentedAuthor = {}
     self.mostActiveClients = {}