def setUp(self): self.library1 = LibraryManager('The_library') self.book1 = eBook('B20V2', 'Me', 'Elton John', 2017, 4, 'OverDrive Read', 'biography', False) self.book2 = Textbook('A111', 'why do we need to sleep?', 'John Simpliciano', 2017, 9, 'hardcover case wrap', 'health', False) self.book3 = Textbook('A110', 'why do we sleep?', 'John Simpliciano', 2015, 3, 'hardcover case wrap', 'health', True)
def test_display_info(self): """tests the description of the ebook object to make sure it returns none but prints the description""" self.assertFalse(self.ebook.get_availability_status()) self.assertEqual(self.ebook.display_info(), None) self.ebook1 = eBook('L091A', 'Deadpool Vol.4: Monkey Business', 'Daniel Way', 2019, 5, 'Fast Read Ebooks', 'comics', True) self.assertTrue(self.ebook1.get_availability_status()) self.assertEqual(self.ebook1.display_info(), None)
def test_constructor(self): """tests the constructor as a 'failure' test""" self.assertIsNotNone(self.ebook) self.assertIsInstance(self.ebook, eBook) with self.assertRaises(TypeError): ebook = eBook('B20V2', 'Me', 'Elton John', 2017, 4, 2, 'biography', False) with self.assertRaises(ValueError): ebook = eBook('B20V2', 'Me', 'Elton John', 2017, 4, 'OverRead', 'biography', False) with self.assertRaises(TypeError): ebook = eBook('B20V2', 'Me', 'Elton John', 2017, 4, 'OverDrive Read', 34, False) with self.assertRaises(ValueError): ebook = eBook('B20V2', 'Me', 'Elton John', 2017, 4, 'OverDrive Read', 'bio', False)
def from_dict(book_dict: dict, book_type: str): """ Return textbook instance state from JSON format as dictionary """ global instance if book_type == "ebook": instance = eBook(book_dict["id"], book_dict["title"], book_dict["author"], book_dict["published_year"], book_dict["edition"], book_dict["platform"], book_dict["genre"], book_dict["is_borrowed"]) elif book_type == "textbook": instance = Textbook(book_dict["id"], book_dict["title"], book_dict["author"], book_dict["published_year"], book_dict["edition"], book_dict["cover_type"], book_dict["subject"], book_dict["is_borrowed"]) return instance
def add_book(book_type): data = request.json try: if book_type == "textbook": textbook = Textbook(data["id"], data["title"], data["author"], data["published_year"], data["edition"], data["cover_type"], data["subject"], data["is_borrowed"]) library.add_book(textbook) elif book_type == "ebook": ebook = eBook(data["id"], data["title"], data["author"], data["published_year"], data["edition"], data["platform"], data["genre"], data["is_borrowed"]) library.add_book(ebook) else: return make_response(f'Invalid book_type "{book_type}"!', 400) except KeyError as error: message = str(error) return make_response(message, 400) else: return make_response(data["id"], 200)
def setUp(self): """creates an object to be tested and to prevent redundancy in creating objects""" self.ebook = eBook('B20V2', 'Me', 'Elton John', 2017, 4, 'OverDrive Read', 'biography', False)
# librarian.show_available_book_category('ebook') # print('Textbook subjects available in the library:') # librarian.show_available_book_category('textbook') if __name__ == '__main__': librarian = LibraryManager('Susan Sanderson') book1 = Textbook('A111', 'why do we need to sleep?', 'John Simpliciano', 2017, 3, 'hardcover case wrap', 'health', False) book2 = Textbook('B222', 'color methology', 'Maryam Taer', 2002, 4, 'paperback', 'arts', True) book3 = Textbook('V654', 'Hamlet', 'Shakespeare', 2000, 10, 'hardcover dust jacket', 'literature', True) book4 = Textbook('F009', 'Mein Kampf', 'Adolf Hitler', 1925, 6, 'paperback', 'history', False) book5 = eBook('B20V2', 'Me', 'Elton John', 2017, 4, 'OverDrive Read', 'biography', False) book6 = eBook('M3K12', 'Pax', 'Sara Pennypacker', 2012, 5, 'OverDrive Read', 'kids', True) book7 = eBook('L091A', 'Deadpool Vol.4: Monkey Business', 'Daniel Way', 2019, 5, 'Fast Read Ebooks', 'comics', True) book8 = eBook('GH255', 'Golden in Death', 'J. D Robb', 2016, 5, 'OverDrive Read', 'fantasy', True) # ---------------------------------------------------------------------------------------------------------------------- """Trying some 'success' cases per method""" try: librarian.add_book(book1) except LookupError: print('The property already exists in the inventory.') try: librarian.add_book(book2)