Ejemplo n.º 1
0
    def write_donors(self, file_path, msg=None):
        """
        Writes the donors to a file.

        :self:      The Class
        :file_path: The path of the output file.
        :msg:       The message to tell the user when the save is successful.
        """
        content = "\n".join([str(d) for d in self.donors])
        FileHelpers.write_file(file_path, content, msg)
Ejemplo n.º 2
0
def send_to_all():
    """
    Export thank you notes for all donors.
    """
    print("\n\nLets thank everybody!")
    print(
        str("\nThis will prepare a letter to send to everyone has donated to "
            "Studio Starchelle in the past."))
    print(
        str("All letters will be saved as text (.txt) files in the default directory a "
            "different directory is specified."))

    save_dir = FileHelpers.get_user_output_path()

    if save_dir is None:
        print("\nCancelling send to all.  Returning to main menu...\n")
        return

    for donor in donor_list:
        file_path = path.join(save_dir, f"{donor.name}.txt")
        FileHelpers.write_file(file_path,
                               donor.get_email(donor_list.email_template))

    print(f"Donor letters successfully saved to: {save_dir}")
Ejemplo n.º 3
0
 def test_write_file_list(self):
     open_mock = mock.mock_open()
     with patch("builtins.open", open_mock, create=True):
         FileHelpers.write_file("./test.csv", ["stuff", "in", "a", "box"])
         open_mock.assert_any_call("./test.csv", "w")
         open_mock().writelines.assert_any_call(["stuff", "in", "a", "box"])
Ejemplo n.º 4
0
 def test_write_file_string(self):
     open_mock = mock.mock_open()
     with patch("builtins.open", open_mock, create=True):
         FileHelpers.write_file("./test.txt", "stuff in a box")
         open_mock.assert_any_call("./test.txt", "w")
         open_mock().write.assert_any_call("stuff in a box")