def testConvert_TestResourceDef(self): obj = ndb_models.TestResourceDef( name='foo', default_download_url='bar', decompress=True, decompress_dir='dir', params=ndb_models.TestResourceParameters( decompress_files=['file'])) msg = messages.TestResourceDef( name='foo', default_download_url='bar', decompress=True, decompress_dir='dir', params=messages.TestResourceParameters(decompress_files=['file'])) self.assertSameTestResourceDef( obj, messages.Convert(obj, messages.TestResourceDef)) self.assertSameTestResourceDef( messages.Convert(msg, ndb_models.TestResourceDef), msg) obj = ndb_models.TestResourceDef(name='foo') msg = messages.TestResourceDef(name='foo') self.assertSameTestResourceDef( obj, messages.Convert(obj, messages.TestResourceDef)) self.assertSameTestResourceDef( messages.Convert(msg, ndb_models.TestResourceDef), msg)
def testCreateTestRun(self, mock_find_resources): test = ndb_models.Test( name='test', command='command', test_resource_defs=[ ndb_models.TestResourceDef( name='foo', default_download_url='default_download_url'), ndb_models.TestResourceDef( name='bar', default_download_url='default_download_url', decompress=True, decompress_dir='dir'), ]) test.put() overwritten_obj = ndb_models.TestResourceObj( name='foo', url='origin_url', cache_url='cache_url') test_run_config = ndb_models.TestRunConfig( test_key=test.key, cluster='cluster', device_specs=['device_serial:serial'], test_resource_objs=[overwritten_obj], ) mock_find_resources.return_value = [overwritten_obj] test_run = test_kicker.CreateTestRun(['label'], test_run_config) test_run = ndb_models.TestRun.get_by_id(test_run.key.id()) self.assertModelEqual(test, test_run.test) self.assertEqual(['label'], test_run.labels) self.assertModelEqual(test_run_config, test_run.test_run_config) self.assertModelSetEqual([ ndb_models.TestResourceObj( name='bar', url='default_download_url', decompress=True, decompress_dir='dir', mount_zip=False, params=ndb_models.TestResourceParameters()), ndb_models.TestResourceObj( name='foo', url='origin_url', cache_url='cache_url', decompress=False, decompress_dir='', mount_zip=False, params=ndb_models.TestResourceParameters()), ], test_run.test_resources) self.assertEqual(ndb_models.TestRunState.PENDING, test_run.state) tasks = self.mock_task_scheduler.GetTasks( queue_names=[test_kicker.TEST_KICKER_QUEUE]) self.assertLen(tasks, 1) task = tasks[0] data = json.loads(task.payload) self.assertEqual(test_run.key.id(), data['test_run_id']) self.assertIsNone(test_run.sequence_id)
def testConvertToTestResourceMap_unionDecompressFiles(self): test_resource_defs = [ ndb_models.TestResourceDef( name='foo', decompress=True, decompress_dir='dir', params=ndb_models.TestResourceParameters( decompress_files=['a', 'b'])), ndb_models.TestResourceDef( name='foo', decompress=True, decompress_dir='dir', params=ndb_models.TestResourceParameters( decompress_files=['', 'b', 'c'])), ndb_models.TestResourceDef(name='bar', decompress=True), ndb_models.TestResourceDef( name='bar', decompress=True, params=ndb_models.TestResourceParameters( decompress_files=['bar'])), ] objs = test_kicker._ConvertToTestResourceMap(test_resource_defs) self.assertDictEqual( objs, { 'foo': ndb_models.TestResourceObj( name='foo', decompress=True, decompress_dir='dir', mount_zip=False, params=ndb_models.TestResourceParameters( decompress_files=['a', 'b', 'c'])), 'bar': ndb_models.TestResourceObj( name='bar', decompress=True, decompress_dir='', mount_zip=False, params=ndb_models.TestResourceParameters( decompress_files=[])), }) # Assert that the input objects are unchanged. self.assertEqual(test_resource_defs[0].params.decompress_files, ['a', 'b']) self.assertEqual(test_resource_defs[1].params.decompress_files, ['', 'b', 'c']) self.assertIsNone(test_resource_defs[2].params) self.assertEqual(test_resource_defs[3].params.decompress_files, ['bar'])
def _TestResourceDefMessageConverter(msg): return ndb_models.TestResourceDef( name=msg.name, default_download_url=msg.default_download_url, test_resource_type=msg.test_resource_type, decompress=msg.decompress, decompress_dir=msg.decompress_dir, mount_zip=msg.mount_zip, params=Convert(msg.params, ndb_models.TestResourceParameters))
def testConvertToTestResourceMap_invalidArguments(self): # Test test_resource_type field. with self.assertRaises(ValueError): test_kicker._ConvertToTestResourceMap([ ndb_models.TestResourceDef( name='bar', test_resource_type=ndb_models.TestResourceType.UNKNOWN), ndb_models.TestResourceDef( name='bar', test_resource_type=ndb_models.TestResourceType.DEVICE_IMAGE), ]) # Test decompress field. with self.assertRaises(ValueError): test_kicker._ConvertToTestResourceMap([ ndb_models.TestResourceDef(name='bar', decompress=True), ndb_models.TestResourceDef(name='bar', decompress=False), ]) # Test decompress_dir field. with self.assertRaises(ValueError): test_kicker._ConvertToTestResourceMap([ ndb_models.TestResourceDef(name='bar', decompress=True), ndb_models.TestResourceDef( name='bar', decompress=True, decompress_dir='dir'), ])
def testConvert_Test(self): obj = ndb_models.Test( name='name', test_resource_defs=[ ndb_models.TestResourceDef(name='foo', default_download_url='bar') ], command='command', env_vars=[ ndb_models.NameValuePair(name='name', value='value'), ], output_file_patterns=['pattern_1', 'pattern_2'], setup_scripts=['script_1', 'script_2', 'script_3']) msg = messages.Convert(obj, messages.Test) self.assertIsInstance(msg, messages.Test) self.assertSameTest(obj, msg)
def _CreateMockTest(self): test = ndb_models.Test( name='Foo', test_resource_defs=[ ndb_models.TestResourceDef( name='test_resource_name', default_download_url='test_resource_url'), ], command='command', env_vars=[ ndb_models.NameValuePair(name='env_var_name', value='env_var_value') ], output_file_patterns=['output_file_pattern'], setup_scripts=['setup_script'], jvm_options=['jvm_option'], java_properties=[ ndb_models.NameValuePair(name='java_property_name', value='java_property_value') ]) test.put() return test
def testCreateTestRun_withNodeConfig(self, mock_find_resources): test = ndb_models.Test( name='test', command='command', test_resource_defs=[ ndb_models.TestResourceDef( name='abc', default_download_url='default_download_url'), ndb_models.TestResourceDef( name='def', default_download_url='default_download_url'), ndb_models.TestResourceDef( name='xyz', default_download_url='default_download_url'), ]) test.put() node_config = ndb_models.GetNodeConfig() node_config.env_vars.append( ndb_models.NameValuePair(name='foo', value='bar')) node_config.test_resource_default_download_urls = [ ndb_models.NameValuePair(name='def', value='default_download_url2'), ndb_models.NameValuePair(name='xyz', value='default_download_url2'), ] node_config.put() overwritten_obj = ndb_models.TestResourceObj( name='xyz', url='origin_url', cache_url='cache_url') test_run_config = ndb_models.TestRunConfig( test_key=test.key, cluster='cluster', device_specs=['device_serial:serial'], test_resource_objs=[overwritten_obj]) mock_find_resources.return_value = [overwritten_obj] test_run = test_kicker.CreateTestRun( ['label'], test_run_config) test_run = ndb_models.TestRun.get_by_id(test_run.key.id()) self.assertEqual(test.command, test_run.test.command) self.assertModelListEqual(node_config.env_vars, test_run.test.env_vars) self.assertEqual(['label'], test_run.labels) self.assertModelEqual(test_run_config, test_run.test_run_config) self.assertModelSetEqual([ ndb_models.TestResourceObj( name='abc', url='default_download_url', decompress=False, decompress_dir='', mount_zip=False, params=ndb_models.TestResourceParameters()), ndb_models.TestResourceObj( name='def', url='default_download_url2', decompress=False, decompress_dir='', mount_zip=False, params=ndb_models.TestResourceParameters()), ndb_models.TestResourceObj( name='xyz', url='origin_url', cache_url='cache_url', decompress=False, decompress_dir='', mount_zip=False, params=ndb_models.TestResourceParameters()), ], test_run.test_resources) self.assertEqual(ndb_models.TestRunState.PENDING, test_run.state) tasks = self.mock_task_scheduler.GetTasks( queue_names=[test_kicker.TEST_KICKER_QUEUE]) self.assertEqual(1, len(tasks)) task = tasks[0] data = json.loads(task.payload) self.assertEqual(test_run.key.id(), data['test_run_id'])