Skip to content

Add cancel_by_tag support - #33

Open
irstmon wants to merge 1 commit into
scolby33:developfrom
irstmon:develop
Open

Add cancel_by_tag support#33
irstmon wants to merge 1 commit into
scolby33:developfrom
irstmon:develop

Conversation

@irstmon

@irstmon irstmon commented Mar 26, 2026

Copy link
Copy Markdown

Add cancel_by_tag support

What

Adds a new cancel_by_tag(tag) method to PushoverAPI, implementing the
[cancel_by_tag receipts endpoint](https://pushover.net/api/receipts#cancel-by-tag)
of the Pushover API.

Why

The Pushover API allows attaching arbitrary tags to emergency-priority messages
via the tags parameter. These tags can be used to cancel all matching receipts
at once - without needing to store individual receipt IDs. This is useful for
applications like monitoring systems that may send many related emergency
notifications (e.g. per-server alerts) and want to cancel them all at once when
an issue is resolved.

Usage

p = PushoverAPI("your_app_token")

# Send emergency message with a tag (tags parameter is passed through as-is)
p.send_message(
    "user_token",
    "Server mail01 is down",
    priority=2,
    retry=60,
    expire=3600,
    tags="mail01,rack-a,chicago",
)

# Later: cancel all receipts tagged "chicago"
p.cancel_by_tag("chicago")

Changes

src/pushover_complete/pushover_api.py

Added cancel_by_tag(tag) method after cancel_receipt(). It follows the
exact same pattern as the existing cancel_receipt() method - a single call
to _generic_post with the tag as the URL parameter:

POST https://api.pushover.net/1/receipts/cancel_by_tag/{tag}.json

tests/PushoverAPI/test_PushoverAPI.py

Added two new tests after the existing receipt cancel tests:

  • test_PushoverAPI_cancels_by_tag - verifies a successful cancel call
  • test_PushoverAPI_raises_error_on_bad_tag_cancel - verifies that a
    BadAPIRequestError is raised when the tag has no active receipts

The new tests import receipt_cancel_by_tag_callback from responses_callbacks
and TEST_TAG from constants, following the exact same structure as the
existing receipt cancel tests.

tests/responses_callbacks.py

Added receipt_cancel_by_tag_callback to mock the
/receipts/cancel_by_tag/{tag}.json endpoint. It validates the app token and
checks that the tag in the URL matches TEST_TAG, returning a 400 error
otherwise. Also added TEST_TAG to the imports from tests.constants.

tests/constants.py

Added one new constant:

TEST_TAG = "server-down"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant