def setUp(self):
        mock_clients = self._create_service_mock('external_observatory_agent')
        self.ext_obs_service = ExternalObservatoryAgentService()
        self.ext_obs_service.clients = mock_clients
        self.ext_obs_service.clients.pubsub_management = DotDict()
        self.ext_obs_service.clients.pubsub_management['XP'] = 'science.data'
        self.ext_obs_service.clients.pubsub_management['create_stream'] = Mock(
        )
        self.ext_obs_service.clients.pubsub_management[
            'create_subscription'] = Mock()
        self.ext_obs_service.clients.pubsub_management[
            'register_producer'] = Mock()
        self.ext_obs_service.clients.pubsub_management[
            'activate_subscription'] = Mock()
        self.ext_obs_service.clients.pubsub_management[
            'read_subscription'] = Mock()
        self.ext_obs_service.container = DotDict()
        self.ext_obs_service.container['spawn_process'] = Mock()
        self.ext_obs_service.container['id'] = 'mock_container_id'
        self.ext_obs_service.container['proc_manager'] = DotDict()
        self.ext_obs_service.container.proc_manager[
            'terminate_process'] = Mock()

        # CRUD Shortcuts
        #        self.mock_rr_create = self.ext_obs_service.clients.resource_registry.create
        #        self.mock_rr_read = self.ext_obs_service.clients.resource_registry.read
        #        self.mock_rr_update = self.ext_obs_service.clients.resource_registry.update
        #        self.mock_rr_delete = self.ext_obs_service.clients.resource_registry.delete
        #        self.mock_rr_find = self.ext_obs_service.clients.resource_registry.find_objects
        #        self.mock_rr_assoc = self.ext_obs_service.clients.resource_registry.find_associations
        #        self.mock_rr_create_assoc = self.ext_obs_service.clients.resource_registry.create_association
        #        self.mock_rr_del_assoc = self.ext_obs_service.clients.resource_registry.delete_association

        self.mock_pd_create = self.ext_obs_service.clients.process_dispatcher_service.create_process_definition
        self.mock_pd_read = self.ext_obs_service.clients.process_dispatcher_service.read_process_definition
        self.mock_pd_update = self.ext_obs_service.clients.process_dispatcher_service.update_process_definition
        self.mock_pd_delete = self.ext_obs_service.clients.process_dispatcher_service.delete_process_definition
        self.mock_pd_schedule = self.ext_obs_service.clients.process_dispatcher_service.schedule_process
        self.mock_pd_cancel = self.ext_obs_service.clients.process_dispatcher_service.cancel_process

        self.mock_ps_create_stream = self.ext_obs_service.clients.pubsub_management.create_stream
        self.mock_ps_create_sub = self.ext_obs_service.clients.pubsub_management.create_subscription
        self.mock_ps_register = self.ext_obs_service.clients.pubsub_management.register_producer
        self.mock_ps_activate = self.ext_obs_service.clients.pubsub_management.activate_subscription
        self.mock_ps_read_sub = self.ext_obs_service.clients.pubsub_management.read_subscription

        self.mock_cc_spawn = self.ext_obs_service.container.spawn_process
        self.mock_cc_terminate = self.ext_obs_service.container.proc_manager.terminate_process
    def setUp(self):
        mock_clients = self._create_service_mock('external_observatory_agent')
        self.ext_obs_service = ExternalObservatoryAgentService()
        self.ext_obs_service.clients = mock_clients
        self.ext_obs_service.clients.pubsub_management = DotDict()
        self.ext_obs_service.clients.pubsub_management['XP'] = 'science.data'
        self.ext_obs_service.clients.pubsub_management['create_stream'] = Mock()
        self.ext_obs_service.clients.pubsub_management['create_subscription'] = Mock()
        self.ext_obs_service.clients.pubsub_management['register_producer'] = Mock()
        self.ext_obs_service.clients.pubsub_management['activate_subscription'] = Mock()
        self.ext_obs_service.clients.pubsub_management['read_subscription'] = Mock()
        self.ext_obs_service.container = DotDict()
        self.ext_obs_service.container['spawn_process'] = Mock()
        self.ext_obs_service.container['id'] = 'mock_container_id'
        self.ext_obs_service.container['proc_manager'] = DotDict()
        self.ext_obs_service.container.proc_manager['terminate_process'] = Mock()

        # CRUD Shortcuts
#        self.mock_rr_create = self.ext_obs_service.clients.resource_registry.create
#        self.mock_rr_read = self.ext_obs_service.clients.resource_registry.read
#        self.mock_rr_update = self.ext_obs_service.clients.resource_registry.update
#        self.mock_rr_delete = self.ext_obs_service.clients.resource_registry.delete
#        self.mock_rr_find = self.ext_obs_service.clients.resource_registry.find_objects
#        self.mock_rr_assoc = self.ext_obs_service.clients.resource_registry.find_associations
#        self.mock_rr_create_assoc = self.ext_obs_service.clients.resource_registry.create_association
#        self.mock_rr_del_assoc = self.ext_obs_service.clients.resource_registry.delete_association

        self.mock_pd_create = self.ext_obs_service.clients.process_dispatcher_service.create_process_definition
        self.mock_pd_read = self.ext_obs_service.clients.process_dispatcher_service.read_process_definition
        self.mock_pd_update = self.ext_obs_service.clients.process_dispatcher_service.update_process_definition
        self.mock_pd_delete = self.ext_obs_service.clients.process_dispatcher_service.delete_process_definition
        self.mock_pd_schedule = self.ext_obs_service.clients.process_dispatcher_service.schedule_process
        self.mock_pd_cancel = self.ext_obs_service.clients.process_dispatcher_service.cancel_process

        self.mock_ps_create_stream = self.ext_obs_service.clients.pubsub_management.create_stream
        self.mock_ps_create_sub = self.ext_obs_service.clients.pubsub_management.create_subscription
        self.mock_ps_register = self.ext_obs_service.clients.pubsub_management.register_producer
        self.mock_ps_activate = self.ext_obs_service.clients.pubsub_management.activate_subscription
        self.mock_ps_read_sub = self.ext_obs_service.clients.pubsub_management.read_subscription

        self.mock_cc_spawn = self.ext_obs_service.container.spawn_process
        self.mock_cc_terminate = self.ext_obs_service.container.proc_manager.terminate_process
class TestExternalObservatoryAgentService(PyonTestCase):
    
    def setUp(self):
        mock_clients = self._create_service_mock('external_observatory_agent')
        self.ext_obs_service = ExternalObservatoryAgentService()
        self.ext_obs_service.clients = mock_clients
        self.ext_obs_service.clients.pubsub_management = DotDict()
        self.ext_obs_service.clients.pubsub_management['XP'] = 'science.data'
        self.ext_obs_service.clients.pubsub_management['create_stream'] = Mock()
        self.ext_obs_service.clients.pubsub_management['create_subscription'] = Mock()
        self.ext_obs_service.clients.pubsub_management['register_producer'] = Mock()
        self.ext_obs_service.clients.pubsub_management['activate_subscription'] = Mock()
        self.ext_obs_service.clients.pubsub_management['read_subscription'] = Mock()
        self.ext_obs_service.container = DotDict()
        self.ext_obs_service.container['spawn_process'] = Mock()
        self.ext_obs_service.container['id'] = 'mock_container_id'
        self.ext_obs_service.container['proc_manager'] = DotDict()
        self.ext_obs_service.container.proc_manager['terminate_process'] = Mock()

        # CRUD Shortcuts
#        self.mock_rr_create = self.ext_obs_service.clients.resource_registry.create
#        self.mock_rr_read = self.ext_obs_service.clients.resource_registry.read
#        self.mock_rr_update = self.ext_obs_service.clients.resource_registry.update
#        self.mock_rr_delete = self.ext_obs_service.clients.resource_registry.delete
#        self.mock_rr_find = self.ext_obs_service.clients.resource_registry.find_objects
#        self.mock_rr_assoc = self.ext_obs_service.clients.resource_registry.find_associations
#        self.mock_rr_create_assoc = self.ext_obs_service.clients.resource_registry.create_association
#        self.mock_rr_del_assoc = self.ext_obs_service.clients.resource_registry.delete_association

        self.mock_pd_create = self.ext_obs_service.clients.process_dispatcher_service.create_process_definition
        self.mock_pd_read = self.ext_obs_service.clients.process_dispatcher_service.read_process_definition
        self.mock_pd_update = self.ext_obs_service.clients.process_dispatcher_service.update_process_definition
        self.mock_pd_delete = self.ext_obs_service.clients.process_dispatcher_service.delete_process_definition
        self.mock_pd_schedule = self.ext_obs_service.clients.process_dispatcher_service.schedule_process
        self.mock_pd_cancel = self.ext_obs_service.clients.process_dispatcher_service.cancel_process

        self.mock_ps_create_stream = self.ext_obs_service.clients.pubsub_management.create_stream
        self.mock_ps_create_sub = self.ext_obs_service.clients.pubsub_management.create_subscription
        self.mock_ps_register = self.ext_obs_service.clients.pubsub_management.register_producer
        self.mock_ps_activate = self.ext_obs_service.clients.pubsub_management.activate_subscription
        self.mock_ps_read_sub = self.ext_obs_service.clients.pubsub_management.read_subscription

        self.mock_cc_spawn = self.ext_obs_service.container.spawn_process
        self.mock_cc_terminate = self.ext_obs_service.container.proc_manager.terminate_process

    @unittest.skip("Not Working")
    def test_spawn_worker(self):

        #mocks
        self.mock_cc_spawn.return_value = 'mock_pid'
        self.mock_ps_read_sub.return_value = DotDict({'exchange_name':'mock_exchange'})
#        self.mock_rr_create.return_value = ('mock_eoas_id','junk')

        #execution
        res = self.ext_obs_service.spawn_worker('resource_id')
        log.debug(res)
        print res

        #assertions
#        self.mock_ps_read_sub.assert_called_once_with(resource_id='resource_id')
        self.assertTrue(False)
        self.assertTrue(self.mock_cc_spawn.called)
        self.assertEquals(res, 'mock_pid')