# Path: caravan/swf.py
# def get_workflow_registration_parameter(workflow):
#     args = {}
# 
#     for parameter in REGISTER_WORKFLOW_PARAMETERS:
#         attr_name = inflection.underscore(parameter)
#         attr_value = getattr(workflow, attr_name, None)
# 
#         required = attr_name in REGISTER_WORKFLOW_REQUIRED_PARAMETERS
# 
#         if attr_value is None:
#             if required:
#                 raise InvalidWorkflowError('missing attribute %s' % attr_name)
# 
#         else:
#             is_string = isinstance(attr_value, string_types)
#             is_dict = isinstance(attr_value, dict)
#             is_int = isinstance(attr_value, int)
# 
#             if parameter == 'defaultTaskList' and is_string:
#                 attr_value = {'name': attr_value}
#             if parameter == 'defaultTaskList' and is_dict:
#                 pass
#             if parameter.endswith('Timeout') and is_int:
#                 attr_value = str(attr_value)
#             elif not is_string:
#                 raise InvalidWorkflowError('invalid attribute %s' % attr_name)
# 
#             args[parameter] = attr_value
# 
#     return args
# 
# def register_workflow(connection, domain, workflow):
#     """Register a workflow type.
# 
#     Return False if this workflow already registered (and True otherwise).
#     """
#     args = get_workflow_registration_parameter(workflow)
# 
#     try:
#         connection.register_workflow_type(domain=domain, **args)
#     except ClientError as err:
#         if err.response['Error']['Code'] == 'TypeAlreadyExistsFault':
#             return False  # Ignore this error
#         raise
# 
#     return True
# 
# def get_connection():
#     # Must increase the http timeout since SWF has a timeout of 60 sec
#     config = Config(connect_timeout=50, read_timeout=70)
#     connection = boto3.client("swf", config=config)
#     return connection


import unittest
import mock
from moto import mock_swf
from caravan.swf import (get_workflow_registration_parameter,
                         register_workflow,
                         get_connection)
        from caravan.examples.demo import Demo
            domain='TESTDOMAIN', name='TESTNAME', version='TESTVERSION')

    def test_description(self):
        connection = mock.Mock()

        class Workflow(object):
            name = 'TESTNAME'
            version = 'TESTVERSION'
            description = 'TESTDESC'

        register_workflow(connection, 'TESTDOMAIN', Workflow)

        connection.register_workflow_type.assert_called_once_with(
            description='TESTDESC', domain='TESTDOMAIN',
            name='TESTNAME', version='TESTVERSION')

    def test_defaults(self):
        connection = mock.Mock()

        class Workflow(object):
            name = 'TESTNAME'
            version = 'TESTVERSION'

            default_task_start_to_close_timeout = 'TEST_TSTCT'
            default_execution_start_to_close_timeout = 'TEST_ESTCT'
            default_task_list = 'TEST_TL'
            default_task_priority = 'TEST_TP'
            default_child_policy = 'TEST_CP'
            default_lambda_role = 'TEST_LR'


# Path: caravan/swf.py
# def get_workflow_registration_parameter(workflow):
#     args = {}
# 
#     for parameter in REGISTER_WORKFLOW_PARAMETERS:
#         attr_name = inflection.underscore(parameter)
#         attr_value = getattr(workflow, attr_name, None)
# 
#         required = attr_name in REGISTER_WORKFLOW_REQUIRED_PARAMETERS
# 
#         if attr_value is None:
#             if required:
#                 raise InvalidWorkflowError('missing attribute %s' % attr_name)
# 
#         else:
#             is_string = isinstance(attr_value, string_types)
#             is_dict = isinstance(attr_value, dict)
#             is_int = isinstance(attr_value, int)
# 
#             if parameter == 'defaultTaskList' and is_string:
#                 attr_value = {'name': attr_value}
#             if parameter == 'defaultTaskList' and is_dict:
#                 pass
#             if parameter.endswith('Timeout') and is_int:
#                 attr_value = str(attr_value)
#             elif not is_string:
#                 raise InvalidWorkflowError('invalid attribute %s' % attr_name)
# 
#             args[parameter] = attr_value
# 
#     return args
# 
# def register_workflow(connection, domain, workflow):
#     """Register a workflow type.
# 
#     Return False if this workflow already registered (and True otherwise).
#     """
#     args = get_workflow_registration_parameter(workflow)
# 
#     try:
#         connection.register_workflow_type(domain=domain, **args)
#     except ClientError as err:
#         if err.response['Error']['Code'] == 'TypeAlreadyExistsFault':
#             return False  # Ignore this error
#         raise
# 
#     return True
# 
# def get_connection():
#     # Must increase the http timeout since SWF has a timeout of 60 sec
#     config = Config(connect_timeout=50, read_timeout=70)
#     connection = boto3.client("swf", config=config)
#     return connection


# Path: caravan/tests/test_swf.py
import unittest
import mock
from moto import mock_swf
from caravan.swf import (get_workflow_registration_parameter,
                         register_workflow,
                         get_connection)
        from caravan.examples.demo import Demo

            domain='TESTDOMAIN', name='TESTNAME', version='TESTVERSION')

    def test_description(self):
        connection = mock.Mock()

        class Workflow(object):
            name = 'TESTNAME'
            version = 'TESTVERSION'
            description = 'TESTDESC'

        register_workflow(connection, 'TESTDOMAIN', Workflow)

        connection.register_workflow_type.assert_called_once_with(
            description='TESTDESC', domain='TESTDOMAIN',
            name='TESTNAME', version='TESTVERSION')

    def test_defaults(self):
        connection = mock.Mock()

        class Workflow(object):
            name = 'TESTNAME'
            version = 'TESTVERSION'

            default_task_start_to_close_timeout = 'TEST_TSTCT'
            default_execution_start_to_close_timeout = 'TEST_ESTCT'
            default_task_list = 'TEST_TL'
            default_task_priority = 'TEST_TP'
            default_child_policy = 'TEST_CP'
            default_lambda_role = 'TEST_LR'


        register_workflow(connection, 'TESTDOMAIN', Workflow)