def test_jobsubmission_attr(self): """Test __getattr__""" api = mock.create_autospec(BatchAppsApi) job = JobSubmission(api, "test_job", params={}, settings="test_settings") job.test = "my_param" job.data = "my_data" job.number = 42 #with self.assertRaises(AttributeError): job.none_obj = None #with self.assertRaises(AttributeError): job.dict_obj = {"a": []} self.assertEqual(job.params["test"], "my_param") self.assertEqual(job.params["data"], "my_data") self.assertEqual(job.params["number"], "42") self.assertEqual(job.test, "my_param") self.assertEqual(job.data, "my_data") self.assertEqual(job.number, "42") self.assertEqual(job.settings, "test_settings") self.assertEqual(job.none_obj, "None") self.assertEqual(job.dict_obj, "{'a': []}") with self.assertRaises(AttributeError): print(job.other_obj) job.source = "my_file.txt" del job.source with self.assertRaises(AttributeError): self.assertEqual(job.source, "") del job.test with self.assertRaises(AttributeError): print(job.test) with self.assertRaises(AttributeError): del job.new_data
def test_jobsubmission_attr(self): """Test __getattr__""" api = mock.create_autospec(BatchAppsApi) job = JobSubmission(api, "test_job", params={}, settings="test_settings") job.test = "my_param" job.data = "my_data" job.number = 42 #with self.assertRaises(AttributeError): job.none_obj = None #with self.assertRaises(AttributeError): job.dict_obj = {"a":[]} self.assertEqual(job.params["test"], "my_param") self.assertEqual(job.params["data"], "my_data") self.assertEqual(job.params["number"], "42") self.assertEqual(job.test, "my_param") self.assertEqual(job.data, "my_data") self.assertEqual(job.number, "42") self.assertEqual(job.settings, "test_settings") self.assertEqual(job.none_obj, "None") self.assertEqual(job.dict_obj, "{'a': []}") with self.assertRaises(AttributeError): print(job.other_obj) job.source = "my_file.txt" del job.source with self.assertRaises(AttributeError): self.assertEqual(job.source, "") del job.test with self.assertRaises(AttributeError): print(job.test) with self.assertRaises(AttributeError): del job.new_data
def test_jobsubmission_create_job_message(self, mock_filter, mock_pool): """Test _create_job_message""" api = mock.create_autospec(BatchAppsApi) api.jobtype.return_value = "TestApp" mock_pool.return_value = {"autopool":"0"} files = mock.create_autospec(FileCollection) files._get_message.return_value = ["file1", "file2"] files.__len__.return_value = 2 mock_filter.return_value = [{"Name":"k1", "Value":"v1"}] job = JobSubmission(api, "test_job", params={}) job.instances = -1 #with self.assertRaises(ValueError): msg = job._create_job_message() mock_pool.assert_called_with(1) self.assertEqual(msg, {'Name':'test_job', 'Type': 'TestApp', 'RequiredFiles':[], 'autoPoolSpecification': {"autopool":"0"}, 'Parameters':[{"Name":"k1", "Value":"v1"}], 'JobFile':'', 'Settings':'', 'Priority':'Medium'}) job.required_files = files job.instances = 5 job.settings = "blah" msg = job._create_job_message() mock_pool.assert_called_with(5) self.assertEqual(msg, {'Name':'test_job', 'Type': 'TestApp', 'RequiredFiles':["file1", "file2"], 'autoPoolSpecification': {"autopool":"0"}, 'Parameters':[{"Name":"k1", "Value":"v1"}], 'JobFile':'', 'Settings':'blah', 'Priority':'Medium'}) job.source = None job.instances = [] job.type = 42 job.name = {} job.pool = "testID" msg = job._create_job_message() self.assertEqual(msg, {'Name':'{}', 'Type': 'TestApp', 'RequiredFiles':["file1", "file2"], 'poolId': "testID", 'Parameters':[{"Name":"k1", "Value":"v1"}], 'JobFile':'None', 'Settings':'blah', 'Priority':'Medium'}) job.pool = mock.create_autospec(Pool) job.pool.id = "differentID" msg = job._create_job_message() self.assertEqual(msg, {'Name':'{}', 'Type': 'TestApp', 'RequiredFiles':["file1", "file2"], 'poolId': "differentID", 'Parameters':[{"Name":"k1", "Value":"v1"}], 'JobFile':'None', 'Settings':'blah', 'Priority':'Medium'})
def test_jobsubmission_create_job_message(self, mock_filter, mock_pool): """Test _create_job_message""" api = mock.create_autospec(BatchAppsApi) api.jobtype.return_value = "TestApp" mock_pool.return_value = {"autopool": "0"} files = mock.create_autospec(FileCollection) files._get_message.return_value = ["file1", "file2"] files.__len__.return_value = 2 mock_filter.return_value = [{"Name": "k1", "Value": "v1"}] job = JobSubmission(api, "test_job", params={}) job.instances = -1 #with self.assertRaises(ValueError): msg = job._create_job_message() mock_pool.assert_called_with(1) self.assertEqual( msg, { 'Name': 'test_job', 'Type': 'TestApp', 'RequiredFiles': [], 'autoPoolSpecification': { "autopool": "0" }, 'Parameters': [{ "Name": "k1", "Value": "v1" }], 'JobFile': '', 'Settings': '', 'Priority': 'Medium' }) job.required_files = files job.instances = 5 job.settings = "blah" msg = job._create_job_message() mock_pool.assert_called_with(5) self.assertEqual( msg, { 'Name': 'test_job', 'Type': 'TestApp', 'RequiredFiles': ["file1", "file2"], 'autoPoolSpecification': { "autopool": "0" }, 'Parameters': [{ "Name": "k1", "Value": "v1" }], 'JobFile': '', 'Settings': 'blah', 'Priority': 'Medium' }) job.source = None job.instances = [] job.type = 42 job.name = {} job.pool = "testID" msg = job._create_job_message() self.assertEqual( msg, { 'Name': '{}', 'Type': 'TestApp', 'RequiredFiles': ["file1", "file2"], 'poolId': "testID", 'Parameters': [{ "Name": "k1", "Value": "v1" }], 'JobFile': 'None', 'Settings': 'blah', 'Priority': 'Medium' }) job.pool = mock.create_autospec(Pool) job.pool.id = "differentID" msg = job._create_job_message() self.assertEqual( msg, { 'Name': '{}', 'Type': 'TestApp', 'RequiredFiles': ["file1", "file2"], 'poolId': "differentID", 'Parameters': [{ "Name": "k1", "Value": "v1" }], 'JobFile': 'None', 'Settings': 'blah', 'Priority': 'Medium' })