def test_required_paths(self): with self.assertRaisesRegex(IOError, 'No such directory'): Librarian('bar') with self.assertRaisesRegex(IOError, 'not an annexed repo'): Librarian(self.repo)
def test_send_back(self): librarian = Librarian() librarian.add_book("xxxx", "b") member1 = Member() member2 = Member() # can send back a book book = member1.borrow("xxxx") self.assertEqual(book.is_borrowed, True) self.assertEqual(member1.number_book_borrowed, 1) member1.send_back("xxxx") self.assertEqual(book.is_borrowed, False) self.assertEqual(member1.number_book_borrowed, 0) # can't send back a book that is not yours book = member1.borrow("xxxx") self.assertEqual(book.is_borrowed, True) member2.send_back("xxxx") self.assertEqual(book.is_borrowed, True) member1.send_back("xxxx") self.assertEqual(book.is_borrowed, False) # can't send back a book not borrowed book = member1.send_back("xxxx") self.assertIsNone(book)
def setup(): print("generation of a librarian...") librarian = Librarian() librarian.add_book("toto", "tom") librarian.add_book("toto II", "tom") librarian.add_book("xx21", "tim") librarian.add_book("xx22", "tim") librarian.add_book("Investir dans le btc", "Elon Musk")
def test_combat(self): hero = Hero() villain = Mob() lib = Librarian() winner = lib.combat_time(hero, villain) # print "WINNER WINNER", winner, villain.is_alive(), hero.is_alive(), hero.health self.assertTrue(hero.is_alive()) self.assertEqual(hero, winner)
def main(): # connect to database connection = sql_connect() cnx = connection[0] cursor = connection[1] USER_TYPES = { 1: Librarian(cursor, cnx), 2: Administrator(cursor, cnx), 3: Borrower(cursor, cnx), } while True: user_type = entryPrompt() if user_type == 'quit': print(constants.QUIT_MESSAGE) break func = USER_TYPES.get(user_type) if not func: print(constants.INCORRECT_INPUT) else: continue_driver = func.driver() if not continue_driver: print(constants.QUIT_MESSAGE) break # close cursor and connection sql_close(cnx, cursor)
def login(): if request.method == "POST": form_data = request.form username = form_data.get("username") password = form_data.get("password") if validate(username) and validate(password): librarian = Librarian() librarian = librarian.get(username) if librarian: if bcrypt.check_password_hash(librarian.password, password): librarian.authenticated = True login_user(librarian) return redirect('/') else: flash("Incorrect Credentials.", "danger") return render_template("login.html")
def test_user_can_signup(self): guest = Guest() member = Member() librairian = Librarian() self.assertEqual(guest.id, 0) self.assertIsNotNone(member.id) self.assertIsNotNone(librairian.id)
def create_repo(repo): subprocess.check_output(['git', '-C', repo, 'init']) subprocess.check_output(['git', '-C', repo, 'annex', 'init', 'testing']) l = Librarian(repo) for i in range(3): d = os.path.join(repo, 'dir_{0}'.format(i)) os.mkdir(d) filename = os.path.join(d, 'test_%s.txt' % i) with open(filename, 'w') as f: f.write("Hello %d" % i) l.annex.git_raw('annex', 'add', filename) l.annex.git_raw('commit', '-m', 'Added %d' % i) return l
def create_or_update_fact(): librarian = Librarian.Instance() name = request.json['name'] body = request.json['body'] fact_type = request.json['fact_type'] metadata = request.json['metadata'] if request.json.has_key('fact_id') and request.json['fact_id']: fact_id = request.json['fact_id'] f = librarian.update(fact_id, name, fact_type, body, metadata) else: f = librarian.create(name, fact_type, body, metadata) return jsonify(resp=f)
def test_borrow(self): librarian = Librarian() librarian.add_book("a", "b") librarian.add_book("c", "d") librarian.add_book("e", "f") librarian.add_book("g", "h") librarian.add_book("i", "j") librarian.add_book("k", "l") member = Member() member2 = Member() # Return None when borrowing a book already borrowed member.borrow("a") self.assertIsNone(member.borrow("a")) self.assertIsNone(member2.borrow("a")) # Return None when borrowing more than 3 books member.borrow("c") member.borrow("e") self.assertIsNone(member.borrow("g")) # Return None when borrowing a non existing book self.assertIsNone(member2.borrow("fkjerfjkzen")) book = Book("xx", "xx") book2 = Book("xy", "xx") librarian.add_book("xx", "xx") librarian.add_book("xy", "xx") # Can Borrow previous_book_borrowed = member2.number_book_borrowed self.assertEqual(member2.borrow("xx").title, book.title) self.assertEqual(member2.borrow("xy").borrowed_by, member2.id) self.assertEqual(member2.number_book_borrowed, previous_book_borrowed + 2)
def user_loader(username): return Librarian().get(username)
# 山田くん from librarian import Librarian class Visitor: pass if __name__ == '__main__': # 窓口の中村くんを作る nakamura = Librarian() # 中村くんに昆虫図鑑の場所を聞く location = nakamura.searchBook("昆虫図鑑") if location == "貸出中です": print("貸出中かよ…") elif location == "その本は所蔵していません": print("なんだ、ないのか") else: print("サンキュ!")
def clone_repo(origin, repo): subprocess.check_output(['git', 'clone', origin, repo], stderr=subprocess.STDOUT) subprocess.check_output(['git', '-C', repo, 'annex', 'init', 'testing']) l = Librarian(repo) return l
def lend(self): """ Testing code of lend method """ film = Librarian("film") self.assertEqual(film.type_item, "film")
def test_librarian(self): lib = Librarian() my_mob = lib.create_mob() self.assertEqual(type(my_mob.name), str) self.assertGreater(len(my_mob.name), 0)
def test_add_book(self): librarian = Librarian() previous_length = len(LIBRARY) librarian.add_book("title", "author") self.assertEqual(previous_length + 1, len(LIBRARY))
def test_librarian_create_mob(self): lib = Librarian() mob = lib.create_mob() self.assertTrue(mob)
def get_all_facts(): librarian = Librarian.Instance() return jsonify(resp=librarian.get_all())
def rent(self): """ Testing code of rent method """ audiobook = Librarian("audiobook") self.assertEqual(audiobook.type_item, "audiobook")
import discord from discord.ext import commands from utils import load_paywalls, load_token from librarian import Librarian from rando import Creeper, Utes, RateLimiter from wordle import Wordle from collector import Collector if __name__ == "__main__": """local resource loads""" # load paywalled sites paywalled_sites = load_paywalls() # load bot token token = load_token() """bot instantiation""" # creates discord bot object (with member intents enabled to grab members) intents = discord.Intents.default() intents.members = True bot = commands.Bot(intents=intents, command_prefix="!", case_insensitive=True) # add command cogs to bot bot.add_cog(Librarian(paywalled_sites)) # archive is commands and listener bot.add_cog(RateLimiter()) # gripe at sal and aj when they fight bot.add_cog(Utes()) # calc and gif bot.add_cog(Creeper(bot)) # listen to say weird things bot.add_cog(Wordle(bot)) # calculate wordle stats bot.add_cog(Collector(bot)) # aggregate yee data # run the bot bot.run(token)
def add(self): """ This a testing code of the add method """ book = Librarian("book") self.assertEqual(book.type_item, "book") self.assertNotEqual(book.type_item, "audiobook")
def setUp(self): librarian = Librarian('Smith', 'Amy', '*****@*****.**', 'Assistant Librarian')
audiobooks = [] films = [] loop = True while (loop): print("\n----LIBRARY MANAGEMENT SYSTEM----\n") print("THE FOLLOWING ARE ITEMS IN THE LIBRARY") print("1. Book \n2. Audiobook \n3. Film") print("\nFOLLOWING ARE ACTIONS YOU CAN MAKE ON ITEMS IN THE LIBRARY: ") print("1. ADD \n2. SELL \n3. RENT \n4. LEND \n5. VIEW ITEM") action = int( input("\nPLEASE ENTER THE NUMBER OF THE OPERATION YOU WANT TO MAKE: ")) print("---------------------------------------------------------\n") if action == 1: new = Librarian() new.add(books, audiobooks, films) if action == 2: buy = Librarian() buy.sell(books, audiobooks, films) if action == 3: torent = Librarian() torent.rent(audiobooks, films) if action == 4: borrow = Librarian() borrow.lend(books) if action == 5:
def find_action(): librarian = Librarian.Instance() return jsonify(resp=librarian.get_by_type('fn'))
def view(self): """ Testing code of view method """ audiobook = Librarian("audiobook") self.assertNotEqual(audiobook.type_item, "book")
def main(): create_library = Library("Appleton", "234 Lindenwoon Place", "614-358-3224", "*****@*****.**", "Mon to Fri", "8 to 5") #initalize the library object print(create_library.name) # library name print(create_library.address) # library phone print(create_library.phone) # library phone print(create_library.email) # library email print(create_library.days_of_week) # library days of the week print(create_library.hours) #libaray hours myLinkedList = LinkedList() # initalize a linked list object librarian_one = Librarian('Ama Bates', '34', '90 Forestview Rd', '123456', '614-358-3223', '*****@*****.**') #created a library #the six book objects are created node_a = Book("Computer Science", "Jenna Carlos", "2401", "New York Lib", "2018", 1) #Book 1 node_b = Book("Introduction to Chemistry", "Jasmiine Futon", "2402", "New York Lib", "2007", 2) #Book 2 node_c = Book("General Biology", "Maria Cantos", "2403", "New York Lib", "2018", 3) #Book node_d = Book("Material Engineering", "David Leman", "2404", "New York Lib", "2019", 4) # Book 4 node_e = Book("Python Programming", "Melissa Bridges", "2405", "Midwest Publisher", 2002, 5) # Book 5 node_f = Book("Ecological Chemistry", "Anu Lu", "2406", "Midwest Publisher", 2010, 6) # Book 6 myLinkedList.add_book_to_front( node_a) #six books are addded to the book linked list myLinkedList.add_book_to_front(node_b) myLinkedList.add_book_to_front(node_c) myLinkedList.add_book_to_front(node_d) myLinkedList.add_book_to_front(node_e) myLinkedList.add_book_to_front(node_f) #the head of the list user_one = User( 'Ama', 'Password6&', '90 Forestview Rd', '123456', '614-358-3223', '*****@*****.**') #the librarian has an user account # and checks to see if the password Password6& is valid. result = user_one.ask_user( ) # asks the user to confirm their username and password if result: user_one.borrow_book( node_d ) #user borrows book(node D) and a due date is printed to the shell else: print("Wrong Username OR password" ) #prints to the shell if username and password is incorrect. myLinkedList.remove_book_location( node_a.book_location) #book(node a) is removed from the list myLinkedList.display_book( ) #the five books are printed to the shell(from node f to node b). Node f is in front/ myLinkedList.sort_author_name() #the list is sorted by author last name print("The Sorted Linked List") myLinkedList.display_book( ) #the sorted linked list is printed to the shell.
from novel import Novel from printer import Printer from librarian import Librarian novel = Novel("1984", "George Orwell") librarian = Librarian() librarian.setNovel(novel) printer = Printer() printer.setNovel(novel) # Uppdatera årtalet novel.setYear(1949) #uppdatera innehållet novel.setContent( "Freedom is the freedom to say that two plus two make four. If that is granted, all else follows." )