# Path: kale/message.py
# class KaleMessage:
#     def __init__(self,
#                  sqs_message_id=None,
#                  sqs_receipt_handle=None,
#                  sqs_queue_name=None,
#                  task_class=None,
#                  task_name=None,
#                  task_id=None,
#                  payload=None,
#                  current_retry_num=None,
#                  current_failure_num=None,
#                  enqueued_time=None,
#                  publisher_data=None,
#                  instantiate_task=False,
#                  delete_func=None
#                  ):
#     def _validate_task_payload(payload):
#     def _get_message_body(self):
#     def encode(self):
#     def decode_sqs(cls, sqs_message):
#     def decode_str(cls, message_str):
#     def _class_from_path(self, task_path):
#     def delete(self):
# 
# Path: kale/task.py
# PERMANENT_FAILURE_UNRECOVERABLE = 'unrecoverable'
# PERMANENT_FAILURE_NO_RETRY = 'no_retries'
# PERMANENT_FAILURE_RETRIES_EXCEEDED = 'max_retries'
#     EXCEPTION_LIST = (
#         exceptions.BlacklistedException,
#         KeyError,
#         NotImplementedError,
#         SyntaxError,
#         UnboundLocalError)
# class Task(object):
#     def __init__(self, message_body=None, *args, **kwargs):
#     def _get_publisher():
#     def _get_task_id(cls, *args, **kwargs):
#     def publish(cls, app_data, *args, **kwargs):
#     def _get_delay_sec_for_retry(cls, current_retry_num):
#     def handle_failure(cls, message, raised_exception, increment_failure_num=True):
#     def republish(cls, message, failure_count):
#     def run(self, *args, **kwargs):
#     def run_task(self, *args, **kwargs):
#     def should_run_task(self, *args, **kwargs):
#     def _check_blacklist(self, *args, **kwargs):
#     def _dequeued(self, *args, **kwargs):
#     def _setup_task_environment():
#     def _clean_task_environment(task_id=None, task_name=None, exc=None):
#     def _pre_run(self, *args, **kwargs):
#     def _post_run(self, *args, **kwargs):
#     def _alert_runtime_exceeded(self, *args, **kwargs):
#     def _kill_runtime_exceeded(self, *args, **kwargs):
#     def _report_permanent_failure(cls, message, exception, failure_type,
#                                   log_exception):


import unittest
import mock
from kale import message
from kale import task
        self.assertIsNotNone(kale_msg)
        self.assertEqual('kale.task.Task', kale_msg.task_name)
        self.assertEqual(123, kale_msg._enqueued_time)
        self.assertEqual(0, kale_msg.task_retry_num)
        self.assertEqual(0, kale_msg.task_failure_num)
        self.assertEqual(1, kale_msg.task_id)
        self.assertEqual([], kale_msg.task_args)
        self.assertEqual({}, kale_msg.task_kwargs)

    def test_message_with_appdata(self):
        payload = {'args': [], 'kwargs': {}, 'app_data': {}}

        # Test create
        kale_msg = message.KaleMessage(
            task_class=task.Task,
            task_id=1,
            payload=payload,
            current_retry_num=None)
        self.assertIsNotNone(kale_msg)
        self.assertEqual({}, kale_msg.task_app_data)

    @mock.patch('kale.message._get_current_timestamp')
    @mock.patch('kale.message._get_publisher_data')
    def test_encode(self, mock_get_current_timestamp, mock__get_publisher_data):
        payload = {'args': [], 'kwargs': {}, 'app_data': {}}

        mock_get_current_timestamp.return_value = 123
        mock__get_publisher_data.return_value = 'test_publisher'

        kale_msg = message.KaleMessage(

# Path: kale/message.py
# class KaleMessage:
#     def __init__(self,
#                  sqs_message_id=None,
#                  sqs_receipt_handle=None,
#                  sqs_queue_name=None,
#                  task_class=None,
#                  task_name=None,
#                  task_id=None,
#                  payload=None,
#                  current_retry_num=None,
#                  current_failure_num=None,
#                  enqueued_time=None,
#                  publisher_data=None,
#                  instantiate_task=False,
#                  delete_func=None
#                  ):
#     def _validate_task_payload(payload):
#     def _get_message_body(self):
#     def encode(self):
#     def decode_sqs(cls, sqs_message):
#     def decode_str(cls, message_str):
#     def _class_from_path(self, task_path):
#     def delete(self):
# 
# Path: kale/task.py
# PERMANENT_FAILURE_UNRECOVERABLE = 'unrecoverable'
# PERMANENT_FAILURE_NO_RETRY = 'no_retries'
# PERMANENT_FAILURE_RETRIES_EXCEEDED = 'max_retries'
#     EXCEPTION_LIST = (
#         exceptions.BlacklistedException,
#         KeyError,
#         NotImplementedError,
#         SyntaxError,
#         UnboundLocalError)
# class Task(object):
#     def __init__(self, message_body=None, *args, **kwargs):
#     def _get_publisher():
#     def _get_task_id(cls, *args, **kwargs):
#     def publish(cls, app_data, *args, **kwargs):
#     def _get_delay_sec_for_retry(cls, current_retry_num):
#     def handle_failure(cls, message, raised_exception, increment_failure_num=True):
#     def republish(cls, message, failure_count):
#     def run(self, *args, **kwargs):
#     def run_task(self, *args, **kwargs):
#     def should_run_task(self, *args, **kwargs):
#     def _check_blacklist(self, *args, **kwargs):
#     def _dequeued(self, *args, **kwargs):
#     def _setup_task_environment():
#     def _clean_task_environment(task_id=None, task_name=None, exc=None):
#     def _pre_run(self, *args, **kwargs):
#     def _post_run(self, *args, **kwargs):
#     def _alert_runtime_exceeded(self, *args, **kwargs):
#     def _kill_runtime_exceeded(self, *args, **kwargs):
#     def _report_permanent_failure(cls, message, exception, failure_type,
#                                   log_exception):


# Path: kale/tests/test_message.py
import unittest
import mock
from kale import message
from kale import task

        self.assertIsNotNone(kale_msg)
        self.assertEqual('kale.task.Task', kale_msg.task_name)
        self.assertEqual(123, kale_msg._enqueued_time)
        self.assertEqual(0, kale_msg.task_retry_num)
        self.assertEqual(0, kale_msg.task_failure_num)
        self.assertEqual(1, kale_msg.task_id)
        self.assertEqual([], kale_msg.task_args)
        self.assertEqual({}, kale_msg.task_kwargs)

    def test_message_with_appdata(self):
        payload = {'args': [], 'kwargs': {}, 'app_data': {}}

        # Test create
        kale_msg = message.KaleMessage(
            task_class=task.Task,
            task_id=1,
            payload=payload,
            current_retry_num=None)
        self.assertIsNotNone(kale_msg)
        self.assertEqual({}, kale_msg.task_app_data)

    @mock.patch('kale.message._get_current_timestamp')
    @mock.patch('kale.message._get_publisher_data')
    def test_encode(self, mock_get_current_timestamp, mock__get_publisher_data):
        payload = {'args': [], 'kwargs': {}, 'app_data': {}}

        mock_get_current_timestamp.return_value = 123
        mock__get_publisher_data.return_value = 'test_publisher'

        kale_msg = message.KaleMessage(

            task_class=task.Task,