# Path: lamvery/actions/build.py
# class BuildAction(BaseAction):
# 
#     def __init__(self, args):
#         super(BuildAction, self).__init__(args)
#         self._single_file = args.single_file
#         self._no_libs = args.no_libs
#         self._env = parse_env_args(args.env)
# 
#     def action(self):
#         archive_name = self._config.get_archive_name()
#         function_filename = self._config.get_function_filename()
#         secret = self._config.generate_lambda_secret()
#         exclude = self._config.get_exclude()
# 
#         builder = Builder(
#             filename=archive_name,
#             function_filename=function_filename,
#             secret=secret,
#             single_file=self._single_file,
#             no_libs=self._no_libs,
#             exclude=exclude,
#             runtime=self._config.get_runtime(),
#             env=self._env,
#             clean_build=self._config.is_clean_build(),
#             hooks=self._config.get_build_hooks())
# 
#         zipfile = builder.build()
#         with open(archive_name, 'w') as f:
#             f.write(zipfile.read())
#         zipfile.close()
# 
#         self._logger.info('Output archive(zip) to {}'.format(archive_name))


import os
from unittest import TestCase
from nose.tools import ok_
from mock import Mock
from lamvery.actions.build import BuildAction




def default_args():
    args = Mock()
    args.conf_file = '.lamvery.yml'
    args.dry_run = True
    args.no_libs = False
    args.single_file = False
    return args


class BuildActionTestCase(TestCase):

    def tearDown(self):
        if os.path.exists('test.zip'):
            os.remove('test.zip')

    def test_action(self):
        action = BuildAction(default_args())
        action._config = Mock()
        action._config.get_archive_name = Mock(return_value='test.zip')
        action._config.get_function_filename = Mock(return_value='test.py')
        action._config.generate_lambda_secret = Mock(return_value={})
        action._config.get_exclude = Mock(return_value=[])
        action._config.get_build_hooks = Mock(return_value={'pre': ['whoami'], 'post': ['whoami']})
        action.action()
        ok_(os.path.exists('test.zip'))


# Path: lamvery/actions/build.py
# class BuildAction(BaseAction):
# 
#     def __init__(self, args):
#         super(BuildAction, self).__init__(args)
#         self._single_file = args.single_file
#         self._no_libs = args.no_libs
#         self._env = parse_env_args(args.env)
# 
#     def action(self):
#         archive_name = self._config.get_archive_name()
#         function_filename = self._config.get_function_filename()
#         secret = self._config.generate_lambda_secret()
#         exclude = self._config.get_exclude()
# 
#         builder = Builder(
#             filename=archive_name,
#             function_filename=function_filename,
#             secret=secret,
#             single_file=self._single_file,
#             no_libs=self._no_libs,
#             exclude=exclude,
#             runtime=self._config.get_runtime(),
#             env=self._env,
#             clean_build=self._config.is_clean_build(),
#             hooks=self._config.get_build_hooks())
# 
#         zipfile = builder.build()
#         with open(archive_name, 'w') as f:
#             f.write(zipfile.read())
#         zipfile.close()
# 
#         self._logger.info('Output archive(zip) to {}'.format(archive_name))


# Path: tests/lamvery/actions/build_test.py
import os
from unittest import TestCase
from nose.tools import ok_
from mock import Mock
from lamvery.actions.build import BuildAction





def default_args():
    args = Mock()
    args.conf_file = '.lamvery.yml'
    args.dry_run = True
    args.no_libs = False
    args.single_file = False
    return args


class BuildActionTestCase(TestCase):

    def tearDown(self):
        if os.path.exists('test.zip'):
            os.remove('test.zip')

    def test_action(self):
        action = BuildAction(default_args())
        action._config = Mock()
        action._config.get_archive_name = Mock(return_value='test.zip')
        action._config.get_function_filename = Mock(return_value='test.py')
        action._config.generate_lambda_secret = Mock(return_value={})
        action._config.get_exclude = Mock(return_value=[])
        action._config.get_build_hooks = Mock(return_value={'pre': ['whoami'], 'post': ['whoami']})
        action.action()
        ok_(os.path.exists('test.zip'))


        action = BuildAction(default_args())