# Path: lamvery/actions/rollback.py
# class RollbackAction(BaseAction):
# 
#     def __init__(self, args):
#         super(RollbackAction, self).__init__(args)
#         self._set_alias = SetAliasAction(args)
# 
#     def action(self):
#         func_name = self._config.get_function_name()
#         client = self.get_lambda_client()
#         remote_conf = client.get_function_conf(func_name)
#         alias_name = self._set_alias.get_alias_name()
# 
#         if len(remote_conf) == 0:
#             raise Exception(
#                 '"{}" function does not exist. Please `deploy` first.'.format(func_name))
# 
#         pre_version = client.get_previous_version(func_name, alias_name)
#         if pre_version is None:
#             raise Exception(
#                 'There is no previous version. ' +
#                 'Please `deploy` with `publish` option or `versioning` configuration.')
# 
#         self._logger.info(
#             '[Function] Previous version: {}'.format(pre_version))
# 
#         self._set_alias._version = pre_version
#         self._set_alias.action()


from unittest import TestCase
from nose.tools import raises
from mock import Mock, patch
from lamvery.actions.rollback import RollbackAction
# -*- coding: utf-8 -*-




def default_args():
    args = Mock()
    args.conf_file = '.lamvery.yml'
    args.dry_run = True

    return args


class RollbackActionTestCase(TestCase):

    @raises(Exception)
    def test_action_function_not_exists(self):
        with patch('lamvery.actions.base.LambdaClient') as c:
            c.get_function_conf = Mock(return_value={})
            c.get_function_conf = Mock(return_value=None)
            action = RollbackAction(default_args())
            action._get_client = Mock(return_value=c)
            action.action()

    @raises(Exception)
    def test_action_previous_version_not_exists(self):
        with patch('lamvery.actions.base.LambdaClient') as c:
            c.get_function_conf = Mock(return_value={'foo': 'bar'})
            c.get_previous_version = Mock(return_value=None)

# Path: lamvery/actions/rollback.py
# class RollbackAction(BaseAction):
# 
#     def __init__(self, args):
#         super(RollbackAction, self).__init__(args)
#         self._set_alias = SetAliasAction(args)
# 
#     def action(self):
#         func_name = self._config.get_function_name()
#         client = self.get_lambda_client()
#         remote_conf = client.get_function_conf(func_name)
#         alias_name = self._set_alias.get_alias_name()
# 
#         if len(remote_conf) == 0:
#             raise Exception(
#                 '"{}" function does not exist. Please `deploy` first.'.format(func_name))
# 
#         pre_version = client.get_previous_version(func_name, alias_name)
#         if pre_version is None:
#             raise Exception(
#                 'There is no previous version. ' +
#                 'Please `deploy` with `publish` option or `versioning` configuration.')
# 
#         self._logger.info(
#             '[Function] Previous version: {}'.format(pre_version))
# 
#         self._set_alias._version = pre_version
#         self._set_alias.action()


# Path: tests/lamvery/actions/rollback_test.py
from unittest import TestCase
from nose.tools import raises
from mock import Mock, patch
from lamvery.actions.rollback import RollbackAction

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




def default_args():
    args = Mock()
    args.conf_file = '.lamvery.yml'
    args.dry_run = True

    return args


class RollbackActionTestCase(TestCase):

    @raises(Exception)
    def test_action_function_not_exists(self):
        with patch('lamvery.actions.base.LambdaClient') as c:
            c.get_function_conf = Mock(return_value={})
            c.get_function_conf = Mock(return_value=None)
            action = RollbackAction(default_args())
            action._get_client = Mock(return_value=c)
            action.action()

    @raises(Exception)
    def test_action_previous_version_not_exists(self):
        with patch('lamvery.actions.base.LambdaClient') as c:
            c.get_function_conf = Mock(return_value={'foo': 'bar'})
            c.get_previous_version = Mock(return_value=None)

            action = RollbackAction(default_args())