Example #1
0
def test_6():
    tdb = getdb()
    send_letters(tdb)
    curdir = getmydir()  # get current directory from the main program
    files = os.listdir(curdir)
    for name in tdb:
        assert "_".join(name.split()) + ".txt" in files
    def test_send_letter(self):
        mailroom4.send_letters()

        def check_file(file_name):
            state = 0
            with open(file_name, 'r') as infile:
                for line in infile.readlines():
                    if state == 0 and line.startswith('Dear '):
                        state += 1
                    elif state == 1 and line.startswith(
                            'Thank you for your current generous donations: '):
                        state += 1
                    elif state == 2 and line.startswith(
                            'This will be put to good use. '):
                        state += 1
                    elif state == 3 and line.startswith('Thanks'):
                        state += 1
            assert state == 4

        num_files = 0
        for file in os.listdir(os.getcwd()):
            if '.txt' in file:
                num_files += 1
                check_file(file)

        assert num_files > 0
 def test_send_letters(self):
     mailroom4.send_letters()
     cwd_list = os.listdir(os.getcwd())
     today = datetime.date.today()
     for donor in mailroom4.get_donors_amts():
         donor_letter = donor + today.strftime('%Y%m%d') + '.txt'
         donor_letter = donor_letter.strip('\'')
         assert donor_letter in cwd_list
Example #4
0
def test_send_letters():
    """
    This only tests that the files get created, but that's a start

    Note that the contents of the letter was already
    tested with test_gen_letter
    """

    mailroom.send_letters()

    assert os.path.isfile('Jeff Bezos.txt')
    assert os.path.isfile('William Gates.txt')
    # check that it'snot empty:
    with open('William Gates.txt') as f:
        size = len(f.read())
    assert size > 0
Example #5
0
def test_send_letters():
    destination_path = mr.send_letters()

    for donor_id in mr.donor_db:
        file_name = mr.get_destination_filename(destination_path, donor_id)
        assert os.path.isfile(file_name)

        with open(file_name) as f:
            file_text = f.read()
            assert file_text == mr.thank_you_message(
                donor_id, mr.donor_db[donor_id]["donations"][-1])
Example #6
0
    def test_input3(self):
        donor_list = [["Jennifer Miller", 145076.19],
                      ["William Rodriguez", 161585.16],
                      ["Patricia Brown", 100863.96]]
        message = "Dear {:s},\n\
    Thank you for donating ${:,.2f}.\n\
    Sincerely,\n\
    Your Local Charity"

        comp_list = []
        for item in donor_list:
            comp_list.append(message.format(*item))
        self.assertEqual(mailroom4.send_letters(), comp_list)
def test_letters():
    """Test the send_letters() function to make sure a file containing an email
    exists. Also make sure the name, number of donations, and sum of donation 
    amounts is correct."""

    # Remove all text files
    subprocess.run('del *.txt', shell=True)
    mr.send_letters()

    for donor in mr.donors:

        # Check that a file with the email contents exists for each donor
        fname = donor.replace(' ', '_') + '.txt'
        assert len(glob.glob(fname)) == 1

        # Read through the letter, and make sure the name, number of donations,
        # and total sum of donations is correct
        with open(fname, 'r') as infile:
            for line in infile:
                # Check name
                if line.startswith('Dear'):
                    letter_name = line[len('Dear'):line.find(',')]
                    letter_name = letter_name.replace(' ', '')
                    actual_name = donor.replace(' ', '')
                    assert letter_name == actual_name

                if line.startswith('Your'):
                    # Check number of donations
                    n_donations = line[len('Your'):line.find('donation')]
                    n_donations = int(n_donations.replace(' ', ''))
                    assert n_donations == len(mr.donors[donor])

                    # Check the sum of donation amounts
                    d_sum = line[line.find('$') + 1:line.find('help')]
                    d_sum = float(d_sum.replace(' ', ''))
                    assert d_sum == round(sum(mr.donors[donor]), 2)

    subprocess.run('del *.txt', shell=True)
Example #8
0
def test_7():
    expected = """Dear Aleksandr Lyapunov,

	Thank you for your very kind donation of $731.

	It will be put to very good use.

			Sincerely,
			   -The Team."""

    os.chdir(getmydir())  # change to current directory
    tdb = getdb()  # rerieve the database
    send_letters(tdb)  # generate letters and write to current directory
    fname = "Aleksandr_Lyapunov.txt"

    try:  # Catch File Open Exceptions
        file = open(fname, 'r')
        read_text = file.read()
        file.close()
    except (OSError, IOError):
        print("File Open Error for: ", fname)

    assert read_text == expected
 def test_send_letters(self):
     mr.send_letters()
     for donor in mr.donor_data.keys():
         assert os.path.isfile(donor + ".txt")
def test_send_letters():
    mailroom4.send_letters(donors2)
    for name in [*donors2]:
        name2 = name.replace(" ", "_")
        assert os.path.isfile(name2 + ".txt") is True
Example #11
0
def test_send_letters():
    mailroom.send_letters()
    assert os.path.isfile('Paul_Allen.txt')
    with open('Paul_Allen.txt', 'r') as f:
        letter = f.read()
        assert letter == "Thank you, Paul Allen, for your kind donation of $1.32"
def test_send_letters():
    mailroom.send_letters()
    for d in mailroom.donors:
        file_name = f"{d}.txt"
        assert path.isfile(file_name)
Example #13
0
def test2_send_letters():  # checks output when letters already exist
    assert mail.send_letters(dict) == None
Example #14
0
def test1_send_letters():  # checks that a file is created per donor entry
    mail.send_letters(dict)
    for root, dir, fldr in os.walk('./letters'):
        assert any(f == 'Name1.txt' for f in fldr)
        assert any(f == 'Name1.txt' for f in fldr)