Exemplo n.º 1
0
def test_add_phone():
    """Test-func for <add_phone> function"""
    address_book = AddressBook()
    name, phone = (
        Name('Romanskyy Andrey').name, Phone('380675119811').phone)
    record = Record()
    record.add_contact_phonenumb(phone)
    address_book.add_record(name, record.__dict__)

    datacase_one = ('Zivenko Kos', '380675119812')
    result_one = (
        "\n\tThe contact <Zivenko Kos> was added to address book with phone <380675119812>."
    )

    datacase_two = ('Romanskyy Andrey', '380675119811')
    result_two = (
        "\n\tThe contact's data is already in address book."
    )

    datacase_three = ('Romanskyy Andrey', '380675119822')
    result_three = (
        "\n\tThe phone <380675119822> for contact <Romanskyy Andrey>\n\t\
        was successfully added to address book."
    )

    assert add_phone(address_book, datacase_one) == result_one
    assert add_phone(address_book, datacase_two) == result_two
    assert add_phone(address_book, datacase_three) == result_three
Exemplo n.º 2
0
def test_add_record():
    """Test-func for <add_record> method"""
    assert AddressBook().add_record(
        'Andrey Romanskyy', '380575119811'
    ) == {'Andrey Romanskyy': '380575119811'}

    assert AddressBook().add_record(
        'Andrey Romanskyy', '380575119811'
    ) != 'Andrey Romanskyy=380575119811'
Exemplo n.º 3
0
def test_change_existing_phone():
    """Test-func for <change_existing_phone> method"""
    address_book = AddressBook()
    name, phone = (
        Name('Romanskyy Andrey').name, Phone('380675119811').phone)
    record = Record()
    record.add_contact_phonenumb(phone)
    address_book.add_record(name, record.__dict__)

    data = ('Romanskyy Andrey', '380675119811')
    assert change_existing_phone(address_book, data) == (
        "\n\t<380675119811> for contact <Romanskyy Andrey>\n\twas changed for <380675119812>."
    )
Exemplo n.º 4
0
def test_change_error():
    """Test-func for <change_existing_phone> method"""
    address_book = AddressBook()
    name, phone = (
        Name('Romanskyy Andrey').name, Phone('380675119811').phone)
    record = Record()
    record.add_contact_phonenumb(phone)
    address_book.add_record(name, record.__dict__)

    data = ('Romanskyy Andrey', '380675119811')

    assert change_existing_phone(address_book, data) == (
        '\n\tEnter correct number.'
    )
Exemplo n.º 5
0
def test_exit():
    """Test-func for <exit> func"""
    address_book = AddressBook()
    name, phone = (
        Name('Romanskyy Andrey').name, Phone('380675119811').phone)
    record = Record()
    record.add_contact_phonenumb(phone)
    address_book.add_record(name, record.__dict__)

    with pytest.raises(SystemExit) as pytest_exit:
        save_and_exit(address_book)
    assert pytest_exit.type == SystemExit
    assert pytest_exit.value.code == (
        "\n\tThe address book was saved to <data.bin> file.\n\tGood bye!"
    )
Exemplo n.º 6
0
def test_show_one_contact_data():
    """Test-func for <show_one_contact_data> function"""
    address_book = AddressBook()
    name, phone = (
        Name('Romanskyy Andrey').name, Phone('380675119811').phone)
    record = Record()
    record.add_contact_phonenumb(phone)
    address_book.add_record(name, record.__dict__)

    result = '\n\tThe contact Romanskyy Andrey has\
        \n\tbirthday info - None\
        \n\tphone/s - 380675119811.\n'

    wrong_result = None

    assert show_one_contact_data(address_book) == result
    assert show_one_contact_data(address_book) == wrong_result
Exemplo n.º 7
0
def main():
    """Run full procedure of work with addressbook
    """
    print("""
    WORKING INSTRUCTION

    To continue working you have following commands:
        Enter <hello> - to load address book.

    After entering initial comand you have following commands:

        <add name surname phone number> BLANK SIGNS REQUIRED
        (format example - add Name Surname 38XXXXXXXXXX),

        <change name surname phone number> BLANK SIGNS REQUIRED
        (format example - change Name Surname 38XXXXXXXXXX),

        <phones name surname> BLANK SIGNS REQUIRED
        (format example - phones Name Surname),

    To exit enter one of the following commands:
        <good bye>, <close>, <exit>, <.>

    To show phon book enter <show all>
    """)

    initial_user_comand = input("\n\tWaitting for your comand: ").casefold()

    while not initial_user_comand == "hello":
        print("\n\tIn order to work with address book enter <Hello>")
        initial_user_comand = input(
            "\n\tWaitting for your comand: ").casefold()

    path = Path("data.bin")
    path_exists = path.is_file()

    address_book = deserialize_data(path) if path_exists else AddressBook()
    if path_exists:
        print(
            f"\n\tYou address book has been restored from <{path}> file,\n\tand it's ready to work."
        )

    else:
        print("\n\tCongratulation, you have created new address book!")

    while True:

        user_command = input("\nWaitting for your comand: ")
        user_command = user_command.casefold()

        command, data = parsing_user_input(user_command)
        print(command, data)

        info = handler_func(command, address_book, data)
        print(info)
Exemplo n.º 8
0
def test_show_all_contacts():
    """Test-func for <show_all_contacts> func"""
    address_book = AddressBook()

    name_one, phone_one = (
        Name('Romanskyy Andrey').name, Phone('380675119811').phone)
    record_one = Record()
    record_one.add_contact_phonenumb(phone_one)
    address_book.add_record(name_one, record_one.__dict__)

    name_two, phone_two = (
        Name('Romanskyy Andrey').name, Phone('380675119811').phone)
    record_two = Record()
    record_two.add_contact_phonenumb(phone_two)
    address_book.add_record(name_two, record_two.__dict__)

    # use <n>
    assert show_all_contacts(address_book) == (
        '\n\tContinue your work with commands.'
    )

    # use <y>
    with pytest.raises(StopIteration) as pytest_si:
        show_all_contacts(address_book)
    assert pytest_si.type == StopIteration
Exemplo n.º 9
0
def test_handler_func():
    """Test-func for <handler_func> function"""
    address_book = AddressBook()
    name, phone = (
        Name('Romanskyy Andrey').name, Phone('380675119811').phone)
    record = Record()
    record.add_contact_phonenumb(phone)
    address_book.add_record(name, record.__dict__)

    show_command = 'show all'
    show_result = "\n\tYou have seen all contact's info."

    data = ('Nata Bazan', '380675554433')
    add_command = 'add'
    add_result = '\n\tThe contact <Nata Bazan> was added to address book with phone <380675554433>.'

    assert handler_func(show_command, address_book, data) == (
        '\n\tContinue your work with commands.'
    )
    assert handler_func(show_command, address_book, data) == show_result
    assert handler_func(show_command, address_book, data) == show_result
    assert handler_func(add_command, address_book, data) == add_result
Exemplo n.º 10
0
def test_search_contacts():
    """Test-func for <search_contacts> function"""
    address_book = AddressBook()
    name, phone = (
        Name('Romanskyy Andrey').name, Phone('380675119811').phone)
    record = Record()
    record.add_contact_phonenumb(phone)
    address_book.add_record(name, record.__dict__)

    contact_data = 'romans'
    wrong_data = 'some'

    result = '\n\tThe contact Romanskyy Andrey has\
        \n\tbirthday info - None\
        \n\tphone/s - 380675119811.\n'

    assert address_book.search_contacts(contact_data) == result
    assert address_book.search_contacts(wrong_data) != result
    assert address_book.search_contacts(wrong_data) is None