# Path: ntfy/cli.py
# def main(cli_args=None):
#     if cli_args is not None:
#         args = parser.parse_args(cli_args)
#     else:
#         args = parser.parse_args()
# 
#     logging.config.dictConfig({
#         'version': 1,
#         'disable_existing_loggers': False,
#         'formatters': {
#             'default': {
#                 'format': '%(levelname)s: %(message)s'
#             },
#         },
#         'handlers': {
#             'default': {
#                 'level': args.log_level,
#                 'class': 'logging.StreamHandler',
#                 'formatter': 'default',
#             },
#         },
#         'loggers': {
#             '': {
#                 'handlers': ['default'],
#                 'level': args.log_level,
#                 'propagate': True,
#             }
#         }
#     })
# 
#     if args.config is not None:
#         config = load_config(args.config)
#     elif path.exists(path.expanduser(DEFAULT_CONFIG)):
#         config = load_config(DEFAULT_CONFIG)
#     elif path.exists(OLD_DEFAULT_CONFIG):
#         config = load_config(OLD_DEFAULT_CONFIG)
#     elif path.exists(path.expanduser(SITE_DEFAULT_CONFIG)):
#         config = load_config(SITE_DEFAULT_CONFIG)
#     else:  # get default config and print message about missing file
#         config = load_config()
# 
#     if 'NTFY_BACKENDS' in environ:
#         config['backends'] = environ['NTFY_BACKENDS'].split(',')
# 
#     if args.backend:
#         config['backends'] = args.backend
# 
#     if args.option is None:
#         args.option = {}
#     for backend, backend_options in args.option.items():
#         if backend is not None:
#             config.setdefault(backend, {}).update(backend_options)
# 
#     if getattr(args, 'func', None) == run_cmd and args.longer_than is None and\
#             'longer_than' in config:
#         args.longer_than = config['longer_than']
# 
#     if getattr(args, 'func', None) == run_cmd and 'hide_command' in config:
#         args.hide_command = config['hide_command']
# 
#     if hasattr(args, 'func'):
#         message, retcode = args.func(args)
#         if message is None:
#             return 0
#         if emojize is not None and not args.no_emoji:
#             message = emojize(message, use_aliases=True)
#         return notify(
#             message,
#             args.title,
#             config,
#             retcode=retcode,
#             **dict(args.option.get(None, [])))
#     else:
#         parser.print_help()


from sys import modules, version_info
from unittest import TestCase, main
from mock import MagicMock, mock_open, patch
from ntfy.cli import main as ntfy_main


py = version_info.major

builtin_module = '__builtin__' if py == 2 else 'builtins'


class TestIntegration(TestCase):
    @patch(builtin_module + '.open', mock_open())
    @patch('ntfy.config.safe_load')
    @patch('ntfy.backends.pushover.requests.post')
    def test_pushover(self, mock_post, mock_yamlload):
        mock_yamlload.return_value = {
            'backends': ['pushover'],
            'pushover': {
                'user_key': MagicMock()
            },
        }

# Path: ntfy/cli.py
# def main(cli_args=None):
#     if cli_args is not None:
#         args = parser.parse_args(cli_args)
#     else:
#         args = parser.parse_args()
# 
#     logging.config.dictConfig({
#         'version': 1,
#         'disable_existing_loggers': False,
#         'formatters': {
#             'default': {
#                 'format': '%(levelname)s: %(message)s'
#             },
#         },
#         'handlers': {
#             'default': {
#                 'level': args.log_level,
#                 'class': 'logging.StreamHandler',
#                 'formatter': 'default',
#             },
#         },
#         'loggers': {
#             '': {
#                 'handlers': ['default'],
#                 'level': args.log_level,
#                 'propagate': True,
#             }
#         }
#     })
# 
#     if args.config is not None:
#         config = load_config(args.config)
#     elif path.exists(path.expanduser(DEFAULT_CONFIG)):
#         config = load_config(DEFAULT_CONFIG)
#     elif path.exists(OLD_DEFAULT_CONFIG):
#         config = load_config(OLD_DEFAULT_CONFIG)
#     elif path.exists(path.expanduser(SITE_DEFAULT_CONFIG)):
#         config = load_config(SITE_DEFAULT_CONFIG)
#     else:  # get default config and print message about missing file
#         config = load_config()
# 
#     if 'NTFY_BACKENDS' in environ:
#         config['backends'] = environ['NTFY_BACKENDS'].split(',')
# 
#     if args.backend:
#         config['backends'] = args.backend
# 
#     if args.option is None:
#         args.option = {}
#     for backend, backend_options in args.option.items():
#         if backend is not None:
#             config.setdefault(backend, {}).update(backend_options)
# 
#     if getattr(args, 'func', None) == run_cmd and args.longer_than is None and\
#             'longer_than' in config:
#         args.longer_than = config['longer_than']
# 
#     if getattr(args, 'func', None) == run_cmd and 'hide_command' in config:
#         args.hide_command = config['hide_command']
# 
#     if hasattr(args, 'func'):
#         message, retcode = args.func(args)
#         if message is None:
#             return 0
#         if emojize is not None and not args.no_emoji:
#             message = emojize(message, use_aliases=True)
#         return notify(
#             message,
#             args.title,
#             config,
#             retcode=retcode,
#             **dict(args.option.get(None, [])))
#     else:
#         parser.print_help()


# Path: tests/test_integration.py
from sys import modules, version_info
from unittest import TestCase, main
from mock import MagicMock, mock_open, patch
from ntfy.cli import main as ntfy_main



py = version_info.major

builtin_module = '__builtin__' if py == 2 else 'builtins'


class TestIntegration(TestCase):
    @patch(builtin_module + '.open', mock_open())
    @patch('ntfy.config.safe_load')
    @patch('ntfy.backends.pushover.requests.post')
    def test_pushover(self, mock_post, mock_yamlload):
        mock_yamlload.return_value = {
            'backends': ['pushover'],
            'pushover': {
                'user_key': MagicMock()
            },
        }

        self.assertEqual(0, ntfy_main(['send', 'foobar']))