# Path: marathon/models/events.py
# class EventFactory:
# 
#     """
#     Handle an event emitted from the Marathon EventBus
#     See: https://mesosphere.github.io/marathon/docs/event-bus.html
#     """
# 
#     def __init__(self):
#         pass
# 
#     event_to_class = {
#         'api_post_event': MarathonApiPostEvent,
#         'status_update_event': MarathonStatusUpdateEvent,
#         'framework_message_event': MarathonFrameworkMessageEvent,
#         'subscribe_event': MarathonSubscribeEvent,
#         'unsubscribe_event': MarathonUnsubscribeEvent,
#         'add_health_check_event': MarathonAddHealthCheckEvent,
#         'remove_health_check_event': MarathonRemoveHealthCheckEvent,
#         'failed_health_check_event': MarathonFailedHealthCheckEvent,
#         'health_status_changed_event': MarathonHealthStatusChangedEvent,
#         'unhealthy_task_kill_event': MarathonUnhealthyTaskKillEvent,
#         'group_change_success': MarathonGroupChangeSuccess,
#         'group_change_failed': MarathonGroupChangeFailed,
#         'deployment_success': MarathonDeploymentSuccess,
#         'deployment_failed': MarathonDeploymentFailed,
#         'deployment_info': MarathonDeploymentInfo,
#         'deployment_step_success': MarathonDeploymentStepSuccess,
#         'deployment_step_failure': MarathonDeploymentStepFailure,
#         'event_stream_attached': MarathonEventStreamAttached,
#         'event_stream_detached': MarathonEventStreamDetached,
#         'app_terminated_event': MarathonAppTerminatedEvent,
#         'instance_changed_event': MarathonInstanceChangedEvent,
#         'unknown_instance_terminated_event': MarathonUnknownInstanceTerminated,
#         'unhealthy_instance_kill_event': MarathonUnhealthyInstanceKillEvent,
#         'instance_health_changed_event': MarathonInstanceHealthChangedEvent,
#         'pod_created_event': MarathonPodCreatedEvent,
#         'pod_updated_event': MarathonPodUpdatedEvent,
#         'pod_deleted_event': MarathonPodDeletedEvent,
#     }
# 
#     class_to_event = {v: k for k, v in event_to_class.items()}
# 
#     def process(self, event):
#         event_type = event['eventType']
#         if event_type in self.event_to_class:
#             clazz = self.event_to_class[event_type]
#             return clazz.from_json(event)
#         else:
#             raise MarathonError(f'Unknown event_type: {event_type}, data: {event}')
# 
# class MarathonStatusUpdateEvent(MarathonEvent):
#     KNOWN_ATTRIBUTES = [
#         'slave_id', 'task_id', 'task_status', 'app_id', 'host', 'ports', 'version', 'message', 'ip_addresses']
# 
# Path: marathon/models/task.py
# class MarathonIpAddress(MarathonObject):
#     """
#     """
#     def __init__(self, ip_address=None, protocol=None):
#         self.ip_address = ip_address
#         self.protocol = protocol


from marathon.models.events import EventFactory, MarathonStatusUpdateEvent
from marathon.models.task import MarathonIpAddress
import unittest


class MarathonEventTest(unittest.TestCase):

    def test_event_factory(self):
        self.assertEqual(
            set(EventFactory.event_to_class.keys()),
            set(EventFactory.class_to_event.values()),
        )

    def test_marathon_event(self):
        """Test that we can process at least one kind of event."""
        payload = {
            "eventType": "status_update_event",
            "slaveId": "slave-01",
            "taskId": "task-01",
            "taskStatus": "TASK_RUNNING",
            "message": "Some message",
            "appId": "/foo/bar",
            "host": "host-01",
            "ipAddresses": [
                {"ip_address": "127.0.0.1", "protocol": "tcp"},
                {"ip_address": "127.0.0.1", "protocol": "udp"},
            ],
            "ports": [0, 1],
            "version": "1234",
            "timestamp": 12345,
        }

# Path: marathon/models/events.py
# class EventFactory:
# 
#     """
#     Handle an event emitted from the Marathon EventBus
#     See: https://mesosphere.github.io/marathon/docs/event-bus.html
#     """
# 
#     def __init__(self):
#         pass
# 
#     event_to_class = {
#         'api_post_event': MarathonApiPostEvent,
#         'status_update_event': MarathonStatusUpdateEvent,
#         'framework_message_event': MarathonFrameworkMessageEvent,
#         'subscribe_event': MarathonSubscribeEvent,
#         'unsubscribe_event': MarathonUnsubscribeEvent,
#         'add_health_check_event': MarathonAddHealthCheckEvent,
#         'remove_health_check_event': MarathonRemoveHealthCheckEvent,
#         'failed_health_check_event': MarathonFailedHealthCheckEvent,
#         'health_status_changed_event': MarathonHealthStatusChangedEvent,
#         'unhealthy_task_kill_event': MarathonUnhealthyTaskKillEvent,
#         'group_change_success': MarathonGroupChangeSuccess,
#         'group_change_failed': MarathonGroupChangeFailed,
#         'deployment_success': MarathonDeploymentSuccess,
#         'deployment_failed': MarathonDeploymentFailed,
#         'deployment_info': MarathonDeploymentInfo,
#         'deployment_step_success': MarathonDeploymentStepSuccess,
#         'deployment_step_failure': MarathonDeploymentStepFailure,
#         'event_stream_attached': MarathonEventStreamAttached,
#         'event_stream_detached': MarathonEventStreamDetached,
#         'app_terminated_event': MarathonAppTerminatedEvent,
#         'instance_changed_event': MarathonInstanceChangedEvent,
#         'unknown_instance_terminated_event': MarathonUnknownInstanceTerminated,
#         'unhealthy_instance_kill_event': MarathonUnhealthyInstanceKillEvent,
#         'instance_health_changed_event': MarathonInstanceHealthChangedEvent,
#         'pod_created_event': MarathonPodCreatedEvent,
#         'pod_updated_event': MarathonPodUpdatedEvent,
#         'pod_deleted_event': MarathonPodDeletedEvent,
#     }
# 
#     class_to_event = {v: k for k, v in event_to_class.items()}
# 
#     def process(self, event):
#         event_type = event['eventType']
#         if event_type in self.event_to_class:
#             clazz = self.event_to_class[event_type]
#             return clazz.from_json(event)
#         else:
#             raise MarathonError(f'Unknown event_type: {event_type}, data: {event}')
# 
# class MarathonStatusUpdateEvent(MarathonEvent):
#     KNOWN_ATTRIBUTES = [
#         'slave_id', 'task_id', 'task_status', 'app_id', 'host', 'ports', 'version', 'message', 'ip_addresses']
# 
# Path: marathon/models/task.py
# class MarathonIpAddress(MarathonObject):
#     """
#     """
#     def __init__(self, ip_address=None, protocol=None):
#         self.ip_address = ip_address
#         self.protocol = protocol


# Path: tests/test_model_event.py
from marathon.models.events import EventFactory, MarathonStatusUpdateEvent
from marathon.models.task import MarathonIpAddress
import unittest



class MarathonEventTest(unittest.TestCase):

    def test_event_factory(self):
        self.assertEqual(
            set(EventFactory.event_to_class.keys()),
            set(EventFactory.class_to_event.values()),
        )

    def test_marathon_event(self):
        """Test that we can process at least one kind of event."""
        payload = {
            "eventType": "status_update_event",
            "slaveId": "slave-01",
            "taskId": "task-01",
            "taskStatus": "TASK_RUNNING",
            "message": "Some message",
            "appId": "/foo/bar",
            "host": "host-01",
            "ipAddresses": [
                {"ip_address": "127.0.0.1", "protocol": "tcp"},
                {"ip_address": "127.0.0.1", "protocol": "udp"},
            ],
            "ports": [0, 1],
            "version": "1234",
            "timestamp": 12345,
        }

        factory = EventFactory()