class TestInstrumentManagement(PyonTestCase): def setUp(self): self.mock_ionobj = self._create_IonObject_mock('ion.services.sa.instrument.instrument_management_service.IonObject') #self.mock_ionobj = IonObject mock_clients = self._create_service_mock('instrument_management_service') self.instrument_mgmt_service = InstrumentManagementService() self.instrument_mgmt_service.clients = mock_clients # must call this manually self.instrument_mgmt_service.on_init()
def setUp(self): self.mock_ionobj = self._create_IonObject_mock( 'ion.services.sa.instrument.instrument_management_service.IonObject' ) #self.mock_ionobj = IonObject mock_clients = self._create_service_mock('instrument_management') self.instrument_mgmt_service = InstrumentManagementService() self.instrument_mgmt_service.clients = mock_clients # must call this manually self.instrument_mgmt_service.on_init()
class TestInstrumentManagement(PyonTestCase): def setUp(self): self.mock_ionobj = self._create_IonObject_mock('ion.services.sa.instrument.instrument_management_service.IonObject') #self.mock_ionobj = IonObject mock_clients = self._create_service_mock('instrument_management') self.instrument_mgmt_service = InstrumentManagementService() self.instrument_mgmt_service.clients = mock_clients # must call this manually self.instrument_mgmt_service.on_init() self.addCleanup(delattr, self, "instrument_mgmt_service") self.addCleanup(delattr, self, "mock_ionobj") #self.resource_impl_cleanup() log.debug("setUp complete")
def setUp(self): self.mock_ionobj = self._create_IonObject_mock( 'ion.services.sa.instrument.instrument_management_service.IonObject' ) #self.mock_ionobj = IonObject mock_clients = self._create_service_mock('instrument_management') self.instrument_mgmt_service = InstrumentManagementService() self.instrument_mgmt_service.clients = mock_clients # must call this manually self.instrument_mgmt_service.on_init() self.addCleanup(delattr, self, "instrument_mgmt_service") self.addCleanup(delattr, self, "mock_ionobj") #self.resource_impl_cleanup() log.debug("setUp complete")
def setUp(self): self.mock_ionobj = self._create_IonObject_mock('ion.services.sa.instrument.instrument_management_service.IonObject') #self.mock_ionobj = IonObject self.mock_clients = self._create_service_mock('instrument_management') self.RR = self.mock_clients.resource_registry self.IMS = InstrumentManagementService() self.IMS.clients = self.mock_clients # must call this manually self.IMS.on_init() self.IMS.module_uploader = RegisterModulePreparerEgg(dest_user="******", dest_host="my_host", dest_path="/my/remote/wwwroot/my/path", dest_wwwprefix="http://my_host/my/path") self.addCleanup(delattr, self, "IMS") self.addCleanup(delattr, self, "mock_ionobj")
def setUp(self): self.mock_ionobj = self._create_IonObject_mock('ion.services.sa.instrument.instrument_management_service.IonObject') #self.mock_ionobj = IonObject mock_clients = self._create_service_mock('instrument_management') self.instrument_mgmt_service = InstrumentManagementService() self.instrument_mgmt_service.clients = mock_clients # must call this manually self.instrument_mgmt_service.on_init() self.addCleanup(delattr, self, "instrument_mgmt_service") self.addCleanup(delattr, self, "mock_ionobj")
def setUp(self): self.mock_ionobj = self._create_IonObject_mock('ion.services.sa.instrument.instrument_management_service.IonObject') #self.mock_ionobj = IonObject self.mock_clients = self._create_service_mock('instrument_management') self.RR = self.mock_clients.resource_registry self.IMS = InstrumentManagementService() self.IMS.clients = self.mock_clients # must call this manually self.IMS.on_init() self.IMS.module_uploader = RegisterModulePreparerEgg(dest_user="******", dest_host="my_host", dest_path="/my/remote/wwwroot/my/path", dest_wwwprefix="http://my_host/my/path") self.addCleanup(delattr, self, "IMS") self.addCleanup(delattr, self, "mock_ionobj")
class TestIMSRegisterAgent(PyonTestCase): def setUp(self): self.mock_ionobj = self._create_IonObject_mock('ion.services.sa.instrument.instrument_management_service.IonObject') #self.mock_ionobj = IonObject self.mock_clients = self._create_service_mock('instrument_management') self.RR = self.mock_clients.resource_registry self.IMS = InstrumentManagementService() self.IMS.clients = self.mock_clients # must call this manually self.IMS.on_init() self.IMS.module_uploader = RegisterModulePreparerEgg(dest_user="******", dest_host="my_host", dest_path="/my/remote/wwwroot/my/path", dest_wwwprefix="http://my_host/my/path") self.addCleanup(delattr, self, "IMS") self.addCleanup(delattr, self, "mock_ionobj") #self.resource_impl_cleanup() #def resource_impl_cleanup(self): #pass def _mock_uploader_subprocess(self, emulate_success): self.mock_dict = {} popen_mock = Mock() popen_mock.communicate.return_value = ("scp_out dump", "scp_err dump") if emulate_success: popen_mock.returncode = 0 else: popen_mock.returncode = 1 subprocess_mock = Mock() subprocess_mock.Popen.return_value = popen_mock subprocess_mock.PIPE = "MYPIPE" tempfile_mock = Mock() tempfile_mock.mkstemp.return_value = ("my_handle", "my_tempfile_name") self.mock_dict["tempfile"] = tempfile_mock self.mock_dict["subprocess"] = subprocess_mock self.mock_dict["os"] = Mock() self.IMS.module_uploader.modules = self.mock_dict def test_register_instrument_agent_notimpl_unit(self): inst_agent_id = "iaid1" # See OOIION-1655: register_instrument_agent should be re-implemented as part of R3 D041 Data Processing Management Service with self.assertRaises(NotImplementedError): self.IMS.register_instrument_agent(inst_agent_id, BASE64_EGG, BASE64_ZIPFILE) @unittest.skip('OOIION-1655 Implemented as part of R3 D041 Data Processing Management Service') def test_register_instrument_agent_unit(self): # setup inst_agent_id = "iaid1" self._mock_uploader_subprocess(False) self.RR.read.return_value = any_old(RT.InstrumentAgent) self.assertRaises(BadRequest, self.IMS.register_instrument_agent, inst_agent_id, BASE64_EGG, BASE64_ZIPFILE) self.RR.read.assert_called_once_with(inst_agent_id, '') self._mock_uploader_subprocess(True) self.IMS.register_instrument_agent(inst_agent_id, BASE64_EGG, BASE64_ZIPFILE) self.RR.execute_lifecycle_transition.assert_called_once_with(inst_agent_id, LCE.INTEGRATE) remote_cred = "my_user@my_host" remote_path = "/my/remote/wwwroot/my/path/seabird_sbe37smb_ooicore-0.1-py2.7.egg" scp_dest = "%s:%s" % (remote_cred, remote_path) self.mock_dict["subprocess"].Popen.assert_called_any(["scp", "-v", "-o", "PasswordAuthentication=no", "-o", 'StrictHostKeyChecking=no', 'my_tempfile_name', scp_dest], stdout=self.mock_dict["subprocess"].PIPE, stderr=self.mock_dict["subprocess"].PIPE) self.mock_dict["subprocess"].Popen.assert_called_any(["ssh", remote_cred, "chmod", "664", remote_path], stdout=self.mock_dict["subprocess"].PIPE, stderr=self.mock_dict["subprocess"].PIPE) self.assertEqual(4, self.RR.create_attachment.call_count) url_content = "[InternetShortcut]\nURL=http://my_host/my/path/seabird_sbe37smb_ooicore-0.1-py2.7.egg" found = False for acall in self.mock_ionobj.call_args_list: if ("Attachment",) == acall[0]: self.assertEqual(url_content, acall[1]["content"]) found = True self.assertTrue(found, "URL attachment not found")
class TestIMSRegisterAgent(PyonTestCase): def setUp(self): self.mock_ionobj = self._create_IonObject_mock('ion.services.sa.instrument.instrument_management_service.IonObject') #self.mock_ionobj = IonObject self.mock_clients = self._create_service_mock('instrument_management') self.RR = self.mock_clients.resource_registry self.IMS = InstrumentManagementService() self.IMS.clients = self.mock_clients # must call this manually self.IMS.on_init() self.IMS.module_uploader = RegisterModulePreparerEgg(dest_user="******", dest_host="my_host", dest_path="/my/remote/wwwroot/my/path", dest_wwwprefix="http://my_host/my/path") self.addCleanup(delattr, self, "IMS") self.addCleanup(delattr, self, "mock_ionobj") #self.resource_impl_cleanup() #def resource_impl_cleanup(self): #pass def _mock_uploader_subprocess(self, emulate_success): self.mock_dict = {} popen_mock = Mock() popen_mock.communicate.return_value = ("scp_out dump", "scp_err dump") if emulate_success: popen_mock.returncode = 0 else: popen_mock.returncode = 1 subprocess_mock = Mock() subprocess_mock.Popen.return_value = popen_mock subprocess_mock.PIPE = "MYPIPE" tempfile_mock = Mock() tempfile_mock.mkstemp.return_value = ("my_handle", "my_tempfile_name") self.mock_dict["tempfile"] = tempfile_mock self.mock_dict["subprocess"] = subprocess_mock self.mock_dict["os"] = Mock() self.IMS.module_uploader.modules = self.mock_dict def test_register_instrument_agent_unit(self): # setup inst_agent_id = "iaid1" self._mock_uploader_subprocess(False) self.assertRaises(BadRequest, self.IMS.register_instrument_agent, inst_agent_id, BASE64_EGG, BASE64_ZIPFILE) self.RR.read.assert_called_once_with(inst_agent_id, '') self._mock_uploader_subprocess(True) self.IMS.register_instrument_agent(inst_agent_id, BASE64_EGG, BASE64_ZIPFILE) self.RR.execute_lifecycle_transition.assert_called_once_with(inst_agent_id, LCE.INTEGRATE) remote_cred = "my_user@my_host" remote_path = "/my/remote/wwwroot/my/path/seabird_sbe37smb_ooicore-0.1-py2.7.egg" scp_dest = "%s:%s" % (remote_cred, remote_path) self.mock_dict["subprocess"].Popen.assert_called_any(["scp", "-v", "-o", "PasswordAuthentication=no", "-o", 'StrictHostKeyChecking=no', 'my_tempfile_name', scp_dest], stdout=self.mock_dict["subprocess"].PIPE, stderr=self.mock_dict["subprocess"].PIPE) self.mock_dict["subprocess"].Popen.assert_called_any(["ssh", remote_cred, "chmod", "664", remote_path], stdout=self.mock_dict["subprocess"].PIPE, stderr=self.mock_dict["subprocess"].PIPE) self.assertEqual(4, self.RR.create_attachment.call_count) url_content = "[InternetShortcut]\nURL=http://my_host/my/path/seabird_sbe37smb_ooicore-0.1-py2.7.egg" found = False for acall in self.mock_ionobj.call_args_list: if ("Attachment",) == acall[0]: self.assertEqual(url_content, acall[1]["content"]) found = True self.assertTrue(found, "URL attachment not found")