Ejemplo n.º 1
0
 def create_one(self, new_book_details: dict):
     """
     Adds new Book from dict with information passed from web form
     :param new_book_details:
     :return:
     """
     response = {"flash_message": "", "book_url_title": ""}
     book = Book(new_book_details)
     create_book = self.create(book)
     if create_book is not None:
         response['flash_message'] = "Could Not Add book, Try Again"
     else:
         response['flash_message'] = f'{book.get_formatted_title()} added!'
         response['book_url_title'] = book.get_title_for_url()
     return response
Ejemplo n.º 2
0
 def setUp(self):
     file = open('test/data/book.json')
     book_data = json.load(file)
     file.close()
     self.books = []
     for book in book_data:
         self.books.append(Book(book))
 def setUp(self):
     # Mock of Review Query
     review_json = open('test/data/book.json')
     self.books_from_json = json.load(review_json)
     review_json.close()
     self.books_object_list = []
     self.books = ManageBooks()
     for book in self.books_from_json:
         self.books_object_list.append(Book(book))
Ejemplo n.º 4
0
 def get_one_by_id(self, object_id: str):
     """
         Queries Data Storage for Book based on attribute_name
         :param object_id: object_id
         :return: book: Book
     """
     book = self.model.find_by_id(ObjectId(object_id))
     if book:
         return Book(book)
Ejemplo n.º 5
0
 def get_by_title(self, title: str):
     """
         Queries Data Storage for Book based on attribute_name
         :param title: str
         :return: book: Book
     """
     book = Book(self.model.find_by_field_name_and_value(title, 'title'))
     if book:
         return book
Ejemplo n.º 6
0
 def create(self, book: Book):
     """
         Wrapper method for Model
         :param book: Book
         :return: None
     """
     create_book = self.model.create_one(book.get_dict())
     if not create_book:
         return create_book
Ejemplo n.º 7
0
    def update_details(self, book_id: str, new_book_details: dict):
        """
        Push Update book Information to Mongo
        :param book_id:
        :param new_book_details:
        :return: response: dict {flash_message, book_title}
        """
        response = {"flash_message": "", "book_title": ""}

        book = Book(new_book_details)
        create_book = self.update(ObjectId(book_id), book.get_dict())
        if create_book is not None:
            response['flash_message'] = "Could Not Add book, Try Again"
        else:
            response[
                'flash_message'] = f'{book.get_formatted_title()} updated!'
            response['book_url_title'] = book.get_title_for_url()
        return response
Ejemplo n.º 8
0
 def search(self, query: str):
     """
         Wrap search call for Collection search Index for Book Title or Author (Based Mongo Search Index)
         :param query: str
         :return: list of books matching search query
     """
     query_results = []
     search_books_query_result = self.model.search(query)
     if search_books_query_result:
         for book in search_books_query_result:
             query_results.append(Book(book))
         return query_results
Ejemplo n.º 9
0
 def get_all(self):
     response = []
     books = self.model.find_all()
     for book in books:
         response.append(Book(book))
     return response