def dialog(): """dialog with user""" phone_book = sqlcontacts.PhoneBook() while True: print("""What do you want to do? c - create r - read u - update d - delete q - quit""") try: action = input("?").lower() if action == 'c': name = input("Input new contact name \n") phone = input("Input the phone \n") phone_book.create(name, phone) elif action == 'r': name = input("Input the contact name \n") print(phone_book.read(name)) elif action == 'u': name = input("Input the contact name \n") phone = input("Input new phone \n") phone_book.update(name, phone) elif action == 'd': name = input("Input the contact name for deleting \n") phone_book.delete(name) elif action == 'q': break else: print("incorrect input") except KeyError: print("incorrect input")
def main(): ''' :return: ''' while True: print("""What do you want to do? c - create r - read u - update d - delete q - quit """) phone_book = sqlcontacts.PhoneBook() action = input("?").lower() if action == 'c': name = input("Input name:") number = input("Input number") print(phone_book.create(name, number)) if action == 'r': name = input("Input name:") print(phone_book.read(name)) if action == 'u': name = input("Input name:") number = input("Input number") print(phone_book.update(name, number)) if action == 'd': name = input("Input name:") print(phone_book.delete(name)) if action == 'q': break
def test_create(): """ :return: """ phone_b = sqlcontacts.PhoneBook() phone_b.create("Bill", 911) assert phone_b.read('Bill') == 911
def test_delete(): """ :return: """ phone_b = sqlcontacts.PhoneBook() phone_b.create("Bill", 911) phone_b.delete("Bill") with pytest.raises(KeyError): phone_b.read('Bill')
def user_interface(): """ Define options :return: """ while True: print("""What do you want to do? c - create r - read u - update d - delete q - quit """) book = sqlcontacts.PhoneBook() action = input().lower() if action == 'c': print("Want to add a new contact? Please, print a name: ") name = input("Print name here: ") print("Now, please, fill the number: ") number = input("Print number here: ") book.create(name, number) print('Thank you!') elif action == 'r': print("Find a contact? Please, print a name: ") name = input("Print name here: ") book.read(name) print('Thank you!') elif action == 'u': print("OK. Please, print a contact name to update: ") name = input("Print name here: ") print("Now, please, update the number: ") number = input("Print number here: ") book.update(name, number) print('Thank you!') elif action == 'd': print("Contact is dead? Sorry... Please, print a name to delete: ") name = input("Print name here: ") book.delete(name) print('Thank you!') elif action == 'q': break elif action not in 'crudq': print('There is no such option, please try again!') continue
def interface(): """Phone interface""" # phone_book = contacts.PhoneBook() phone_book = sqlcontacts.PhoneBook() while True: print("""What do you want to do? c - create r - read u - update d - delete q - quit """) funcs = {'c': create, 'r': read, 'u': update} action = input("?").lower() if action == 'q': break funcs.get(action, 'You enter wrong command')(phone_book)
def main(): """main function""" phone_book = sqlcontacts.PhoneBook() while True: print("""What do you want to do? c - create r - read u - update d - delete q - quit """) action = input("?").lower() try: if action == 'q': break if action == 'c': name = input("Name: ") number = input("Number: ") phone_book.create(name, number) print("Added") elif action == "r": name = input("Name: ") print(phone_book.read(name)) elif action == "u": name = input("Name: ") number = input("Number: ") phone_book.update(name, number) print("Updated") elif action == "d": name = input("Name: ") phone_book.delete(name) print("Deleted") else: print("Incorrect action.Try again") except KeyError: print("Number not in phone book or number must be unique") except ValueError: print("Invalid input")
def dialog(): """dialog with user""" phb = sqlcontacts.PhoneBook() while True: print("""What do you want to do? c - create r - read u - update d - delete q - quit """) action = input("Choose:").lower() if action == 'q': break if action == 'c': try: name = input("User name: ") phone = input("User phone: ") phb.create(name, phone) except KeyError: print("Name must be unique!\n") else: print("Done!\n") elif action == 'r': try: name = input("User name: ") print(f"Phone number: {phb.read(name)}") except KeyError: print("This name is not present in list\n") elif action == "u": name = input("User name: ") phone = input("Phone: ") phb.update(name, phone) print("Successful!\n") elif action == "d": name = input("User name: ") phb.delete(name) print("Successful!\n")
import pytest import sqlcontacts p = sqlcontacts.PhoneBook() def test_create(): p.create("Bill", 911) assert p.read('Bill') == 911 p.delete("Bill") def test_update(): p.create("Bill", 911) p.update("Bill", 112) assert p.read('Bill') == 112 p.delete("Bill") def test_delete(): p.create("Bill", 911) p.delete("Bill") with pytest.raises(KeyError): p.read('Bill')
def test_create(): p = sqlcontacts.PhoneBook() p.create("Bill", 911) assert p.read('Bill') == 911
def test_delete(): p = sqlcontacts.PhoneBook() p.create("Bill", 911) p.delete("Bill") with pytest.raises(KeyError): p.read('Bill')
def test_update(): p = sqlcontacts.PhoneBook() p.create("Bill", 911) p.update("Bill", 112) assert p.read('Bill') == 112