From 8a226167c243543df4f4235b7377ba4ed6c8d96b Mon Sep 17 00:00:00 2001 From: Tim van der Heijden Date: Fri, 28 Apr 2023 13:20:46 +0200 Subject: [PATCH 1/3] Fix files as list to dict --- notify/mail.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notify/mail.py b/notify/mail.py index fad2921..6d5e324 100644 --- a/notify/mail.py +++ b/notify/mail.py @@ -35,7 +35,7 @@ def __init__( e-mail address to add as cc bcc: str e-mail address to add as bcc - files: str, list + files: str, dict Path(s) to file(s) to add as attachment df: pd.DataFrame dataframe that needs to be added to the HTML message. @@ -48,7 +48,7 @@ def __init__( self.bcc = bcc.replace(";", ",") if bcc is not None else bcc self.subject = subject self.message = message - self.files = [files] if isinstance(files, str) else files + self.files = {files.split("/")[-1]: files} if isinstance(files, str) else files self.df = df self.graph = Graph() self.graph.ensure_graph_for_app_only_auth() From 57423a481b70ba9880e9712d45f15ed4d8f3e923 Mon Sep 17 00:00:00 2001 From: Tim van der Heijden Date: Fri, 28 Apr 2023 13:21:19 +0200 Subject: [PATCH 2/3] Fix files as list to dict --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 17ca7e3..76a65d8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = zyppnotify -version = 0.5.0 +version = 0.6.0 author = Zypp author_email = hello@zypp.io description = Send users notifications through various platforms From e9ec3e9bd27d1dffefc458e64d98322cac02bd81 Mon Sep 17 00:00:00 2001 From: Tim van der Heijden Date: Fri, 28 Apr 2023 17:29:43 +0200 Subject: [PATCH 3/3] Add test --- notify/tests/test_email.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/notify/tests/test_email.py b/notify/tests/test_email.py index 933359c..4478853 100644 --- a/notify/tests/test_email.py +++ b/notify/tests/test_email.py @@ -74,6 +74,22 @@ def test_send_file(): assert response.status_code == 202 +def test_send_multiple_files(): + message = "This is a test from notify for multiple files" + subject = "Test Notify multiple files" + core_file_name = "2010 car efficiency" + file_name_1 = f"{core_file_name}_1.csv" + file_name_2 = f"{core_file_name}_2.csv" + file_path = os.path.join("notify", "tests", "data", f"{core_file_name}.csv") + response = NotifyMail( + to=f"{os.environ.get('TEST_EMAIL_1')}", + subject=subject, + message=message, + files={file_name_1: file_path, file_name_2: file_path}, + ).send_email() + assert response.status_code == 202 + + def test_send_file_from_storage(): message = "This is a test from notify" subject = "Test Notify file Azure Storage"