mirror of
https://github.com/caronc/apprise.git
synced 2024-11-22 16:13:12 +01:00
92 lines
2.8 KiB
Python
92 lines
2.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
#
|
|
# Copyright (C) 2019 Chris Caron <lead2gold@gmail.com>
|
|
# All rights reserved.
|
|
#
|
|
# This code is licensed under the MIT License.
|
|
#
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
# of this software and associated documentation files(the "Software"), to deal
|
|
# in the Software without restriction, including without limitation the rights
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
# furnished to do so, subject to the following conditions :
|
|
#
|
|
# The above copyright notice and this permission notice shall be included in
|
|
# all copies or substantial portions of the Software.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
# THE SOFTWARE.
|
|
|
|
from __future__ import print_function
|
|
from apprise import cli
|
|
from apprise import NotifyBase
|
|
from click.testing import CliRunner
|
|
from apprise.Apprise import SCHEMA_MAP
|
|
|
|
|
|
def test_apprise_cli():
|
|
"""
|
|
API: Apprise() CLI
|
|
|
|
"""
|
|
|
|
class GoodNotification(NotifyBase):
|
|
def __init__(self, **kwargs):
|
|
super(GoodNotification, self).__init__()
|
|
|
|
def notify(self, **kwargs):
|
|
# Pretend everything is okay
|
|
return True
|
|
|
|
class BadNotification(NotifyBase):
|
|
def __init__(self, **kwargs):
|
|
super(BadNotification, self).__init__()
|
|
|
|
def notify(self, **kwargs):
|
|
# Pretend everything is okay
|
|
return False
|
|
|
|
# Set up our notification types
|
|
SCHEMA_MAP['good'] = GoodNotification
|
|
SCHEMA_MAP['bad'] = BadNotification
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(cli.main)
|
|
# no servers specified; we return 1 (non-zero)
|
|
assert result.exit_code == 1
|
|
|
|
result = runner.invoke(cli.main, ['-v'])
|
|
assert result.exit_code == 1
|
|
|
|
result = runner.invoke(cli.main, ['-vv'])
|
|
assert result.exit_code == 1
|
|
|
|
result = runner.invoke(cli.main, ['-vvv'])
|
|
assert result.exit_code == 1
|
|
|
|
result = runner.invoke(cli.main, [
|
|
'-t', 'test title',
|
|
'-b', 'test body',
|
|
'good://localhost',
|
|
])
|
|
assert result.exit_code == 0
|
|
|
|
result = runner.invoke(cli.main, [
|
|
'-t', 'test title',
|
|
'good://localhost',
|
|
], input='test stdin body\n')
|
|
assert result.exit_code == 0
|
|
|
|
result = runner.invoke(cli.main, [
|
|
'-t', 'test title',
|
|
'-b', 'test body',
|
|
'bad://localhost',
|
|
])
|
|
assert result.exit_code == 1
|