minor fixes lingering from #1368

pull/1232/merge
Chris Caron 2025-07-30 22:25:50 -04:00 committed by GitHub
parent b0fff4bc5b
commit 8dc7ba7bdb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 96 additions and 14 deletions

View File

@ -2,11 +2,13 @@
**Related issue (if applicable):** #<!--apprise issue number goes here-->
<!-- Have anything else to describe? Define it here; this helps build the wiki item later
-- Delete this section if you are not creating a new plugin --
## *ServiceName* Notifications
* **Source**: https://official.website.example.ca
* **Icon Support**: No
* **Message Format**: Plain Text
* **Message Limit**: ~10,000 Characters
* **Icon Support**: Yes / No
* **Message Format**: Plain Text / HTML / Markdown
* **Message Limit**: nn Characters
Describe your service here..
@ -43,8 +45,6 @@ apprise -vv -t "Title" -b "Message content" \
service://token
```
-->
## New Service Completion Status
<!-- This section is only applicable if you're adding a new service -->
* [ ] apprise/plugins/<!--new plugin name -->.py
@ -55,16 +55,18 @@ apprise -vv -t "Title" -b "Message content" \
* [ ] packaging/redhat/python-apprise.spec
- add new service into the `%global common_description`
-- END OF NEW PLUGIN SECTION - REMOVE ABOVE SECION IF NOT A NEW PLUGIN -->
## Checklist
<!-- The following must be completed or your PR can't be merged -->
* [ ] The code change is tested and works locally.
* [ ] There is no commented out code in this PR.
* [ ] No lint errors (use `tox -e lint`)
* [ ] 100% test coverage (use `tox -e minimal`)
* [ ] No lint errors (use `tox -e lint` and even `tox -e format` to autofix what it can)
* [ ] Test coverage added (use `tox -e minimal`)
## Testing
<!-- If this your code is testable by other users of the program
it would be really helpful to define this here -->
it would be really helpful to define this here -->
Anyone can help test this source code as follows:
```bash
# Create a virtual environment to work in as follows:
@ -83,5 +85,8 @@ pip install git+https://github.com/caronc/apprise.git@<this.branch-name>
apprise -t "Test Title" -b "Test Message" \
<apprise url related to ticket>
# If you have cloned the branch and have tox available to you
# the following can also allow you to test:
tox -e apprise -- -t "Test Title" -b "Test Message" \
<apprise url related to ticket>
```

View File

@ -395,7 +395,7 @@ class Apprise:
self,
body: Union[str, bytes],
title: Union[str, bytes] = "",
notify_type: common.NotifyType = common.NotifyType.INFO,
notify_type: Union[str, common.NotifyType] = common.NotifyType.INFO,
body_format: Optional[str] = None,
tag: Any = common.MATCH_ALL_TAG,
match_always: bool = True,
@ -526,6 +526,18 @@ class Apprise:
logger.error(msg)
raise TypeError(msg)
try:
notify_type = (
notify_type if isinstance(notify_type, common.NotifyType)
else common.NotifyType(notify_type.lower())
)
except (AttributeError, ValueError, TypeError):
err = (
f"An invalid notification type ({notify_type}) was "
"specified.")
raise TypeError(err) from None
try:
if title and isinstance(title, bytes):
title = title.decode(self.asset.encoding)

View File

@ -286,10 +286,36 @@ def apprise_test(do_notify):
assert a.add("good://localhost") is True
assert len(a) == 1
# Bad Notification Type is still allowed as it is presumed the user
# know's what their doing
# Bad Notification Types are not accepted
assert (
do_notify(a, title="my title", body="my body", notify_type="bad")
is False
)
# Notifications of string type are accepted
assert (
do_notify(a, title="my title", body="my body", notify_type="warning")
is True
)
# Notifications of string type are accepted
assert (
do_notify(a, title="my title", body="my body", notify_type="warning")
is True
)
# Notifications of string type are accepted
assert (
do_notify(a, title="my title", body="my body", notify_type="warning")
is True
)
# Notifications where notify_type is of the NotifyType object is the
# preferred choice
assert (
do_notify(
a, title="my title", body="my body",
notify_type=NotifyType.WARNING)
is True
)

View File

@ -2008,7 +2008,7 @@ def test_apprise_cli_plugin_loading(mock_post, tmpdir):
@notify(on="clihook")
def mywrapper(body, title, notify_type, *args, **kwargs):
# A simple test - print to screen
print("{}: {} - {}".format(notify_type, title, body))
print("{}: {} - {}".format(notify_type.value, title, body))
# No return (so a return of None) get's translated to True
@ -2016,7 +2016,7 @@ def test_apprise_cli_plugin_loading(mock_post, tmpdir):
@notify(on="clihookA")
def mywrapper(body, title, notify_type, *args, **kwargs):
# A simple test - print to screen
print("!! {}: {} - {}".format(notify_type, title, body))
print("!! {}: {} - {}".format(notify_type.value, title, body))
# No return (so a return of None) get's translated to True
"""))
@ -2286,6 +2286,37 @@ def test_apprise_cli_plugin_loading(mock_post, tmpdir):
# to the CLI
assert result.exit_code == 0
result = runner.invoke(
cli.main,
[
"--plugin-path",
join(str(tmpdir), "complex"),
"--notification-type", "invalid",
"-b",
"test body",
# our clihook that returns true
"clihook1://",
],
)
# Bad notification type specified
assert result.exit_code == 2
result = runner.invoke(
cli.main,
[
"--plugin-path",
join(str(tmpdir), "complex"),
"-b",
"-i", "warning"
"test body",
# our clihook that returns true
"clihook1://",
],
)
# Bad notification type specified
assert result.exit_code == 0
result = runner.invoke(
cli.main,
[

View File

@ -87,6 +87,13 @@ commands =
coverage run --source=apprise -m pytest tests {posargs}
coverage report
[testenv:test]
description = Run simplified tests without coverage
extras = dev,all-plugins
commands =
pip install --no-cache-dir -e ".[dev,all-plugins]"
pytest --tb=short -q {posargs}
[testenv:clean]
description = Remove build artifacts and cache files
skip_install = true
@ -96,6 +103,7 @@ allowlist_externals =
commands =
find . -type f -name "*.pyc" -delete
find . -type f -name "*.pyo" -delete
find . -type f -name "*.orig" -delete
find . -type d -name "__pycache__" -delete
rm -rf BUILD SOURCES SRPMS BUILDROOT .cache .ruff_cache .coverage-reports .coverage coverage.xml dist build apprise.egg-info .mypy_cache .pytest_cache