# 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
# -*- coding: utf-8 -*-





def default_args():
    args = Mock()
    args.conf_file = '.lamvery.yml'
    args.kind = 'function'
    return args


class GenerateActionTestCase(TestCase):

    def tearDown(self):
        for suffix in ['py', 'js']:
            filename = 'namespace.{}'.format(suffix)
            if os.path.exists(filename):
                os.remove(filename)

    def test_action(self):
        with patch('lamvery.actions.init.confirm_overwrite') as c:
            c.return_value = True

# 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

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





def default_args():
    args = Mock()
    args.conf_file = '.lamvery.yml'
    args.kind = 'function'
    return args


class GenerateActionTestCase(TestCase):

    def tearDown(self):
        for suffix in ['py', 'js']:
            filename = 'namespace.{}'.format(suffix)
            if os.path.exists(filename):
                os.remove(filename)

    def test_action(self):
        with patch('lamvery.actions.init.confirm_overwrite') as c:
            c.return_value = True

            action = GenerateAction(default_args())