class TestPhonebook(unittest.TestCase): def setUp(self): """Initialize variables that will be used""" self.contact1 = Phonebook() def test_add_contact(self): """Test whether user can add a contact""" self.contact1.add_contact("John Doe", 123) self.assertEqual(len(self.contact1.contact_phone_list), 1) def test_update_contact(self): """Test whether user can update contact""" contact = self.contact1.update_contact("John Doe", 345) self.assertEqual(contact, 345) def test_view_contact(self): """Test whether user can view contact""" self.contact1.update_contact("John Doe", 345) phone = self.contact1.contact_phone_list["John Doe"] self.assertEqual(phone, 345) def test_delete_contact(self): """Test whether user can delete contact""" self.contact1.add_contact("John Doe", 123) self.contact1.delete_contact('John Doe') self.assertEqual(len(self.contact1.contact_phone_list), 0) def test_delete_if_no_contact(self): """Test whether user can delete contact""" with self.assertRaises(KeyError): self.contact1.delete_contact('John Doe') if __name__ == "__main__": unittest.main(exit=False)
def main(): phone_book = Phonebook() phone_book.add_contact( Contact('Дмитрий', 'Дюков', '+70000000000', email='*****@*****.**', telegram='@dukov', email2='*****@*****.**', facebook='DyukovDmitry')) phone_book.add_contact( Contact('Эмануил', 'Виторган', '+70000000001', email='*****@*****.**', telegram='@emsvit')) phone_book.add_contact( Contact('Тюльпек', 'Ганджубасов', '+70000000002', favorite=True, email='*****@*****.**', telegram='@gandzhubasov')) phone_book.add_contact( Contact('Курмультук', 'Ильясов', '+70000000003', favorite=True, email='*****@*****.**', telegram='@mudeni')) phone_book.add_contact( Contact('Зугинтульба', 'Иванова', '+70000000004', favorite=True, email='*****@*****.**', telegram='@eultubey')) print( '=====================================Печать всех =====================================================' ) phone_book.print_contacts() print( '=====================================Удаление по номеру ==============================================' ) phone_book.delete_contact('+70000000000') print( '=====================================Показать избраных ===============================================' ) phone_book.print_favorite() print( '=====================================Поиск по Имени и Фамилии ========================================' ) phone_book.search_contact('Тюльпек', 'Ганджубасов')
class PhonebookDeleteTestCase(unittest.TestCase): def setUp(self): self.phonebook = Phonebook() self.contact = self.phonebook.add_contact("Redlion", "0715846586") def test_delete_contact(self): resp = self.phonebook.delete_contact("Redlion") self.assertEqual(resp["message"], "Contact successfully deleted!!") def test_view_contact_deleted(self): self.phonebook.delete_contact("Redlion") resp = self.phonebook.view_contact("Redlion") self.assertEqual(resp["message"], "The contact is missing!!")
from contact import Contact from phonebook import Phonebook if __name__ == '__main__': jhon = Contact('Jhon', 'Smith', '+71234567809', telegram='@jhony', email='*****@*****.**') thomas = Contact('Thomas', 'Anderson', '+3123398810902', favourite_contact=True, telegram='@Neo', email='*****@*****.**') contacts = Phonebook('Моя телефонная книга') contacts.add_contact(jhon) contacts.add_contact(thomas) contacts.view() contacts.search_favourite() contacts.main_search('Thomas', 'Anderson') contacts.delete_contact("+71234567809") contacts.view()