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)
Example #2
0
 def test_read_from_file(self):
     """ tests to see if read_from_file method is called properly """
     self.librarian = LibraryManager('Maryam')
     self.assertTrue(os.path.exists('library_manager.json'))
     self.librarian1 = LibraryManager('John')
     os.remove('library_manager.json')
     self.assertFalse(os.path.exists('library_manager.json'))
Example #3
0
def init():
    manager = LibraryManager(True)
    for key in lib_to_user:
        manager.add_link(key, lib_to_user[key])
    
    users = UserGroup('pknu', True)
    for user_data in user_pknu:
        sid, pw, name = user_data
        users.add_user(sid, pw, name)
        
    pklib = Library('대연/중앙도서관', True)
    for section_id in data_pklib:
        qr_codes = data_pklib[section_id]
        pklib.add_section(section_id, qr_codes)
Example #4
0
    pklib = Library('대연/중앙도서관', True)
    for section_id in data_pklib:
        qr_codes = data_pklib[section_id]
        pklib.add_section(section_id, qr_codes)

def sign_in(campus, uid, pw):
    ug = UserGroup(campus)

def show_table(db_name, table_name):
    conn = sqlite3.connect(db_name)
    cursor= conn.cursor()
    for d in cursor.execute('select * from ' + table_name).fetchall():
        print(d)
    conn.close()

manager = LibraryManager()

    
actions = {
    (1,1) : manager.sign_in,
    (2,1) : manager.get_all_seats_data,
    (3,1) : manager.get_seat_data,
    (3,2) : manager.seat,
    (3,3) : manager.extend,
    (3,4) : manager.leave,
    (3,5) : manager.get_user_seat,
    (4,1) : manager.get_extending_time,
    (4,2) : manager.get_extending_min_time,
    (4,3) : manager.can_extend 
}
Example #5
0
# Group 16
# Maryam Taer & John Simpliciano
# Set 2C
# 2020-03-16

from flask import Flask, jsonify, request, make_response
from library_manager import LibraryManager
from textbook import Textbook
from ebook import eBook

app = Flask(__name__)

library = LibraryManager("Maryam")


@app.route("/library_manager/<book_type>", methods=["POST"])
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)
Example #6
0
accounts = {}
member_id = 1000

while True:
    choice = int(
        input("Hello, what do you want to do today\n\n\
		1. Create membership\n\
		2. Show list of books\n\
		3. Count of books\n\
		4. Borrow books\n\
		5. Return books\n"))

    if choice == 1:
        account_name = input("Enter your name : ")
        pin = int(input("Enter a PIN : "))
        accounts[member_id] = LibraryManager(account_name, pin, member_id)
        print(accounts[member_id])
        print(
            f"Congratulations! You are now a member and your member_id is {member_id}"
        )
        member_id += 1

    elif choice == 2:
        member_id = eval(input("Enter your Member ID : "))
        upin = int(input("Enter your PIN : "))
        if upin == accounts[member_id].pin:
            accounts[member_id].show_list_of_books()
        else:
            print("Wrong PIN, please try again. ")

    elif choice == 3:
Example #7
0
    print(
        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,
class TestLibraryManager(unittest.TestCase):
    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_constructor(self):
        """ valid constructor """
        self.assertIsInstance(self.library1, LibraryManager)

    def test_get_name(self):
        """ test if function returns correct name"""
        self.assertEqual(self.library1.get_name, 'The_library')

    def test_add_book(self):
        """ test if function adds to the inventory """
        self.library1.add_book(self.book1)

    def test_add_book_fail(self):
        """ test if function raises error when book in library """
        with self.assertRaises(LookupError):
            self.library1.add_book(self.book1)
            self.library1.add_book(self.book1)

    def test_remove_book(self):
        """ test if function removes from inventory """
        self.library1.add_book(self.book1)
        self.library1.remove_book('B20V2')

    def test_remove_book_fail(self):
        """ test if function raises error when book with no id exists """
        with self.assertRaises(KeyError):
            self.library1.remove_book('B20V2')

    def test_get_book_by_id(self):
        """ test if function returns correct book by id"""
        self.library1.add_book(self.book1)
        self.assertIsNone(self.library1.get_book_by_id('B202'))

        self.library1.add_book(self.book2)
        self.assertEqual(self.library1.get_book_by_id('A111'), self.book2)

    def test_exist_in_library(self):
        """ Test if book exist in library by id """
        self.library1.add_book(self.book1)
        self.assertIs(self.library1.exists_in_library('B20V2'), True)
        self.assertIs(self.library1.exists_in_library('B2V2'), False)

    def test_get_all_books(self):
        """ test if function returns all books in inventory """
        self.assertEqual(self.library1.get_all_books(), [])
        self.library1.add_book(self.book1)
        self.assertEqual(type(self.library1.get_all_books()), dict)

    def test_get_book_stats(self):
        """ test if function returns inventory stats """
        self.library1.add_book(self.book1)
        self.library1.add_book(self.book3)
        self.assertIsInstance(self.library1.get_book_stat(), LibraryStats)

    def test_show_book_not_borrowed(self):
        """ Test if function displays description"""
        self.library1.add_book(self.book1)
        self.library1.add_book(self.book2)
        self.library1.show_book_not_borrowed("textbook")

    def test_show_book_not_borrowed_fail(self):
        """ Test if function raises an error """
        with self.assertRaises(ValueError):
            self.library1.show_book_not_borrowed("asd")

    def test_show_available_book_category(self):
        """ test if function display correct book categories"""
        self.library1.add_book(self.book1)
        self.library1.add_book(self.book2)
        self.library1.show_available_book_category('textbook')
        self.library1.show_available_book_category('ebook')
Example #9
0
class TestLibraryManager(TestCase):
    def setUp(self):
        self.library1 = LibraryManager('The_library')

        self.mock_save_func = mock.Mock()
        self.library1._write_to_file = self.mock_save_func

        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_constructor(self):
        """ valid constructor """
        self.assertIsInstance(self.library1, LibraryManager)

    def test_read_from_file(self):
        """ tests to see if read_from_file method is called properly """
        self.librarian = LibraryManager('Maryam')
        self.assertTrue(os.path.exists('library_manager.json'))
        self.librarian1 = LibraryManager('John')
        os.remove('library_manager.json')
        self.assertFalse(os.path.exists('library_manager.json'))

    def test_get_name(self):
        """ test if function returns correct name"""
        self.assertEqual(self.library1.get_name, 'The_library')

    def test_add_book(self):
        """ test if function adds to the inventory """
        self.library1.add_book(self.book1)
        self.assertTrue(self.mock_save_func.called)

    def test_add_book_fail(self):
        """ test if function raises error when book in library """
        with self.assertRaises(LookupError):
            self.library1.add_book(self.book1)
            self.library1.add_book(self.book1)
        self.assertTrue(self.mock_save_func.called)
        self.assertEqual(self.mock_save_func.call_count, 1)

    def test_remove_book(self):
        """ test if function removes from inventory """
        self.library1.add_book(self.book1)
        self.library1.remove_book('B20V2')
        self.assertTrue(self.mock_save_func.called)
        self.assertEqual(self.mock_save_func.call_count, 1)

    def test_remove_book_fail(self):
        """ test if function raises error when book with no id exists """
        with self.assertRaises(KeyError):
            self.library1.remove_book('B20V2')

    def test_update_book(self):
        """ test the success samples of update book performance """
        self.library1.add_book(self.book1)
        self.library1.update_book('B20V2', 'Fast Read Ebooks', 'fantasy')

        self.library1.add_book(self.book3)
        self.library1.update_book('A110', 'language', 'paperback')

        self.assertTrue(self.mock_save_func.called)
        self.assertEqual(self.mock_save_func.call_count, 4)

    def test_update_book_fail(self):
        """ test the failure sample of update book performance """
        with self.assertRaises(ValueError):
            self.library1.update_book('A110', 'paperback', 'language')
            self.assertTrue(self.mock_save_func.called)
            self.assertEqual(self.mock_save_func.call_count, 1)

    def test_to_dict(self):
        """ tests the performance of converting objects to json dictionary """
        self.library1.add_book(self.book1)
        self.library1.add_book(self.book2)
        self.library1.add_book(self.book3)
        self.assertTrue(self.library1.to_dict())

    def test_get_book_by_id(self):
        """ test if function returns correct book by id"""
        self.library1.add_book(self.book1)
        self.assertIsNone(self.library1.get_book_by_id('B202'))

        self.library1.add_book(self.book2)
        self.assertEqual(self.library1.get_book_by_id('A111'), self.book2)

    def test_exist_in_library(self):
        """ Test if book exist in library by id """
        self.library1.add_book(self.book1)
        self.assertIs(self.library1.exists_in_library('B20V2'), True)
        self.assertIs(self.library1.exists_in_library('B2V2'), False)

    def test_get_all_books(self):
        """ test if function returns all books in inventory """
        self.assertEqual(self.library1.get_all_books(), [])
        self.library1.add_book(self.book1)
        self.assertEqual(type(self.library1.get_all_books()), dict)

    def test_get_book_stats(self):
        """ test if function returns inventory stats """
        self.library1.add_book(self.book1)
        self.library1.add_book(self.book3)
        self.assertIsInstance(self.library1.get_book_stat(), LibraryStats)

    def test_show_book_not_borrowed(self):
        """ Test if function displays description"""
        self.library1.add_book(self.book1)
        self.library1.add_book(self.book2)
        self.library1.show_book_not_borrowed("textbook")

    def test_show_book_not_borrowed_fail(self):
        """ Test if function raises an error """
        with self.assertRaises(ValueError):
            self.library1.show_book_not_borrowed("asd")

    def test_show_available_book_category(self):
        """ test if function display correct book categories"""
        self.library1.add_book(self.book1)
        self.library1.add_book(self.book2)
        self.library1.show_available_book_category('textbook')
        self.library1.show_available_book_category('ebook')
Example #10
0
    print(
        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,