# 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




class Test(unittest.TestCase):

    def test_get_connection(self):
        swf_connection = get_connection()

        # Boto3 client object are dynamically forged...
        self.assertEqual(swf_connection.__class__.__name__, 'SWF')
        self.assertEqual(swf_connection.__class__.__module__, 'botocore.client')

        self.assertEqual(swf_connection.meta.config.read_timeout, 70)
        self.assertEqual(swf_connection.meta.config.region_name, 'us-east-1')
        self.assertEqual(swf_connection.meta.service_model.service_name, 'swf')


class TestRegisterWorkflow(unittest.TestCase):

    def setUp(self):
        self.mock_swf = mock_swf()
        self.mock_swf.start()


# 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





class Test(unittest.TestCase):

    def test_get_connection(self):
        swf_connection = get_connection()

        # Boto3 client object are dynamically forged...
        self.assertEqual(swf_connection.__class__.__name__, 'SWF')
        self.assertEqual(swf_connection.__class__.__module__, 'botocore.client')

        self.assertEqual(swf_connection.meta.config.read_timeout, 70)
        self.assertEqual(swf_connection.meta.config.region_name, 'us-east-1')
        self.assertEqual(swf_connection.meta.service_model.service_name, 'swf')


class TestRegisterWorkflow(unittest.TestCase):

    def setUp(self):
        self.mock_swf = mock_swf()
        self.mock_swf.start()


        self.connection = get_connection()