コード例 #1
0
ファイル: tests.py プロジェクト: p0licat/university
def testBook():
    try:
        book1 = Book(1, "a", "b", "c")
        assert book1.getId() == 1
        assert book1.getTitle() == "a"
        assert book1.getDescription() == "b"
        assert book1.getAuthor() == "c"
    except:
        assert False
        
    try:
        book1 = Book("D", "d", "d", "d")
        print(book1)
        assert False
    except BookException:
        pass
    
    try:
        book1 = Book(1, "a", "b", "c")
        book1.setTitle(3)
        assert False
    except:
        pass
    
    print ("Book tests ran successfully!")
コード例 #2
0
 def setUp(self):
     self.client = Client(23, 'alex')
     self.client2 = Client(12, 'diana')
     self.book = Book(21, 'titlu', 'descriere', 'author')
     self.book2 = Book(22, 'titlu2', 'descriere2', 'author2')
     self.rental = Rental(21236, 21, 23, date(2017, 11, 5), date(2017, 12, 6), date(2017, 12, 5))
     self.rental2 = Rental(21236, 21, 23, date(2017, 11, 5), date(2017, 12, 6), date(2017, 12, 5))
コード例 #3
0
    def setUp(self):
        self.repo = Repository()
        self.brepo = Repository()
        self.crepo = Repository()
        self.Ucontroller = UndoController()
        self.book = Book(21, 'titlu', 'descriere', 'author')
        self.book2 = Book(22, 'titlu2', 'descriere2', 'author')
        self.brepo.add(self.book)
        self.brepo.add(self.book2)
        self.client = Client(23, 'alex')
        self.client2 = Client(24, 'ana')
        self.client3 = Client(29, 'ana')

        self.crepo.add(self.client)
        self.crepo.add(self.client2)
        self.rental = Rental(21236, 21, 24, date(2017, 11, 5),
                             date(2017, 12, 6), date(2017, 12, 5))
        self.rental2 = Rental(21238, 22, 24, date(2017, 11, 5),
                              date(2017, 12, 6), date(2017, 12, 5))
        self.rental3 = Rental(21238, 23, 24, date(2017, 11, 5),
                              date(2017, 12, 6), date(2017, 12, 5))
        self.rental4 = Rental(21238, 21, 29, date(2017, 11, 5),
                              date(2017, 12, 6), date(2017, 12, 5))
        self.rental5 = Rental(21231, 21, 23, date(2017, 11, 5),
                              date(2017, 10, 6), None)

        self.controller = RentalController(self.repo, self.brepo, self.crepo,
                                           self.Ucontroller)
        self.ceva = LateRentalCount(12, 32)
        self.altceva = BookRentalCount(12, 23)
        self.nu = AuthorRentalCount('da', 23)
        self.da = ClientRentalCount(32, 12)
コード例 #4
0
ファイル: tests.py プロジェクト: p0licat/university
def testRentalRepository():
    rentalRepo = Repository()
    book1 = Book(0, "The Q", "Albert", "Heinrich")
    book2 = Book(1, "The D", "Elbert", "Reinsich")
    client1 = Client(0, "Mihai", 1854987548795)
    client2 = Client(1, "Alex", 1987548759658)

    rentalRepo.addElement(Rental(1, book1, 0))
    rentalRepo.addElement(Rental(0, book2, 1))

    # _find(_id) returns the Rental from the repository
    # that has the client Id equal to _id

    assert rentalRepo._find(0).getRentedBook() == book1 
    assert rentalRepo._find(1).getId() == 1

    assert rentalRepo._find(1).getRentedBook() == book2
    assert rentalRepo._find(0).getId() == 0

    # findId() function for Repository class
    assert rentalRepo.findId(12) == False
    assert rentalRepo.findId(0) == True

    # elementFromId()
    assert rentalRepo.elementFromId(0).getRentedBook() == book1

    rentalRepo.addElement(Rental(1, book2, 2)) 

    print ("Rental repository tests ran successfully!")
コード例 #5
0
    def testRemoveBook(self):
        book1 = Book(1, "Title", "Description", "Author")
        book2 = Book(2, "Title1", "Description1", "Author1")
        book3 = Book(3, "Title2", "Description2", "Author2")
        repo = Repository()
        functions = BookController(repo, Statistics(repo))

        functions.addBook(book1.getId(), book1.getTitle(), book1.getDescription(), book1.getAuthor())
        functions.addBook(book2.getId(), book2.getTitle(), book2.getDescription(), book2.getAuthor())
        functions.addBook(book3.getId(), book3.getTitle(), book3.getDescription(), book3.getAuthor())

        msg1 = functions.removeBook(1)

        self.assertTrue(len(msg1) == 0)
        self.assertTrue(functions.getBooks()[0].getId() == book2.getId())
        self.assertTrue(functions.getBooks()[0].getTitle() == book2.getTitle())
        self.assertTrue(functions.getBooks()[0].getDescription() == book2.getDescription())
        self.assertTrue(functions.getBooks()[0].getAuthor() == book2.getAuthor())

        msg2 = functions.removeBook(1)

        self.assertTrue(msg2 == "The provided ID does not exist")
        self.assertTrue(functions.getBooks()[0].getId() == book2.getId())
        self.assertTrue(functions.getBooks()[0].getTitle() == book2.getTitle())
        self.assertTrue(functions.getBooks()[0].getDescription() == book2.getDescription())
        self.assertTrue(functions.getBooks()[0].getAuthor() == book2.getAuthor())
コード例 #6
0
 def test_domains(self):
     '''
     tests the implicit functions of book, client and rent domains
     '''
     book1 = Book(1, "Persona 3", "3rd entry in the series", "Shuji Sogabe")
     book2 = Book(2, "Persona 5", "5th entry in the series", "Atlus")
     assert book1.get_id() == 1
     assert book2.get_title() == "Persona 5"
     assert book1.get_desc() == "3rd entry in the series"
     assert book2.get_author() == "Atlus"
     assert Book.__str__(
         book1
     ) == "Persona 3 by Shuji Sogabe described as '3rd entry in the series' with id 1"
     try:
         Book("Five", 5, 324, "Name")
         assert False
     except ValueError:
         pass
     book1.set_id(8)
     book1.set_author("banana")
     book1.set_title("coconut")
     book1.set_desc("fruits")
     assert book1.get_id() == 8
     assert book1.get_desc() == "fruits"
     assert book1.get_author() == "banana"
     assert book1.get_title() == "coconut"
     client1 = Client(1, "Scott Fitzgerald")
     client2 = Client(2, "Shuji Sogabe")
     assert client1.get_id() == 1
     assert client2.get_name() == "Shuji Sogabe"
     assert Client.__str__(client1) == "Scott Fitzgerald with id 1"
     try:
         Client("Five", "Name")
         assert False
     except ValueError:
         pass
     client1.set_id(8)
     client1.set_name("banana")
     assert client1.get_id() == 8
     assert client1.get_name() == "banana"
     rent = Rental(12, 23, 34, datetime(2018, 2, 2), datetime(2018, 2, 16),
                   datetime(2018, 2, 10))
     assert rent.get_bookID() == 23
     assert rent.get_clientID() == 12
     assert rent.get_rentalID() == 34
     assert str(rent.get_due_date()) == "2018-02-16 00:00:00"
     assert str(rent.get_return_date()) == "2018-02-10 00:00:00"
     assert str(rent.get_rented_date()) == "2018-02-02 00:00:00"
     rent.set_bookID(23)
     rent.set_clientID(9)
     rent.set_rentalID(10)
     rent.set_rented_date(datetime(2018, 11, 3))
     rent.set_return_date(datetime(2018, 8, 31))
     rent.set_due_date(datetime(2018, 2, 8))
     assert rent.get_bookID() == 23
     assert rent.get_clientID() == 9
     assert rent.get_rentalID() == 10
     assert str(rent.get_due_date()) == "2018-02-08 00:00:00"
     assert str(rent.get_return_date()) == "2018-08-31 00:00:00"
     assert str(rent.get_rented_date()) == "2018-11-03 00:00:00"
コード例 #7
0
    def testRentalRepository(self):
        rentalRepo = Repository()
        book1 = Book(0, "The Q", "Albert", "Heinrich")
        book2 = Book(1, "The D", "Elbert", "Reinsich")
        client1 = Client(0, "Mihai", 1854987548795)
        client2 = Client(1, "Alex", 1987548759658)

        rentalRepo.addElement(Rental(1, book1, 0))
        rentalRepo.addElement(Rental(0, book2, 1))

        # _find(_id) returns the Rental from the repository
        # that has the client Id equal to _id

        self.assertEqual(rentalRepo._find(0).getRentedBook(), book1)
        self.assertEqual(rentalRepo._find(1).getId(), 1)

        self.assertEqual(rentalRepo._find(1).getRentedBook(), book2)
        self.assertEqual(rentalRepo._find(0).getId(), 0)

        # findId() function for Repository class
        self.assertEqual(rentalRepo.findId(12), False)
        self.assertEqual(rentalRepo.findId(0), True)

        # elementFromId()
        self.assertEqual(rentalRepo.elementFromId(0).getRentedBook(), book1)

        rentalRepo.addElement(Rental(1, book2, 2))
コード例 #8
0
    def testRentBook(self):
        client1 = Client(1, "Name1")
        client2 = Client(2, "Name2")

        book1 = Book(1, "Title", "Description", "Author")
        book2 = Book(2, "Title1", "Description1", "Author1")

        clientRepo = Repository()
        bookRepo = Repository()
        functions = ClientController(clientRepo, Statistics(clientRepo))
        functiom = BookController(bookRepo, Statistics(bookRepo))

        functions.addClient(client2.getId(), client2.getName())
        functions.addClient(client1.getId(), client1.getName())

        functiom.addBook(book1.getId(), book1.getTitle(), book1.getDescription(), book1.getAuthor())
        functiom.addBook(book2.getId(), book2.getTitle(), book2.getDescription(), book2.getAuthor())
        rentalRepo = Repository()
        functionsr = RentalController(bookRepo, clientRepo, rentalRepo, Statistics(rentalRepo))

        msg1 = functionsr.rentBook(book1.getId(), client1.getId(), createDateFromString("23.11.2017"), "30.11.2017")

        self.assertTrue(len(msg1) == 0)
        self.assertTrue(functionsr.getRentals()[0].getBookId() == book1.getId())
        self.assertTrue(functionsr.getRentals()[0].getClientId() == client1.getId())

        msg2 = functionsr.rentBook(book2.getId, client2.getId(), createDateFromString("20.11.2017"), "19.11.2017")
        self.assertTrue(msg2 == "Inconsistent dates")
コード例 #9
0
ファイル: test_validator.py プロジェクト: alexresiga/courses
    def setUp(self):
        self.validator = Validator()
        self.book = Book(12, '', '', '')
        self.book2 = Book(22, 'da', 'desc', 'aut')

        self.client = Client(13, '')
        self.client2 = Client(14, 'da')
コード例 #10
0
 def setUp(self):
     self.repo = Repository()
     self.rentalRepo = Repository()
     self.Ucontroller = UndoController()
     self.book = Book(21, 'titlu', 'descriere', 'author')
     self.book2 = Book(22, 'titlu2', 'descriere2', 'author2')
     self.controller = BookController(self.repo, self.Ucontroller,
                                      self.rentalRepo)
コード例 #11
0
    def __loadFromFile(self, type):
        """
        :param sample: Element
        :return: None
        :raises RepositoryException when the file cannot be read for some reason
        """
        try:
            f = open(self.__fileName, "r")
            line = f.readline().strip()
            while line != "":
                attrs = line.split(",")

                if type == Book:
                    book = Book(int(attrs[0]), attrs[1], attrs[2], attrs[3])
                    self.__repo.add(book)
                    line = f.readline().strip()

                if type == Client:
                    client = Client(int(attrs[0]), attrs[1])
                    self.__repo.add(client)
                    line = f.readline().strip()

                if type == Rental:
                    rental = Rental(
                        int(attrs[0]), int(attrs[1]), int(attrs[2]),
                        createDateFromString(self.__reverseDate(attrs[3])),
                        createDateFromString(self.__reverseDate(attrs[4])),
                        createDateFromString(self.__reverseDate(attrs[5])))
                    self.__repo.add(rental)
                    line = f.readline().strip()
        except IOError:
            raise RepositoryException()
        finally:
            f.close()
コード例 #12
0
 def test_add(self):
     '''
     tests the add function for client and book controller and rent function for rental service
     also the return function for rental service
     '''
     book = Book(0, "Persona 3", "3rd entry in the series", "Shuji Sogabe")
     self._controller.add_book(book)
     listBooks = self._controller._book_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
     client1 = Client(1, "Scott Fitzgerald")
     self._controller.add_client(client1)
     listClients = self._controller._client_repo.getAll()
     assert len(listClients) == 1
     assert listClients[0].get_name() == "Scott Fitzgerald"
     self._service.rent(book, client1, datetime(2018, 11, 3))
     listRent = self._service._rent_repo.getAll()
     assert len(listRent) == 2
     assert listRent[0].get_clientID() == 1
     assert listRent[0].get_bookID() == 0
     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"
     self._service.return_book(book, client1, datetime(2018, 12, 3))
     listRent = self._service._rent_repo.getAll()
     assert str(listRent[0].get_return_date()) == "2018-12-03 00:00:00"
コード例 #13
0
 def test_add(self):
     '''
     testing the add function of both client repo and book repo + rent repo
     also testing return function for rent
     '''
     book1 = Book(0, "Persona 3", "3rd entry in the series", "Shuji Sogabe")
     self._book_repo.add(book1)
     listBooks = self._book_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
     client1 = Client(1, "Scott Fitzgerald")
     self._client_repo.add(client1)
     listClients = self._client_repo.getAll()
     assert len(listClients) == 1
     assert listClients[0].get_name() == "Scott Fitzgerald"
     self._rental_repo.rent_book(client1, book1, datetime(2018, 11, 3))
     listRent = self._rental_repo.getAll()
     assert len(listRent) == 1
     assert listRent[0].get_clientID() == 1
     assert listRent[0].get_bookID() == 0
     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"
     self._rental_repo.return_book(client1, book1, datetime(2018, 12, 3))
     assert str(listRent[0].get_return_date()) == "2018-12-03 00:00:00"
コード例 #14
0
    def testBookRepository(self):
        repo = Repository()
        book1 = Book(1, "ala", "mala", "dala")

        repo.addElement(book1)
        self.assertEqual(len(repo), 1)

        try:
            if repo.addElement(book1) != False:
                self.assertEqual(False)
        except BookException:
            pass

        book2 = Book(2, "ala", "mala", "dala")
        repo.addElement(book2)

        self.assertEqual(len(repo), 2)
コード例 #15
0
ファイル: tests.py プロジェクト: p0licat/university
def testBookRepository():
    repo = Repository()
    book1 = Book(1, "ala", "mala", "dala")
    
    repo.addElement(book1)
    assert len(repo) == 1
    
    try:
        if repo.addElement(book1) != False:
            assert False
    except BookException:
        pass
    
    book2 = Book(2, "ala", "mala", "dala")
    repo.addElement(book2)
    
    assert len(repo) == 2
    
    print ("BookRepository tests ran successfully!")
コード例 #16
0
    def testDomainBook(self):
        book = Book(1, "Title", "Description", "Author")
        self.assertTrue(book.getTitle() == "Title")
        self.assertTrue(book.getDescription() == "Description")
        self.assertTrue(book.getAuthor() == "Author")
        self.assertTrue(book.getId() == 1)
        self.assertTrue(book.isRented() != True)
        self.assertTrue(not (book == 1))

        book.setRented(True)
        self.assertTrue(book.isRented())
コード例 #17
0
    def testBookController(self):
        repo = Repository()
        controller = BookController(repo)
        undoController = Undo()
        controller.addUndoController(undoController)

        self.assertEqual(controller.addBook(Book(1, "ala", "mala", "dala")),
                         True)
        self.assertNotEqual(controller.searchById(1), False)

        found = controller.searchById(1)
        self.assertEqual(found, Book(1, "ala", "mala", "dala"))
        self.assertEqual(controller.searchByTitle("ala"),
                         Book(1, "ala", "mala", "dala"))

        self.assertNotEqual(
            controller.modifyBookAuthor(Book(1, "ala", "mala", "dala"),
                                        "Mercan"), False)

        self.assertEqual(
            controller.modifyBookTitle(Book(1, "ala", "mala", "Mercan"),
                                       "Newt"), True)
        self.assertEqual(controller.findExistingId(1), True)

        self.assertEqual(
            controller.removeElement(Book(1, "Newt", "mala", "Mercan")), True)
        self.assertEqual(controller.searchById(1), False)
        self.assertEqual(controller.checkIdExists(1), False)
コード例 #18
0
    def create(self, bookID, title, description, author):
        newbook = Book(bookID, title, description, author)
        bookList = self.__repository.getAll()

        for book in bookList:
            if book.getBookID == bookID:
                raise ValueError("The ID must be unique!")
        redo = FunctionCall(self.create, bookID, title, description, author)
        undo = FunctionCall(self.remove, bookID)
        oper = Operation(undo, redo)
        self.__UndoController.add(oper)
        self.__repository.addBook(newbook)
        return newbook
コード例 #19
0
    def testBook(self):
        try:
            book1 = Book(1, "a", "b", "c")
            self.assertEqual(book1.getId(), 1)
            self.assertEqual(book1.getTitle(), "a")
            self.assertEqual(book1.getDescription(), "b")
            self.assertEqual(book1.getAuthor(), "c")
        except:
            self.assertEqual(False)

        try:
            book1 = Book("D", "d", "d", "d")
            self.assertEqual(False)
        except BookException:
            pass

        try:
            book1 = Book(1, "a", "b", "c")
            book1.setTitle(3)
            self.assertEqual(False)
        except:
            pass
コード例 #20
0
 def updateBook(self, id, newTitle, newDesc, newAuthor):
     """
     :param id: int
     :param newTitle: string
     :param newDesc: string
     :param newAuthor: string
     :return: None
     """
     try:
         self.__bookRepo.removeById(id)
         updatedBook = Book(id, newTitle, newDesc, newAuthor)
         self.__bookRepo.add(updatedBook)
     except RepositoryException as re:
         pass
コード例 #21
0
    def testAddBook(self):
        book1 = Book(1, "Title", "Description", "Author")
        book2 = Book(2, "Title1", "Description1", "Author1")
        book3 = Book(1, "Title2", "Description2", "Author2")
        repo = Repository()
        functions = BookController(repo, Statistics(repo))

        msg1 = functions.addBook(book1.getId(), book1.getTitle(), book1.getDescription(), book1.getAuthor())

        self.assertTrue(msg1 == "")
        self.assertTrue(functions.getBooks()[0].getId() == book1.getId())
        self.assertTrue(functions.getBooks()[0].getTitle() == book1.getTitle())
        self.assertTrue(functions.getBooks()[0].getDescription() == book1.getDescription())
        self.assertTrue(functions.getBooks()[0].getAuthor() == book1.getAuthor())

        msg2 = functions.addBook(book2.getId(), book2.getTitle(), book2.getDescription(), book2.getAuthor())

        self.assertTrue(msg2 == "")
        self.assertTrue(functions.getBooks()[1].getId() == book2.getId())
        self.assertTrue(functions.getBooks()[1].getTitle() == book2.getTitle())
        self.assertTrue(functions.getBooks()[1].getDescription() == book2.getDescription())
        self.assertTrue(functions.getBooks()[1].getAuthor() == book2.getAuthor())

        msg3 = functions.addBook(book3.getId(), book3.getTitle(), book3.getDescription(), book3.getAuthor())

        self.assertTrue(msg3 == "Cannot add an existing element")

        self.assertTrue(functions.getBooks()[1].getId() == book2.getId())
        self.assertTrue(functions.getBooks()[1].getTitle() == book2.getTitle())
        self.assertTrue(functions.getBooks()[1].getDescription() == book2.getDescription())
        self.assertTrue(functions.getBooks()[1].getAuthor() == book2.getAuthor())

        self.assertTrue(functions.getBooks()[0].getId() == book1.getId())
        self.assertTrue(functions.getBooks()[0].getTitle() == book1.getTitle())
        self.assertTrue(functions.getBooks()[0].getDescription() == book1.getDescription())
        self.assertTrue(functions.getBooks()[0].getAuthor() == book1.getAuthor())
コード例 #22
0
    def populateBookRepository(self):
        """
        Populate the repo with some random entities
        :return: None
        """

        for i in range(100):
            id = random.randint(1, 100)
            title = "Title" + str(random.randint(1, 100))
            desc = "Description" + str(random.randint(1, 100))
            author = "Author" + str(random.randint(1, 100))

            if not self.__bookRepo.existsById(id):
                book = Book(id, title, desc, author)
                self.addBook(id, title, desc, author)
コード例 #23
0
 def testSearchAvailable(self):
     '''
     tests search function for client/book and available function for rentals
     '''
     book = Book(0, "Persona 3", "3rd entry in the series", "Shuji Sogabe")
     self._controller.add_book(book)
     client = Client(1, "Scott Fitzgerald")
     self._controller.add_client(client)
     self._service.rent(book, client, datetime(2018, 11, 3))
     assert self._controller.parse_search_word("pErSoNa") == "persona"
     assert self._controller.parse_search_word(5) == 5
     assert self._service.available_book(book, datetime(2018, 11, 3),
                                         datetime(2018, 12, 3)) == False
     self._service.return_book(book, client, datetime(2018, 12, 3))
     assert self._service.available_book(book, datetime(2019, 12, 4),
                                         datetime(2019, 12, 23)) == False
コード例 #24
0
    def testRental(self):
        repo = Repository()
        book1 = Book(1, "ala", "mala", "dala")

        rentList = Repository()
        rentList.addElement(Rental(2, book1, 0))

        lis1 = rentList.getElementList()
        self.assertEqual(len(lis1), 1)

        rentList.addElement(Rental(2, book1, 1))
        lis1 = rentList.getElementList()
        self.assertEqual(len(lis1), 2)
        self.assertEqual(lis1[0].getRenterId(), 2)
        self.assertEqual(lis1[0].getRentedBook(), book1)
        self.assertEqual(lis1[0].getId(), 0)
コード例 #25
0
 def put(self, index):
     for i in range(index):
         isbn = self.book_info["items"][i]["volumeInfo"].get(
             "industryIdentifiers")
         if isbn is not None and "ISBN" in isbn[0]["type"]:
             isbn = isbn[0]["identifier"]
         else:
             continue
         title = self.book_info["items"][i]["volumeInfo"].get("title")
         image_link = self.book_info["items"][i]["volumeInfo"].get(
             "imageLinks").get("thumbnail", "")
         try:
             self.books.append(
                 Book(title=title, isbn=isbn, image_link=image_link))
         except ValidationError as e:
             print(f"[ERROR]{e}")
コード例 #26
0
ファイル: tests.py プロジェクト: p0licat/university
def testRental():
    repo = Repository()
    book1 = Book(1, "ala", "mala", "dala")
    
    rentList = Repository()
    rentList.addElement(Rental(2, book1, 0))

    lis1 = rentList.getElementList()
    assert len(lis1) == 1

    rentList.addElement(Rental(2, book1, 1))
    lis1 = rentList.getElementList()
    assert len(lis1) == 2
    assert lis1[0].getRenterId() == 2
    assert lis1[0].getRentedBook() == book1
    assert lis1[0].getId() == 0

    print ("Rental tests ran successfully!")
コード例 #27
0
ファイル: BookController.py プロジェクト: p0licat/university
 def modifyBookAuthor(self, bookElement, newAuthor):
     '''
         Searches repository for corresponding bookElement and replaces its author. This is done by first removing the entry
         from the repository, constructing a new one and adding it.
         Input:
             self - object defined by this class
             bookElement - Book type object
             newAuthor - string
         Output:
             True/False
     '''
     if self._repo.findId(bookElement.getId()) == False:
         return False
     newBook = Book(bookElement.getId(), bookElement.getTitle(),
                    bookElement.getDescription(), newAuthor)
     self._repo.removeElement(bookElement)
     self._repo.addElement(newBook)
     newOperation = ModifyOperation(self._repo, bookElement, newBook)
     self._undoController._addOperation(newOperation)
     return True
コード例 #28
0
    def addBook(self, id, title, description, author):
        """
        
        :param id: int
        :param title: string
        :param description: string
        :param author: string
        :return: a string of errors if any
        """
        errorString = ""
        errorString += self.__validator.validateNewBook(
            id, title, description, author)
        if len(errorString) != 0:
            return errorString

        book = Book(id, title, description, author)

        try:
            self.__bookRepo.add(book)

        except RepositoryException as re:
            return str(re)
        return ""
コード例 #29
0
ファイル: tests.py プロジェクト: p0licat/university
def testBookController():
    repo = Repository()
    controller = BookController(repo)
    undoController = Undo()
    controller.addUndoController(undoController)
    
    assert controller.addBook(Book(1, "ala", "mala", "dala")) == True
    assert controller.searchById(1) != False

    found = controller.searchById(1)
    assert found == Book(1, "ala", "mala", "dala")
    assert controller.searchByTitle("ala") == Book(1, "ala", "mala", "dala")

    assert controller.modifyBookAuthor(Book(1, "ala", "mala", "dala"), 
            "Mercan") != False

    assert controller.modifyBookTitle(Book(1, "ala", "mala", "Mercan"), "Newt") == True
    assert controller.findExistingId(1) == True

    assert controller.removeElement(Book(1, "Newt", "mala", "Mercan")) == True
    assert controller.searchById(1) == False
    assert controller.checkIdExists(1) == False
    
    print ("BookController tests ran successfully!")
コード例 #30
0
    def test_delete(self):
        '''
        testing the delete function of client, book and rental repositories
        also tests find functions for books/ clients
        '''
        book1 = Book(0, "Persona 3", "3rd entry in the series", "Shuji Sogabe")
        self._book_repo.add(book1)
        book2 = Book(1, "Persona 5", "5th entry in the series", "Atlus")
        self._book_repo.add(book2)
        self._book_repo.remove(book1)
        listBooks = self._book_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:
            self._book_repo.remove(Book(34, "til", "de", "dw"))
            assert True
        except IndexError:
            pass
        except ValueError:
            pass

        assert self._book_repo.find(book1) == False
        assert self._book_repo.find(book2) == True
        assert self._book_repo.find_by_id(book2.get_id()) == book2

        client1 = Client(1, "Scott Fitzgerald")
        client2 = Client(2, "Shuji Sogabe")
        self._client_repo.add(client1)
        self._client_repo.add(client2)
        self._client_repo.remove(client1)
        listClients = self._client_repo.getAll()
        assert len(listClients) == 1
        assert listClients[0].get_name() == "Shuji Sogabe"
        assert listClients[0].get_id() == 2
        try:
            self._client_repo.remove(Client(34, "til"))
            assert True
        except IndexError:
            pass
        except ValueError:
            pass

        assert self._client_repo.find(client1) == False
        assert self._client_repo.find(client2) == True
        assert self._client_repo.find(Client(1, "Shuji Sogabe")) == False
        assert self._client_repo.find_by_id(client2.get_id()) == client2
        self._rental_repo.rent_book(client1, book1, datetime(2018, 11, 3))
        self._rental_repo.rent_book(client2, book1, datetime(2018, 12, 3))
        self._rental_repo.delete(self._rental_repo.getAll()[1])
        listRent = self._rental_repo.getAll()
        assert len(listRent) == 1
        assert listRent[0].get_clientID() == 1
        assert listRent[0].get_bookID() == 0
        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"
        try:
            self._rental_repo.rent_book(client2, book1, datetime(2018, 12, 7))
            assert True
        except IndexError:
            pass
        except ValueError:
            pass