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 textbook object to make sure it returns none but prints the description""" self.assertTrue(self.textbook.get_availability_status()) self.assertEqual(self.textbook.display_info(), None) self.textbook = Textbook('A111', 'why do we need to sleep?', 'John Simpliciano', 2017, 9, 'hardcover case wrap', 'health', False) self.assertFalse(self.textbook.get_availability_status()) self.assertEqual(self.textbook.display_info(), None)
def test_constructor(self): """tests the constructor as a 'success' and 'failure' test""" self.assertIsNotNone(self.textbook) self.assertIsInstance(self.textbook, Textbook) with self.assertRaises(TypeError): textbook = Textbook('V654', 'Hamlet', 'Shakespeare', 2000, 10, 2, 'literature', True) with self.assertRaises(ValueError): textbook = Textbook('V654', 'Hamlet', 'Shakespeare', 2000, 10, 'hardcover dust', 'literature', True) with self.assertRaises(TypeError): textbook = Textbook('V654', 'Hamlet', 'Shakespeare', 2000, 3, 'hardcover dust jacket', 3, True) with self.assertRaises(ValueError): textbook = Textbook('V654', 'Hamlet', 'Shakespeare', 2000, 10, 'hardcover dust jacket', 'kids', True)
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)
from textbook import Textbook book1 = Textbook("Programming is the best!", "Joe", "Degere", "19", "1234567", 20, 39.99, "Jerry Springer", 2019) book2 = Textbook("Let's go Skydiving", "Joe", "Degere", "19", "1234789", 25, 24.99, "Jim Carrey", 2019) # Have to make a menu menu_choice = 0 while menu_choice != 5: print("Please make a choice from the menu:") print("1. Add to inventory") print("2. Deduct from inventory") print("3. Change the price of the book") print("4. Change the year the book was published") print("5. End program, Have a good day!") menu_choice = int(input()) # Break down which book is chosen in each function if menu_choice == 1: print("Book 1 or Book 2?") choice = int(input()) if choice == 1: qty = int( input("How much would you like to add to the inventory?")) book1.add_inventory(qty) print("The quantity in the inventory is now" + ' ' + str(book1.quantity) + "\n\n") else: print("The quantity in book 2 is now" + ' ' + str(book2.quantity) + "\n\n")
f"\tNumber of books available to borrow: {book_stat.get_num_not_borrowed():d}\n" ) print('ebooks available to borrow:') librarian.show_book_not_borrowed('ebook') print('Textbooks available to borrow:') librarian.show_book_not_borrowed('textbook') # print('ebook genres available in the library:') # 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) # ----------------------------------------------------------------------------------------------------------------------
def textbooks(self): from textbook import Textbook return Textbook.query(ancestor = self.key).fetch()
# Olivia Lee from textbook import Textbook print("Textbook 1: ") textbook_1 = Textbook(input("Title: "), input("Authors first name: "), input("Authors last name: "), int(input("Authors age: ")), int(input("Edition: ")), int(input("ISBN number: ")), input("Publisher: "), int(input("Year published: ")), int(input("Quantity in stock: ")), float(input("Price: ")), ) print("Textbook 2: ") textbook_2 = Textbook(input("Title: "), input("Authors first name: "), input("Authors last name: "), int(input("Authors age: ")), int(input("Edition: ")), int(input("ISBN number: ")), input("Publisher: "), int(input("Year published: ")), int(input("Quantity in stock: ")), float(input("Price: ")), ) menu_choice = 0 again_choice = 1 print(f"Would you like to view 1. {textbook_1.title} or 2. {textbook_2.title}. Please enter a 1 or a 2.") book_choice = int(input("> ")) while again_choice == 1: if book_choice == 1: while menu_choice != 4: print("Please chose the number to indicate which option you would like to choose") print("1. Add inventory") print("2. Decrease inventory") print("3. Change price") print("4. Leave everything how it is") menu_choice = int(input("> ")) if menu_choice == 1: print("You chose to add inventory")
from textbook import Textbook # enter info for first book print("Enter data for text book:") title = input("Title:\n> ") first = input("Author's first name:\n> ") last = input("Author's last name:\n> ") age = input("Author's age:\n> ") edition = input("Edition:\n> ") isbn_number = input("ISBN Number:\n> ") publisher = input("Publisher:\n> ") year = input("Year published:\n> ") inventory = input("Quantity in inventory:\n> ") price = input("Price:\n> $") # create book object book1 = Textbook(title, first, last, age, edition, isbn_number, publisher, year, inventory, price) # enter info for second book print("Enter data for next text book:") title2 = input("Title:\n> ") first2 = input("Author's first name:\n> ") last2 = input("Author's last name:\n> ") age2 = input("Author's age:\n> ") edition2 = input("Edition:\n> ") isbn_number2 = input("ISBN Number:\n> ") publisher2 = input("Publisher:\n> ") year2 = input("Year published:\n> ") inventory2 = input("Quantity in inventory:\n> ") price2 = input("Price:\n> $") # create book object book2 = Textbook(title2, first2, last2, age2, edition2, isbn_number2,
def savedTextbooks(self): from textbook import Textbook return Textbook.query(ancestor = self.key).filter(Textbook.onSyllabus == False).fetch()
def setUp(self): """creates an object to be tested and to prevent redundancy in creating objects""" self.textbook = Textbook('V654', 'Hamlet', 'Shakespeare', 2000, 3, 'hardcover dust jacket', 'literature', True)
class TestTextbook(TestCase): def setUp(self): """creates an object to be tested and to prevent redundancy in creating objects""" self.textbook = Textbook('V654', 'Hamlet', 'Shakespeare', 2000, 3, 'hardcover dust jacket', 'literature', True) def test_constructor(self): """tests the constructor as a 'success' and 'failure' test""" self.assertIsNotNone(self.textbook) self.assertIsInstance(self.textbook, Textbook) with self.assertRaises(TypeError): textbook = Textbook('V654', 'Hamlet', 'Shakespeare', 2000, 10, 2, 'literature', True) with self.assertRaises(ValueError): textbook = Textbook('V654', 'Hamlet', 'Shakespeare', 2000, 10, 'hardcover dust', 'literature', True) with self.assertRaises(TypeError): textbook = Textbook('V654', 'Hamlet', 'Shakespeare', 2000, 3, 'hardcover dust jacket', 3, True) with self.assertRaises(ValueError): textbook = Textbook('V654', 'Hamlet', 'Shakespeare', 2000, 10, 'hardcover dust jacket', 'kids', True) def test_get_book_type(self): """tests the book type""" self.assertEqual(self.textbook.get_book_type, 'textbook') self.assertIsNotNone(self.textbook.get_book_type) def test_get_book_subject(self): """tests the book subject""" self.assertEqual(self.textbook.get_book_subject, 'literature') self.assertIsNotNone(self.textbook.get_book_subject) def test_set_book_subject(self): """tests the book platform""" self.textbook.set_book_subject('music') self.assertEqual(self.textbook.get_book_subject, 'music') self.assertIsNotNone(self.textbook.get_book_subject) with self.assertRaises(ValueError): self.textbook.set_book_subject('poem') with self.assertRaises(TypeError): self.textbook.set_book_subject(12) def test_get_cover_type(self): """tests the book cover type""" self.assertEqual(self.textbook.get_cover_type, 'hardcover dust jacket') self.assertIsNotNone(self.textbook.get_cover_type) def test_set_cover_type(self): """tests the book platform""" self.textbook.set_cover_type('paperback') self.assertEqual(self.textbook.get_cover_type, 'paperback') self.assertIsNotNone(self.textbook.get_cover_type) with self.assertRaises(ValueError): self.textbook.set_cover_type('poem') with self.assertRaises(TypeError): self.textbook.set_cover_type(12) def test_get_available_cover_types(self): """tests the available cover types in the library""" self.assertEqual(self.textbook.get_available_cover_types, '\n '.join(self.textbook.COVER_TYPE)) self.assertIsNotNone(self.textbook.get_available_cover_types) def test_suffix(self): """tests the book edition suffix for performance""" self.assertEqual(self.textbook.suffix(self.textbook.get_edition()), 'rd') def test_to_dict(self): """ tests the performance of converting textbook objects to json dictionary """ self.assertTrue(self.textbook.to_dict()) self.assertEqual( self.textbook.to_dict(), { 'id': 'V654', 'title': 'Hamlet', 'author': 'Shakespeare', 'published_year': 2000, 'edition': 3, 'cover_type': 'hardcover dust jacket', 'subject': 'literature', 'is_borrowed': True }) def test_display_info(self): """tests the description of the textbook object to make sure it returns none but prints the description""" self.assertTrue(self.textbook.get_availability_status()) self.assertEqual(self.textbook.display_info(), None) self.textbook = Textbook('A111', 'why do we need to sleep?', 'John Simpliciano', 2017, 9, 'hardcover case wrap', 'health', False) self.assertFalse(self.textbook.get_availability_status()) self.assertEqual(self.textbook.display_info(), None)