Exemplo n.º 1
0
def add_contact(phone_book: PhoneBook):
    name = input("Enter name")
    contact = Contact(name)

    contact.personal_phone = input("Enter PersonalPhone")
    contact.phone = input("Enter Phone")
    contact.description = input("Enter Description")

    phone_book.add_contact(contact)

    print("Contact successfully added")
Exemplo n.º 2
0
    def menu_entries():
        pb = PhoneBook(PHONE_BOOK_NAME)
        print(LINE)
        print('Телефонная книга 0.1')

        while True:
            print(LINE)
            print('Вводите команду, h - справка, q - выход')

            choose = input()

            if choose.lower() in ['a']:
                pb.add_contact()
            elif choose.lower() in ['e']:
                name = input('Какую запись вы хотите редактировать (ИМЯ): ').title()
                pb.edit_contact(name)
            elif choose.lower() in ['s']:
                name = input('Какую запись вы хотите найти (ИМЯ): ').title()
                pb.search_contact(name)
            elif choose.lower() in ['d']:
                name = input('Какую запись вы хотите удалить (ИМЯ): ').title()
                res = pb.del_contact(name)
                if res:
                    print(name, ' - запись была успешно удалена')
                else:
                    print('ОШИБКА: Имени нет в базе')
            elif choose.lower() in ['l']:
                pb.list()
            elif choose.lower() in ['h']:
                print('''\
                МЕНЮ КОМАНД:
    ======================================
    a(Add)      - Добавить запись в книгу
    e(Edit) -   - Редактирование записи
    s(Search)   - Поиск контакта
    d(Delete)   - Удаление контакта
    h(Help)     - Показать эту справку
    l(List)     - Отобразить все контакты отсортированные по алфавиту
    q(Quit)     - Выход из программы''')
            elif choose.lower() in ['q']:
                print('Завершение работы программы')
                pb.save()
                raise SystemExit
            else:
                print('Команда не распознана')
Exemplo n.º 3
0
class TestPhoneBook(unittest.TestCase):
    def setUp(self):
        '''initialization'''
        self.initPhoneBook = PhoneBook()

    def test_add_contact(self):
        '''Test if contact is added'''
        response = self.initPhoneBook.add_contact('Dalin', 712876245)
        self.assertEqual(response, 'contact added')

    def test_phone_number_exists(self):
        '''     
            Create new contact and see if number entries
        '''
        self.initPhoneBook.add_contact('Nancy', 712872452)

        response = self.initPhoneBook.phone_number_exists(712872452)
        self.assertTrue(response)

    def test_show_all_contacts(self):
        '''
            Test to see if all contacts are shown
            Create some contacts before we search for them
        '''
        self.initPhoneBook.add_contact('Nancy', 712872452)
        self.initPhoneBook.add_contact('Mwangi', 712876245)

        response = self.initPhoneBook.show_all_contacts()
        self.assertEqual(response, [{
            'phone': 712872452,
            'id': 1,
            'name': 'Nancy'
        }, {
            'phone': 712876245,
            'id': 2,
            'name': 'Mwangi'
        }])

    def test_check_phone_number_is_int(self):
        '''Test if phone number is integer'''
        response = self.initPhoneBook.add_contact('Dalin', 'adfi')
        self.assertEqual(response, 'not a number')

    def test_phone_number_length_is_not_nine(self):
        response = self.initPhoneBook.add_contact('Dalin', 3456789)
        self.assertEqual(response, 'number short or long')

    def test_search_contact_name(self):
        '''Create some contacts before we search for them'''
        self.initPhoneBook.add_contact('Mike', 712872452)
        self.initPhoneBook.add_contact('Mwangi', 712876245)

        response = self.initPhoneBook.search_contact_name('Mwangi')
        self.assertTrue(response)

    def test_search_contact_phone(self):
        '''Create some contacts before we search for them'''
        self.initPhoneBook.add_contact('Mike', 712872452)
        self.initPhoneBook.add_contact('Mwangi', 712876245)

        response = self.initPhoneBook.search_contact_phone(712876245)
        self.assertEqual(response, [{
            'id': 2,
            'name': 'Mwangi',
            'phone': 712876245
        }])

    def test_contact_does_not_exist(self):
        '''Create some contacts before we search for them'''
        self.initPhoneBook.add_contact('Mike', 712872452)
        self.initPhoneBook.add_contact('Mwangi', 712876245)

        response = self.initPhoneBook.search_contact_name('Nancy')
        self.assertFalse(response)

    def test_edit_phone_number(self):
        '''
            Create a contact before we can edit it
            Edit function takes in the name of the person and the new phone number
        '''
        self.initPhoneBook.add_contact('Ann', 712876245)

        response = self.initPhoneBook.edit_phone_number('Ann', 765356999)
        self.assertEqual(response, [{
            'id': 1,
            'name': 'Ann',
            'phone': 765356999
        }])

    def test_delete_contact(self):
        '''
            Create a contact that we will delete
        '''
        self.initPhoneBook.add_contact('Ann', 712676245)

        response = self.initPhoneBook.delete_contact('Ann')
        self.assertEqual(response, 'contact deleted')