Skip to content

Commit

Permalink
[ntfy] Use file option to signal uploading a local file as attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Apr 21, 2023
1 parent 79ea76a commit 986fcb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion mqttwarn/services/ntfy.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def decode_jobitem(item: ProcessorItem) -> NtfyRequest:
raise TypeError(f"Unable to handle `targets` address descriptor data type `{type(item.addrs).__name__}`: {item.addrs}")

url = options["url"]
attachment_path = options.get("attachment")
attachment_path = options.get("file")

# Collect ntfy fields.
fields: DataDict = OrderedDict()
Expand Down
14 changes: 7 additions & 7 deletions tests/services/test_ntfy.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ def test_ntfy_decode_jobitem_attachment_success(attachment_dummy):
"""

item = Item(
addrs={"url": "http://localhost:9999/testdrive", "attachment": attachment_dummy.name},
addrs={"url": "http://localhost:9999/testdrive", "file": attachment_dummy.name},
)

ntfy_request = decode_jobitem(item)

assert ntfy_request.url == "http://localhost:9999/testdrive"
assert ntfy_request.options["url"] == "http://localhost:9999/testdrive"
assert ntfy_request.options["attachment"] == attachment_dummy.name
assert ntfy_request.options["file"] == attachment_dummy.name
assert ntfy_request.fields["filename"] == Path(attachment_dummy.name).name
assert ntfy_request.attachment_data.read() == b"foo"

Expand All @@ -81,14 +81,14 @@ def test_ntfy_decode_jobitem_attachment_failure(caplog):
"""

item = Item(
addrs={"url": "http://localhost:9999/testdrive", "attachment": "/tmp/mqttwarn-random-unknown"},
addrs={"url": "http://localhost:9999/testdrive", "file": "/tmp/mqttwarn-random-unknown"},
)

ntfy_request = decode_jobitem(item)

assert ntfy_request.url == "http://localhost:9999/testdrive"
assert ntfy_request.options["url"] == "http://localhost:9999/testdrive"
assert ntfy_request.options["attachment"] == "/tmp/mqttwarn-random-unknown"
assert ntfy_request.options["file"] == "/tmp/mqttwarn-random-unknown"
assert "filename" not in ntfy_request.fields
assert ntfy_request.attachment_data is None

Expand All @@ -101,15 +101,15 @@ def test_ntfy_decode_jobitem_attachment_with_filename_success(attachment_dummy):
"""

item = Item(
addrs={"url": "http://localhost:9999/testdrive", "attachment": attachment_dummy.name},
addrs={"url": "http://localhost:9999/testdrive", "file": attachment_dummy.name},
data={"filename": "testdrive.txt"},
)

ntfy_request = decode_jobitem(item)

assert ntfy_request.url == "http://localhost:9999/testdrive"
assert ntfy_request.options["url"] == "http://localhost:9999/testdrive"
assert ntfy_request.options["attachment"] == attachment_dummy.name
assert ntfy_request.options["file"] == attachment_dummy.name
assert ntfy_request.fields["filename"] == "testdrive.txt"
assert ntfy_request.attachment_data.read() == b"foo"

Expand Down Expand Up @@ -275,7 +275,7 @@ def test_ntfy_plugin_success(srv, caplog, attachment_dummy):
module = load_module_by_name("mqttwarn.services.ntfy")

item = Item(
addrs={"url": "http://localhost:9999/testdrive", "attachment": attachment_dummy.name},
addrs={"url": "http://localhost:9999/testdrive", "file": attachment_dummy.name},
title="⚽ Message title ⚽",
message="⚽ Notification message ⚽",
data={"priority": "high", "tags": "foo,bar,äöü", "click": "https://example.org/testdrive"},
Expand Down

0 comments on commit 986fcb6

Please sign in to comment.