Skip to content

Commit

Permalink
Allow overriding backend in it's own config, fixes #30
Browse files Browse the repository at this point in the history
  • Loading branch information
dschep committed Mar 16, 2016
1 parent f8c7521 commit af97368
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ntfy/__init__.py
Expand Up @@ -24,6 +24,11 @@ def notify(message, title, config=None, **kwargs):
ret = 0

for backend in config['backends']:
backend_config = config.get(backend, {})
backend_config.update(kwargs)
if 'backend' in backend_config:
backend = backend_config['backend']

try:
module = import_module('ntfy.backends.{}'.format(backend))
except ImportError:
Expand All @@ -33,9 +38,6 @@ def notify(message, title, config=None, **kwargs):
exc_info=True)
continue

backend_config = config.get(backend, {})
backend_config.update(kwargs)

try:
module.notify(message=message, title=title, **backend_config)
except (SystemExit, KeyboardInterrupt):
Expand Down
19 changes: 19 additions & 0 deletions tests/ntfy_test/__init__.py
@@ -1 +1,20 @@
from unittest import TestCase

from mock import patch

from ntfy import notify

from . import cli


class OverrideBackendTestCase(TestCase):
@patch('requests.post')
def test_runcmd(self, mock_post):
ret = notify('message', 'title', {
'backends': ['foobar'],
'foobar': {
'backend': 'pushover',
'user_key': 't0k3n',
}
})
self.assertEqual(ret, 0)

0 comments on commit af97368

Please sign in to comment.