def test_thank_you_text():
    test_donor = Donor("Kristy Martini", 0, 1, 1000)
    send_thank_you(test_donor)
    output_text = []
    output_text.append("Thank you Kristy Martini for your charitable gift to our organization.\n")
    output_text.append("We could not operate without the generosityy of donors like yourself.\n")
    output_text.append("Your generous gift of $1000 will allow us to continue to serve our community in the hopes of a better world.\n")
    output_text.append("   -Kristy Martini")
    output_file = os.path.join(os.getcwd(), "Kristy Martini.txt")
    with open(os.path.join(output_file), 'r') as f:
        lines = f.readlines()
    for i in range(4):
        assert output_text[i] == lines[i]
示例#2
0
def test_send_thank_you_print_letter_no_write(capsys):
    '''
    Data file = test_send_thank_you_donor_existing_amount_no_write.txt
    Testing that the thank you letter is printed, (look for the donor
    in the console output)
    '''
    orig_stdin = sys.stdin
    with open("test_send_thank_you_donor_existing_amount_no_write.txt") \
            as sys.stdin:
        mailroom.send_thank_you()
    sys.stdin = orig_stdin
    out, err = capsys.readouterr()
    sys.stdout.write(out)
    donor = list(mailroom.donor_db.keys())
    assert out.find(donor[0])
示例#3
0
def test_send_thank_you_long_input():
    assert send_thank_you("The Great Leader of the"
                          " Azerothian people", 3.47) == ('Dear The Great'
                                                          ' Leader of the'
                                                          ' Azerothian people'
                                                          ', we wanted to'
                                                          ' say thank you for'
                                                          ' your generous'
                                                          ' donation of'
                                                          ' $3.47!')
示例#4
0
def test_send_thank_you_write_letter_to_file():
    '''
    Test if the thank you letter is written to a file
    Data file = test_send_thank_you_write_letter_to_file
                First line = existing donor
                Second line = donation amount
                Third line = y, (no quotes)
    '''
    orig_stdin = sys.stdin
    with open("test_send_thank_you_write_letter_to_file.txt") \
            as f:
        donor = f.readline().strip()
    if os.path.isfile("./" + donor + ".txt"):
        os.remove("./" + donor + ".txt")
    with open("test_send_thank_you_write_letter_to_file.txt") \
            as sys.stdin:
        mailroom.send_thank_you()
    sys.stdin = orig_stdin
    result = os.path.isfile("./" + donor + ".txt")
    assert result is True
示例#5
0
def test_send_thank_you_donor_existing_menu():
    ''' Simulate a user input of an existing donor.
    After the expected result simulate a user input of 'menu'.
    This will cause the function to return.
    :Data file = test_send_thank_you_donor_existing_menu.txt in
                 current working directory
    '''
    orig_stdin = sys.stdin
    with open("test_send_thank_you_donor_existing_menu.txt") as sys.stdin:
        result = mailroom.send_thank_you()
    sys.stdin = orig_stdin
    assert result is None
示例#6
0
def test_send_thank_you_donor_existing_amount_no_write():
    '''Simulate a user input of an existing donor.
    Simulate a user input of a donation amount.
    :Data file = test_send_thank_you_donor_existing_amount_no_write.txt
                 in current working directory
    '''
    orig_stdin = sys.stdin
    with open("test_send_thank_you_donor_existing_amount_no_write.txt") \
            as sys.stdin:
        result = mailroom.send_thank_you()
    sys.stdin = orig_stdin
    with open("test_send_thank_you_donor_existing_amount_no_write.txt") \
            as f:
        donor = f.readline()
        donor = donor.strip()
        amount = f.readline()
    assert mailroom.donor_db[donor][-1] == float(amount)
    assert result is None
示例#7
0
def test_send_thank_you_list_menu(capsys):
    '''
    Simulate user input of 'list' and the 'menu', (to force a return)
    :data - a text file
            in the current directory, (test_send_thank_you_list_inputs.txt),
            is used as input data.
            The value that the user would input is simulated
            by making a one entry into the file per user input.
            Example: for a user input of 'list', enter 'list'
            on the first line, (no quotes).
            Enter 'menu' on the second line for the second user
            input, (this also forces a return).
    Modified from a solution to the 'input' issue on stackoverflow.
    Seems to work.
    '''
    orig_stdin = sys.stdin
    with open("test_send_thank_you_list_inputs.txt") as sys.stdin:
        result = mailroom.send_thank_you()
    sys.stdin = orig_stdin
    test_print_donors(capsys)
    assert result is None
示例#8
0
def test_send_thank_you():
    letter = mail.send_thank_you("LeBron James")

    assert letter.startswith("Hi LeBron James,")
def test_send_thank_you():
    test_donor = Donor("Kristy Martini", 0, 1, 1000)
    send_thank_you(test_donor)
    output_file = os.path.join(os.getcwd(), "Kristy Martini.txt")
    assert os.path.exists(output_file)
示例#10
0
def test_send_thank_you(parm, parm2, result):
    """Testsing send tahbk_you function"""
    from mailroom import send_thank_you
    assert send_thank_you(parm, parm2) == result
示例#11
0
def test_send_thank_you_valid_input():
    assert send_thank_you("Angelina Jolie", 3.47) == ('Dear Angelina Jolie,'
                                                      ' we wanted to say thank'
                                                      ' you for your generous'
                                                      ' donation of $3.47!')
def test_send_thank_you():
    # An I/O error occurs because the function prompts for donor name,
    # donor list display, or quitting
    with pytest.raises(IOError):
        m.send_thank_you()