コード例 #1
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")
コード例 #2
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())
コード例 #3
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)
コード例 #4
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)
コード例 #5
0
    def testUtils(self):
        bList = []
        self.assertTrue(len(bList) == 0)
        bookRepo = Repository()
        bc = BookController(bookRepo, Statistics(bookRepo))
        bc.populateBookRepository()

        self.assertTrue(0 < len(bookRepo.getAll()) < 100)
コード例 #6
0
    def testUpdateBook(self):
        bookRepo = Repository()
        bc = BookController(bookRepo, Statistics(bookRepo))
        bc.populateBookRepository()
        bc.addBook(101, "Title", "Description", "Author")
        bc.updateBook(101, "title", "description", "author")

        self.assertTrue(bookRepo.getById(101).getTitle() == "title")
        self.assertTrue(bookRepo.getById(101).getAuthor() == "author")
        self.assertTrue(bookRepo.getById(101).getDescription() == "description")
コード例 #7
0
def addBook():
    user_email = get_jwt_identity()
    author = request.form.get('author', None)
    bookname = request.form.get('book_name', None)
    if author is None or bookname is None:
        return jsonify({"error": "check your input"}), 403
    bookController = BookController()
    return jsonify(
        bookController.addBook(name=bookname,
                               author=author,
                               uploader_email=user_email))
コード例 #8
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())
コード例 #9
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!")
コード例 #10
0
    clientRepo = Repository()
    rentalRepo = Repository()
elif mode == "text":
    bookRepo = CSVRepository(path + "bookRepo.csv", Book)
    clientRepo = CSVRepository(path + "clientRepo.csv", Client)
    rentalRepo = CSVRepository(path + "rentalRepo.csv", Rental)
elif mode == "binary":
    bookRepo = PickleRepository(path + "binaryBookRepo.pickle")
    clientRepo = PickleRepository(path + "binaryClientRepo.pickle")
    rentalRepo = PickleRepository(path + "binaryRentalRepo.pickle")
elif mode == "custom":
    bookRepo = CustomRepository(Book)
    clientRepo = CustomRepository(Client)
    rentalRepo = CustomRepository(Rental)
else:
    raise ValueError("Invalid option")

validator = Validator()
stats = Statistics(bookRepo)
bookController = BookController(bookRepo, stats)
bookController.populateBookRepository()

clientController = ClientController(clientRepo, stats)
clientController.populateClientRepository()

rentalController = RentalController(bookRepo, clientRepo, rentalRepo, stats)
#rentalController.populateRentals()

ui = Ui(bookController, clientController, rentalController, validator, stats)

ui.runUi()
コード例 #11
0
def main():
    '''
        This is the main() function and is the first thing that is ran by the program. It contains all the objects 
        necessary for execution and everything related to the UI.
    '''

    # repositories must be initialized with a string containing the type of the repository in order to use files
    clientRepository = Repository("Client")
    bookRepository = Repository("Book")
    rentalRepository = Repository("Rental")

    clientController = ClientController(clientRepository)
    bookController = BookController(bookRepository)
    rentalController = RentalController(rentalRepository, clientController,
                                        bookController)

    keepAlive = True
    while keepAlive:
        userInput = input(
            "Please choose the mode (memory/file). Insert 'x' to quit: ")
        if userInput == 'x':
            return
        elif userInput == 'memory':
            clientRepository.addElement(Client(0, 'Mircea', 1962353535353))
            clientRepository.addElement(Client(1, 'Dorin', 1962353535354))
            clientRepository.addElement(Client(3, 'Marius', 1962353335353))
            clientRepository.addElement(Client(6, 'Dacia', 1962353444353))
            bookRepository.addElement(
                Book(0, "Dorin Mateiu", "Viata pe un Stalp", "Mihaila"))
            bookRepository.addElement(Book(1, "Salutare", "Lume", "Viata"))
            bookRepository.addElement(Book(2, "Inca", "O Carte", "Buna"))

            ui_object = UserInterface(clientController, bookController,
                                      rentalController)
            ui_object.launchMainMenu()

            keepAlive = False
        elif userInput == 'file':
            print("Available files: ")

            files = listdir('resources')
            for i in files:
                if i[-4:] == '.txt':
                    print(i)
            print()

            print("Please choose the file you want to load.",
                  "If that file does not exist it will be created.")
            print("Insert 'x' at any time to quit.")
            chosenFile = input("Please insert file name: ")

            if chosenFile == 'x':
                continue

            alreadyExists = False
            existingFile = None
            for i in files:
                if i[:-4] == chosenFile:
                    alreadyExists = True
                    existingFile = i

            if alreadyExists == True:
                print("File found! Type again to load: ")
                confirmInput = input()
                if confirmInput == 'x':
                    continue
                if confirmInput == chosenFile:
                    # file was found and will be loaded
                    if '.txt' in chosenFile:
                        chosenFile = chosenFile[:-4]
                    filePath = 'resources/' + chosenFile + '.txt'

                    ui_object = UserInterface(clientController, bookController,
                                              rentalController, filePath)
                    ui_object.launchMainMenu()
                else:
                    print("Returning...")
                    continue
            else:
                print("Create file? Type again to confirm: ")
                confirmInput = input()
                if confirmInput == 'x':
                    continue
                if confirmInput == chosenFile:
                    filePath = 'resources/' + chosenFile + '.txt'

                    ui_object = UserInterface(clientController, bookController,
                                              rentalController, None)
                    ui_object.launchMainMenu(filePath)
                else:
                    print("Returning...")
                    continue

            keepAlive = False
        else:
            print("Error! Please insert 'file' or 'memory' ")
コード例 #12
0
def deleteBookNameById(book_id):
    bookController = BookController()
    return jsonify(bookController.deleteBook(book_id))
コード例 #13
0
def updateBookNameById(book_id):
    bookname = request.form.get('name', None)
    bookController = BookController()
    if bookname is None:
        return jsonify({"error": "check your input"}), 403
    return jsonify(bookController.updateBook(book_id, bookname))
コード例 #14
0
def getBookById(book_id):
    bookController = BookController()
    return jsonify(bookController.getBookById(book_id))
コード例 #15
0
def getBooks():
    bookController = BookController()
    return jsonify(bookController.getBooks())
コード例 #16
0
Brepo = FileRepository('books.txt', Book.readBookFromLine, Book.writeBookToLine)

Crepo = FileRepository('clients.txt', Client.readClientFromLine, Client.writeClientToLine)

Rrepo = Repository()
Rrepo.add(Rental(16675, 16, 67, date(2017, 11, 10), date(2017, 12, 11)))
Rrepo.add(Rental(12675, 12, 67, date(2017, 11, 1), date(2017, 11, 11)))
Rrepo.add(Rental(13115, 13, 11, date(2017, 11, 21), date(2017, 11, 11)))
Rrepo.add(Rental(13678, 13, 67, date(2017, 11, 7), date(2017, 11, 20)))
Rrepo.add(Rental(12622, 12, 62, date(2017, 11, 18), date(2017, 1, 11)))
Rrepo.add(Rental(14675, 14, 67, date(2017, 11, 5), date(2017, 11, 24)))
Rrepo.add(Rental(14637, 14, 63, date(2017, 11, 10), date(2017, 10, 11)))
Rrepo.add(Rental(14671, 14, 67, date(2017, 11, 9), date(2017, 12, 11)))
Rrepo.add(Rental(16652, 16, 65, date(2017, 11, 4), date(2017, 11, 16)))
Rrepo.add(Rental(15661, 15, 66, date(2017, 11, 12), date(2017, 10, 30)))
Rrepo.add(Rental(12629, 12, 62, date(2017, 11, 13), date(2017, 11, 25)))
Rrepo.add(Rental(15695, 15, 69, date(2017, 11, 19), date(2017, 11, 24)))
Rrepo.add(Rental(16770, 16, 77, date(2017, 11, 2), date(2017, 11, 24)))

Ucontroller = UndoController()
Bcontroller = BookController(Brepo, Ucontroller, Rrepo)
Ccontroller = ClientController(Crepo, Ucontroller, Rrepo)
Rcontroller = RentalController(Rrepo, Brepo, Crepo, Ucontroller)

ui = UI(Bcontroller, Ccontroller, Rcontroller, Ucontroller)
# ui.mainMenu()

root = Tk()
gui = GUI(root, Bcontroller, Ccontroller, Rcontroller, Ucontroller)
root.mainloop()