# Path: lamvery/actions/generate.py
# class GenerateAction(BaseAction):
# 
#     def __init__(self, args):
#         super(GenerateAction, self).__init__(args)
#         self._kind = args.kind
# 
#     def action(self):
#         if self._kind == 'function':
#             self._generate_function(
#                 self._config.get_handler_namespace(),
#                 self._config.get_handler_function(),
#                 self._config.get_runtime())
#         else:
#             raise Exception('"{}" kind is not supported.'.format(self._kind))
# 
#     def _generate_function(self, namespace, function, runtime):
#         if 'python' in runtime:
#             path = '{}.py'.format(namespace)
#             content = PY_CODE.format(function)
#         elif 'nodejs' in runtime:
#             path = '{}.js'.format(namespace)
#             content = JS_CODE.format(function)
#         else:
#             raise Exception('Runtime "{}" is not supported.'.format(runtime))
# 
#         if confirm_overwrite(path):
#             open(path, 'w').write(content)
#             self._logger.info('Output skeleton function: {}'.format(path))


import os
from unittest import TestCase
from nose.tools import eq_, raises
from mock import Mock, patch
from lamvery.actions.generate import GenerateAction
            action._config.get_runtime = Mock(return_value='python2.7')
            action._config.get_handler_namespace = Mock(return_value='namespace')
            action._config.get_handler_function = Mock(return_value='function')
            action.action()
            eq_(open('namespace.py', 'r').read(), """import lamvery

def function(event, context):
    # Use environment variables
    # lamvery.env.load()
    # print(os.environ['FOO'])

    # Use KMS encryption
    # print(lamvery.secret.get('foo'))

    print('This is a skeleton function.')
""")

    @raises(Exception)
    def test_action_invalid_kind(self):
        args = default_args()
        args.kind = 'foo'
        action = GenerateAction(args)
        action._config = Mock()
        action._config.get_runtime = Mock(return_value='python2.7')
        action._config.get_handler_namespace = Mock(return_value='namespace')
        action._config.get_handler_function = Mock(return_value='function')
        action.action()

    @raises(Exception)
    def test_action_invalid_runtime(self):

# Path: lamvery/actions/generate.py
# class GenerateAction(BaseAction):
# 
#     def __init__(self, args):
#         super(GenerateAction, self).__init__(args)
#         self._kind = args.kind
# 
#     def action(self):
#         if self._kind == 'function':
#             self._generate_function(
#                 self._config.get_handler_namespace(),
#                 self._config.get_handler_function(),
#                 self._config.get_runtime())
#         else:
#             raise Exception('"{}" kind is not supported.'.format(self._kind))
# 
#     def _generate_function(self, namespace, function, runtime):
#         if 'python' in runtime:
#             path = '{}.py'.format(namespace)
#             content = PY_CODE.format(function)
#         elif 'nodejs' in runtime:
#             path = '{}.js'.format(namespace)
#             content = JS_CODE.format(function)
#         else:
#             raise Exception('Runtime "{}" is not supported.'.format(runtime))
# 
#         if confirm_overwrite(path):
#             open(path, 'w').write(content)
#             self._logger.info('Output skeleton function: {}'.format(path))


# Path: tests/lamvery/actions/generate_test.py
import os
from unittest import TestCase
from nose.tools import eq_, raises
from mock import Mock, patch
from lamvery.actions.generate import GenerateAction

            action._config.get_runtime = Mock(return_value='python2.7')
            action._config.get_handler_namespace = Mock(return_value='namespace')
            action._config.get_handler_function = Mock(return_value='function')
            action.action()
            eq_(open('namespace.py', 'r').read(), """import lamvery

def function(event, context):
    # Use environment variables
    # lamvery.env.load()
    # print(os.environ['FOO'])

    # Use KMS encryption
    # print(lamvery.secret.get('foo'))

    print('This is a skeleton function.')
""")

    @raises(Exception)
    def test_action_invalid_kind(self):
        args = default_args()
        args.kind = 'foo'
        action = GenerateAction(args)
        action._config = Mock()
        action._config.get_runtime = Mock(return_value='python2.7')
        action._config.get_handler_namespace = Mock(return_value='namespace')
        action._config.get_handler_function = Mock(return_value='function')
        action.action()

    @raises(Exception)
    def test_action_invalid_runtime(self):

        action = GenerateAction(default_args())