コード例 #1
0
def test_create_report():
    """Test expected donor data output after adding new donors and donations"""
    donor_db = {'Ryan Doe': [2000, 2000], 'Jane Doe': [10000]}
    donor_list = list(donor_db.items())
    expected_donor1 = 'Jane Doe             | 10000.00     | 1          | 10000.00       '
    expected_donor2 = 'Ryan Doe             | 4000.00      | 2          | 2000.00        '
    assert mailroom4.create_report(donor_list)[0] == expected_donor1
    assert mailroom4.create_report(donor_list)[1] == expected_donor2
コード例 #2
0
 def test_create_report(self, mock_print):
     expected = list()
     expected.append(
         "Donor Name    | Total Given   | Num Gifts | Average Gift")
     expected.append("\n")
     expected.append(
         "--------------------------------------------------------")
     expected.append("\n")
     expected.append(
         "Richard Doe     $        90.00           2  $       45.00\n")
     expected.append(
         "Jane Doe        $        25.00           1  $       25.00\n")
     mailroom4.create_report(self.donors)
     mock_print.assert_called_with('\n', ''.join(expected))
コード例 #3
0
def test_create_report():
    result = mr.create_report()
    assert result.startswith(
        "Donor Name                     | Total Given | Num Gifts | Average Gift"
    )
    assert "------------------------------------------------------------------------" in result
    assert "Ariana Grande                  |           3 |         3 | $    2,416.67" in result
コード例 #4
0
 def test_sorted_list(donor_all, donor_sorted):
     result = mailroom4.create_report(donor_all)
     print(donor_all)
     print(result)
     print(donor_sorted)
     assert result == donor_sorted
     return
コード例 #5
0
def test_create_report():
    report = m4.create_report()
    assert report[
        0] == 'Donor Name          | Total Given | Num Gifts | Average Gift'
    assert report[
        2] == 'Bill Gates           $   21935.31           3  $     7311.77'
    assert len(report) == 7
コード例 #6
0
    def test_print_report(self):
        report_text = \
         '''
Donor Name                     | Total Given  | Num Gifts | Average Gift
------------------------------------------------------------------------
Mark Zuckerberg                 $   6840.85           3    $   2280.28
Jeff Bezos                      $   1601.89           2    $    800.94
Paul Allen                      $  11100.80           1    $  11100.80
Joanne K Rowling                $  11078.02           2    $   5539.01
'''
        capturedOutput = io.StringIO()  # Create StringIO object
        sys.stdout = capturedOutput  #  and redirect stdout.
        mailroom.create_report()
        sys.stdout = sys.__stdout__  #Reset Redirect
        self.assertEqual(capturedOutput.getvalue().strip(),
                         report_text.strip())
コード例 #7
0
def test_create_report():
    title = ["Donor Name", "Total Given", "Num Gifts", "Average Gift"]
    listy = [6, "Test1", 3, 2]
    assert mailroom4.create_report({"Test1": [1, 2, 3]}) == print(
        f"{title[0]:<20} | {title[1]:>10} | {title[2]:<} | {title[3]:<}"
        "\n-------------------------------------------------------------"
        f"\n {listy[1]:<21} ${listy[0]:>12.2f}{listy[2]:>11}  ${listy[3]:>12.2f}"
    )
コード例 #8
0
def test_create_report():
    given = [('name', 1, 2, 3.45)]
    expected = (
        "\nDonor Name                | Total Given | Num Gifts | Average Gift\n"
        "------------------------------------------------------------------\n"
        "name                       $       1.00           2  $       3.45\n")
    actual = mailroom4.create_report(given)
    assert actual == expected
def test_create_report():
    """
    to run this test you have to comment out test_donor_name and test_add_donor
    """
    report = mr.create_report()
    
    assert "Luke Skywalker" in report
    assert "1851.03" in report
    assert "220.55" in report
    assert "Yoda                $        1851.03               4 $         462.76" in report
    assert report.startswith("Donor Name          |  Total Given  |   Num Gifts   |  Average Gifts")
コード例 #10
0
def test_create_report():
    report = [
        'Donor Name          | Total Given | Num Gifts | Average Gift',
        '------------------------------------------------------------',
        'Raj                  $    600060.0           2 $    300030.0',
        'alph                 $    123456.0           1 $    123456.0',
        'Paul Hollywood       $     50015.0           4 $    12503.75',
        'Jake                 $      1368.0           3 $       456.0',
        'Mary Berry           $       100.0           1 $       100.0',
        'Peter Pan            $        40.0           4 $        10.0'
    ]
    assert create_report() == report
コード例 #11
0
    def test_10_create_report(self):
        self.assertEqual(
            create_report(),
            'Donor Name             | Total Given | Num Gifts | Average Gift\n\
---------------------------------------------------------------\n\
New Donor               $      400.56           1      400.56\n\
Andrei Wasinski         $      327.00           3      109.00\n\
Ralph Anders            $      315.00           3      105.00\n\
Angelica Kisel          $      125.60           3       41.87\n\
James Hendrick          $       60.00           1       60.00\n\
Stalk Holmes            $       40.00           1       40.00\n\
Traci Johnston          $       20.00           1       20.00')
コード例 #12
0
def test_3():
    teststr = """
 ----------------------------------------------------------------------
 Donor Name               |    Total Given| Num Gifts  |   Average Gift
 ----------------------------------------------------------------------
 Albert Einstein          |$       1550.20|     2      |$        775.10
 Richard Feinman          |$        167.00|     2      |$         83.50
 Lev Landau               |$        288.00|     4      |$         72.00
 Niels Bohr               |$        150.20|     2      |$         75.10
 Ilya Prigogine           |$         25.20|     2      |$         12.60
 Aleksandr Lyapunov       |$        731.00|     1      |$        731.00
 ----------------------------------------------------------------------
"""
    assert create_report() == teststr
コード例 #13
0
    def test_5_create_report(self):
        expected = """Donor Name                    | Total Given       | Num Gifts| Average Gift      
--------------------------------------------------------------------------------
Alvaro Speedy                  $           1280.50          3 $           426.83
Andreas Bolen                  $           1220.00          2 $           610.00
Ivan Smirnoff                  $           1200.00          1 $          1200.00
Haruto Asai                    $           1042.50          2 $           521.25
Ilunga Mulungma                $            900.00          2 $           450.00
Karl Marx                      $            485.40          2 $           242.70
Richard Lionheart              $            366.80          3 $           122.27
Denis Donuts                   $             68.00          1 $            68.00
Great Gatsby                   $              0.50          1 $             0.50
"""
        actual = mlr.create_report()
        self.assertEqual(expected, actual)
コード例 #14
0
def test_check_directory_default():
    direct = mr4.ck_dir()
    print(
        "Please make sure directory (D_letter) is create to pass this condition"
    )
    assert direct is True

    #Test Create Report
    # def test_create_report():
    data = mr4.create_report()
    print(data)
    assert data == [
        ["Tom Cruise", 245.40, 2, 122.70],
        ["Alyssa Nhan", 48.32, 3, 16.11],
        ["Jessy Test", 33.00, 1, 33.00],
        ["Jin Unknown", 24.00, 2, 12.00],
        ["Tom Asdf", 1324.23, 1, 1324.23],
    ]
コード例 #15
0
 def test_create_report(self):
     """
         Test Creat Report
         - print string of report
         - Remove all the space and compare
     """
     expected = (
         '\tDonor Name                              |    Total Give |    Num Gifts |   Average Gift\n'
         '\t________________________________________ ______________   ____________   ______________\n'
         '\tKate Spade                              $           25300            6   $4216.666666666667\n'
         '\tBobbi Brown                             $           20000            4   $        5000.0\n'
         '\tMarc Jacobs                             $           15000            3   $        5000.0\n'
         '\tLulu Lemon                              $           10000            2   $        5000.0\n'
         '\tLily Maycat                             $            5000            1   $        5000.0\n'
     )
     report = mailroom4.create_report()
     assert (report.replace(' ', '').replace('\n', '').replace(
         '\t', '') == expected.replace(' ',
                                       '').replace('\n',
                                                   '').replace('\t', ''))
コード例 #16
0
    def test_create_report(self):
        """ Test assertions for create_report """

        report = mr.create_report()

        for donor in mr.mailroom_db:
            if mr.mailroom_db[donor] == []:
                total_given = ' 0'
            else:
                total_given = f'$ {sum(mr.mailroom_db[donor]):18,.2f}'
                number_of_gifts = f'{len(mr.mailroom_db[donor]):10}'
                avg_donation = f'$ {sum(mr.mailroom_db[donor])/len(mr.mailroom_db[donor]):14,.2f}'

            # So we're just checking that the generated report contains the expected information.
            # It doesn't check for spacing errors but does format the numbers.
            # I could recreate the report here locally and compare to the returned string
            # but that felt like I was just copy pasting the function to the test file.
            self.assertIn(donor, report)
            self.assertIn(total_given, report)
            self.assertIn(number_of_gifts, report)
            self.assertIn(avg_donation, report)
コード例 #17
0
 def test_11_create_report_sorting(self):
     create_report()
     self.assertEqual(mailroom4.sorted_donors, [('New Donor', [400.56]), ('Andrei Wasinski',\
     [101, 151, 75]), ('Ralph Anders', [5, 10, 300.0]), ('Angelica Kisel', [45, 25, 55.6]),\
     ('James Hendrick', [60]), ('Stalk Holmes', [40]), ('Traci Johnston', [20])])
コード例 #18
0
def test_get_donors_db():
    # test that the database function returns a full database
    donors = get_donors_db()
    assert len(donors) != 0
    assert len(create_report(donors)) == len(donors)
コード例 #19
0
 def test_correct_sums_printed_in_report(self):
     for donor, donations in self.donor_dict.items():
         assert str(donor) in mailroom4.create_report()
コード例 #20
0
def test_check_mean(donor="Paul Allen"):
    report_dict = create_report()
    dict_mean = sum(donor_dict[donor]) / len(donor_dict[donor])
    assert dict_mean == report_dict[3][3]
コード例 #21
0
def test_check_sum(donor="Mark Zuckerberg"):
    report_dict = create_report()
    dict_sum = sum(donor_dict[donor])
    assert dict_sum == report_dict[1][1]
コード例 #22
0
def test_num_donations(donor="William Gates"):
    report_dict = create_report()
    dict_num = len(donor_dict[donor])
    for i in report_dict:
        if donor in i:
            assert dict_num == (i[2])
コード例 #23
0
def test_donationsum_order():
    report_dict = create_report()
    assert report_dict[0][1] > report_dict[1][1]
    assert report_dict[0][1] > report_dict[2][1]
    assert report_dict[1][1] > report_dict[2][1]
コード例 #24
0
 def test_verify_all_donor_names_included_in_report(self):
     report_text = mailroom4.create_report()
     for name in self.donor_dict.keys():
         assert name in report_text
コード例 #25
0
 def test_8(self):        
     self.assertEqual(create_report(), (mailroom4.top + mailroom4.rows))
コード例 #26
0
def test_create_report():
    '''Print the report.'''
    assert m4.create_report() == "Report..."
def test_print_report():
    report = mr.print_report()

    assert report == print(mr.create_report())