# Path: lamvery/actions/invoke.py
# class InvokeAction(BaseAction):
# 
#     def __init__(self, args):
#         super(InvokeAction, self).__init__(args)
# 
#         if os.path.exists(args.json):
#             self._json = open(args.json, 'r').read()
#         else:
#             self._json = args.json
# 
#         if args.alias is None:
#             self._alias = self._config.get_default_alias()
#         else:
#             self._alias = args.alias
# 
#         self._version = args.version
# 
#     def action(self):
#         qualifier = self._alias
#         client = self.get_lambda_client()
# 
#         if self._version is not None:
#             qualifier = self._version
# 
#         ret = client.invoke(
#             name=self._config.get_function_name(),
#             qualifier=qualifier,
#             payload=self._json)
# 
#         if ret.get('FunctionError') is None:
#             cprint(base64.b64decode(ret.get('LogResult')), 'green')
#         else:
#             self._logger.error('{} error occurred'.format(ret.get('FunctionError')))
#             cprint(base64.b64decode(ret.get('LogResult')), 'red')


from unittest import TestCase
from mock import Mock, patch
from lamvery.actions.invoke import InvokeAction
import base64
# -*- coding: utf-8 -*-





def default_args():
    args = Mock()
    args.conf_file = '.lamvery.yml'
    args.alias = 'foo'
    args.version = '1'
    args.json = '{"foo": "bar"}'
    return args


class InvokeActionTestCase(TestCase):

    def test_action(self):
        with patch('lamvery.actions.base.LambdaClient') as c:
            m = Mock()
            m.invoke = Mock(return_value={'LogResult': base64.b64encode('foo')})
            c.return_value = m
            action = InvokeAction(default_args())
            action.action()

            args = default_args()
            args.json = '.lamvery.yml'

# Path: lamvery/actions/invoke.py
# class InvokeAction(BaseAction):
# 
#     def __init__(self, args):
#         super(InvokeAction, self).__init__(args)
# 
#         if os.path.exists(args.json):
#             self._json = open(args.json, 'r').read()
#         else:
#             self._json = args.json
# 
#         if args.alias is None:
#             self._alias = self._config.get_default_alias()
#         else:
#             self._alias = args.alias
# 
#         self._version = args.version
# 
#     def action(self):
#         qualifier = self._alias
#         client = self.get_lambda_client()
# 
#         if self._version is not None:
#             qualifier = self._version
# 
#         ret = client.invoke(
#             name=self._config.get_function_name(),
#             qualifier=qualifier,
#             payload=self._json)
# 
#         if ret.get('FunctionError') is None:
#             cprint(base64.b64decode(ret.get('LogResult')), 'green')
#         else:
#             self._logger.error('{} error occurred'.format(ret.get('FunctionError')))
#             cprint(base64.b64decode(ret.get('LogResult')), 'red')


# Path: tests/lamvery/actions/invoke_test.py
from unittest import TestCase
from mock import Mock, patch
from lamvery.actions.invoke import InvokeAction
import base64

# -*- coding: utf-8 -*-





def default_args():
    args = Mock()
    args.conf_file = '.lamvery.yml'
    args.alias = 'foo'
    args.version = '1'
    args.json = '{"foo": "bar"}'
    return args


class InvokeActionTestCase(TestCase):

    def test_action(self):
        with patch('lamvery.actions.base.LambdaClient') as c:
            m = Mock()
            m.invoke = Mock(return_value={'LogResult': base64.b64encode('foo')})
            c.return_value = m
            action = InvokeAction(default_args())
            action.action()

            args = default_args()
            args.json = '.lamvery.yml'

            action = InvokeAction(args)