How to use get_test_views method in autotest

Best Python code snippet using autotest_python

rpc_interface_unittest_fixme.py

Source:rpc_interface_unittest_fixme.py Github

copy

Full Screen

...182 self._create_initial_data()183 def tearDown(self):184 setup_test_environment.tear_down()185 self.god.unstub_all()186 def _check_for_get_test_views(self, test):187 self.assertEquals(test['test_name'], 'mytest1')188 self.assertEquals(test['job_tag'], '1-myjobtag1')189 self.assertEquals(test['job_name'], 'myjob1')190 self.assertEquals(test['job_owner'], 'myuser')191 self.assertEquals(test['status'], 'GOOD')192 self.assertEquals(test['hostname'], 'myhost')193 self.assertEquals(test['kernel'], 'mykernel1')194 def test_get_detailed_test_views(self):195 test = rpc_interface.get_detailed_test_views()[0]196 self._check_for_get_test_views(test)197 self.assertEquals(test['attributes'], {'myattr': 'myval',198 'myattr2': 'myval2'})199 self.assertEquals(test['iterations'], [{'attr': {'iattr': 'ival',200 'iattr2': 'ival2'},201 'perf': {'iresult': 1,202 'iresult2': 2}},203 {'attr': {},204 'perf': {'iresult': 3,205 'iresult2': 4}}])206 self.assertEquals(test['labels'], ['testlabel1', 'testlabel2'])207 self.assertEquals(test['job_keyvals'], {'keyval_key': 'keyval_value'})208 def test_test_attributes(self):209 rpc_interface.set_test_attribute('foo', 'bar', test_name='mytest1')210 test = rpc_interface.get_detailed_test_views()[0]211 self.assertEquals(test['attributes'], {'foo': 'bar',212 'myattr': 'myval',213 'myattr2': 'myval2'})214 rpc_interface.set_test_attribute('foo', 'goo', test_name='mytest1')215 test = rpc_interface.get_detailed_test_views()[0]216 self.assertEquals(test['attributes'], {'foo': 'goo',217 'myattr': 'myval',218 'myattr2': 'myval2'})219 rpc_interface.set_test_attribute('foo', None, test_name='mytest1')220 test = rpc_interface.get_detailed_test_views()[0]221 self.assertEquals(test['attributes'], {'myattr': 'myval',222 'myattr2': 'myval2'})223 def test_immutable_attributes(self):224 self.assertRaises(ValueError, rpc_interface.set_test_attribute,225 'myattr', 'foo', test_name='mytest1')226 def test_get_test_views(self):227 tests = rpc_interface.get_test_views()228 self.assertEquals(len(tests), 3)229 test = rpc_interface.get_test_views(230 job_name='myjob1', test_name='mytest1')[0]231 self.assertEquals(tests[0], test)232 self._check_for_get_test_views(test)233 self.assertEquals(234 [], rpc_interface.get_test_views(hostname='fakehost'))235 def _check_test_names(self, tests, expected_names):236 self.assertEquals(set(test['test_name'] for test in tests),237 set(expected_names))238 def test_get_test_views_filter_on_labels(self):239 tests = rpc_interface.get_test_views(include_labels=['testlabel1'])240 self._check_test_names(tests, ['mytest1'])241 tests = rpc_interface.get_test_views(exclude_labels=['testlabel1'])242 self._check_test_names(tests, ['mytest2', 'kernbench'])243 def test_get_test_views_filter_on_attributes(self):244 tests = rpc_interface.get_test_views(245 include_attributes_where='attribute = "myattr" '246 'and value = "myval"')247 self._check_test_names(tests, ['mytest1'])248 tests = rpc_interface.get_test_views(249 exclude_attributes_where='attribute="myattr2"')250 self._check_test_names(tests, ['mytest2', 'kernbench'])251 def test_get_num_test_views(self):252 self.assertEquals(rpc_interface.get_num_test_views(), 3)253 self.assertEquals(rpc_interface.get_num_test_views(254 job_name='myjob1', test_name='mytest1'), 1)255 def test_get_group_counts(self):256 self.assertEquals(rpc_interface.get_num_groups(['job_name']), 2)257 counts = rpc_interface.get_group_counts(['job_name'])258 groups = counts['groups']259 self.assertEquals(len(groups), 2)260 group1, group2 = groups261 self.assertEquals(group1['group_count'], 2)262 self.assertEquals(group1['job_name'], 'myjob1')263 self.assertEquals(group2['group_count'], 1)264 self.assertEquals(group2['job_name'], 'myjob2')265 extra = {'extra' : 'kernel_hash'}266 counts = rpc_interface.get_group_counts(['job_name'],267 header_groups=[('job_name',)],268 extra_select_fields=extra)269 groups = counts['groups']270 self.assertEquals(len(groups), 2)271 group1, group2 = groups272 self.assertEquals(group1['group_count'], 2)273 self.assertEquals(group1['header_indices'], [0])274 self.assertEquals(group1['extra'], 'mykernel1')275 self.assertEquals(group2['group_count'], 1)276 self.assertEquals(group2['header_indices'], [1])277 self.assertEquals(group2['extra'], 'mykernel2')278 def test_get_status_counts(self):279 counts = rpc_interface.get_status_counts(group_by=['job_name'])280 group1, group2 = counts['groups']281 self.assertEquals(group1['pass_count'], 1)282 self.assertEquals(group1['complete_count'], 2)283 self.assertEquals(group1['incomplete_count'], 0)284 self.assertEquals(group2['pass_count'], 1)285 self.assertEquals(group2['complete_count'], 1)286 self.assertEquals(group2['incomplete_count'], 0)287 def test_get_latest_tests(self):288 counts = rpc_interface.get_latest_tests(group_by=['job_name'])289 group1, group2 = counts['groups']290 self.assertEquals(group1['pass_count'], 0)291 self.assertEquals(group1['complete_count'], 1)292 self.assertEquals(group1['test_idx'], 2)293 self.assertEquals(group2['test_idx'], 3)294 def test_get_latest_tests_extra_info(self):295 counts = rpc_interface.get_latest_tests(group_by=['job_name'],296 extra_info=['job_tag'])297 group1, group2 = counts['groups']298 self.assertEquals(group1['extra_info'], ['1-myjobtag1'])299 self.assertEquals(group2['extra_info'], ['2-myjobtag2'])300 def test_get_job_ids(self):301 self.assertEquals([1,2], rpc_interface.get_job_ids())302 self.assertEquals([1], rpc_interface.get_job_ids(test_name='mytest2'))303 def test_get_hosts_and_tests(self):304 host_info = rpc_interface.get_hosts_and_tests()305 self.assertEquals(len(host_info), 1)306 info = host_info['myhost']307 self.assertEquals(info['tests'], ['kernbench'])308 self.assertEquals(info['id'], 1)309 def _check_for_get_test_labels(self, label, label_num):310 self.assertEquals(label['id'], label_num)311 self.assertEquals(label['description'], '')312 self.assertEquals(label['name'], 'testlabel%d' % label_num)313 def test_test_labels(self):314 labels = rpc_interface.get_test_labels_for_tests(test_name='mytest1')315 self.assertEquals(len(labels), 2)316 label1 = labels[0]317 label2 = labels[1]318 self._check_for_get_test_labels(label1, 1)319 self._check_for_get_test_labels(label2, 2)320 rpc_interface.test_label_remove_tests(label1['id'], test_name='mytest1')321 labels = rpc_interface.get_test_labels_for_tests(test_name='mytest1')322 self.assertEquals(len(labels), 1)323 label = labels[0]324 self._check_for_get_test_labels(label, 2)325 rpc_interface.test_label_add_tests(label1['id'], test_name='mytest1')326 labels = rpc_interface.get_test_labels_for_tests(test_name='mytest1')327 self.assertEquals(len(labels), 2)328 label1 = labels[0]329 label2 = labels[1]330 self._check_for_get_test_labels(label1, 1)331 self._check_for_get_test_labels(label2, 2)332 def test_get_test_attribute_fields(self):333 tests = rpc_interface.get_test_views(334 test_attribute_fields=['myattr', 'myattr2'])335 self.assertEquals(len(tests), 3)336 self.assertEquals(tests[0]['test_attribute_myattr'], 'myval')337 self.assertEquals(tests[0]['test_attribute_myattr2'], 'myval2')338 for index in (1, 2):339 self.assertEquals(tests[index]['test_attribute_myattr'], None)340 self.assertEquals(tests[index]['test_attribute_myattr2'], None)341 def test_filtering_on_test_attribute_fields(self):342 tests = rpc_interface.get_test_views(343 extra_where='test_attribute_myattr.value = "myval"',344 test_attribute_fields=['myattr'])345 self.assertEquals(len(tests), 1)346 def test_grouping_with_test_attribute_fields(self):347 num_groups = rpc_interface.get_num_groups(348 ['test_attribute_myattr'], test_attribute_fields=['myattr'])349 self.assertEquals(num_groups, 2)350 counts = rpc_interface.get_group_counts(351 ['test_attribute_myattr'], test_attribute_fields=['myattr'])352 groups = counts['groups']353 self.assertEquals(len(groups), num_groups)354 self.assertEquals(groups[0]['test_attribute_myattr'], None)355 self.assertEquals(groups[0]['group_count'], 2)356 self.assertEquals(groups[1]['test_attribute_myattr'], 'myval')357 self.assertEquals(groups[1]['group_count'], 1)358 def test_extra_info_test_attributes(self):359 counts = rpc_interface.get_latest_tests(360 group_by=['test_idx'], extra_info=['test_attribute_myattr'],361 test_attribute_fields=['myattr'])362 group1 = counts['groups'][0]363 self.assertEquals(group1['extra_info'], ['myval'])364 def test_get_test_label_fields(self):365 tests = rpc_interface.get_test_views(366 test_label_fields=['testlabel1', 'testlabel2'])367 self.assertEquals(len(tests), 3)368 self.assertEquals(tests[0]['test_label_testlabel1'], 'testlabel1')369 self.assertEquals(tests[0]['test_label_testlabel2'], 'testlabel2')370 for index in (1, 2):371 self.assertEquals(tests[index]['test_label_testlabel1'], None)372 self.assertEquals(tests[index]['test_label_testlabel2'], None)373 def test_filtering_on_test_label_fields(self):374 tests = rpc_interface.get_test_views(375 extra_where='test_label_testlabel1 = "testlabel1"',376 test_label_fields=['testlabel1'])377 self.assertEquals(len(tests), 1)378 def test_grouping_on_test_label_fields(self):379 num_groups = rpc_interface.get_num_groups(380 ['test_label_testlabel1'], test_label_fields=['testlabel1'])381 self.assertEquals(num_groups, 2)382 counts = rpc_interface.get_group_counts(383 ['test_label_testlabel1'], test_label_fields=['testlabel1'])384 groups = counts['groups']385 self.assertEquals(len(groups), 2)386 self.assertEquals(groups[0]['test_label_testlabel1'], None)387 self.assertEquals(groups[0]['group_count'], 2)388 self.assertEquals(groups[1]['test_label_testlabel1'], 'testlabel1')389 self.assertEquals(groups[1]['group_count'], 1)390 def test_get_iteration_result_fields(self):391 num_iterations = rpc_interface.get_num_test_views(392 iteration_result_fields=['iresult', 'iresult2'])393 self.assertEquals(num_iterations, 2)394 iterations = rpc_interface.get_test_views(395 iteration_result_fields=['iresult', 'iresult2'])396 self.assertEquals(len(iterations), 2)397 for index in (0, 1):398 self.assertEquals(iterations[index]['test_idx'], 1)399 self.assertEquals(iterations[0]['iteration_index'], 1)400 self.assertEquals(iterations[0]['iteration_result_iresult'], 1)401 self.assertEquals(iterations[0]['iteration_result_iresult2'], 2)402 self.assertEquals(iterations[1]['iteration_index'], 2)403 self.assertEquals(iterations[1]['iteration_result_iresult'], 3)404 self.assertEquals(iterations[1]['iteration_result_iresult2'], 4)405 def test_filtering_on_iteration_result_fields(self):406 iterations = rpc_interface.get_test_views(407 extra_where='iteration_result_iresult.value = 1',408 iteration_result_fields=['iresult'])409 self.assertEquals(len(iterations), 1)410 def test_grouping_with_iteration_result_fields(self):411 num_groups = rpc_interface.get_num_groups(412 ['iteration_result_iresult'],413 iteration_result_fields=['iresult'])414 self.assertEquals(num_groups, 2)415 counts = rpc_interface.get_group_counts(416 ['iteration_result_iresult'],417 iteration_result_fields=['iresult'])418 groups = counts['groups']419 self.assertEquals(len(groups), 2)420 self.assertEquals(groups[0]['iteration_result_iresult'], 1)421 self.assertEquals(groups[0]['group_count'], 1)422 self.assertEquals(groups[1]['iteration_result_iresult'], 3)423 self.assertEquals(groups[1]['group_count'], 1)424 def _setup_machine_labels(self):425 models.TestAttribute.objects.create(test=self.first_test,426 attribute='host-labels',427 value='label1,label2')428 def test_get_machine_label_fields(self):429 self._setup_machine_labels()430 tests = rpc_interface.get_test_views(431 machine_label_fields=['label1', 'otherlabel'])432 self.assertEquals(len(tests), 3)433 self.assertEquals(tests[0]['machine_label_label1'], 'label1')434 self.assertEquals(tests[0]['machine_label_otherlabel'], None)435 for index in (1, 2):436 self.assertEquals(tests[index]['machine_label_label1'], None)437 self.assertEquals(tests[index]['machine_label_otherlabel'], None)438 def test_grouping_with_machine_label_fields(self):439 self._setup_machine_labels()440 counts = rpc_interface.get_group_counts(['machine_label_label1'],441 machine_label_fields=['label1'])442 groups = counts['groups']443 self.assertEquals(len(groups), 2)444 self.assertEquals(groups[0]['machine_label_label1'], None)445 self.assertEquals(groups[0]['group_count'], 2)446 self.assertEquals(groups[1]['machine_label_label1'], 'label1')447 self.assertEquals(groups[1]['group_count'], 1)448 def test_filtering_on_machine_label_fields(self):449 self._setup_machine_labels()450 tests = rpc_interface.get_test_views(451 extra_where='machine_label_label1 = "label1"',452 machine_label_fields=['label1'])453 self.assertEquals(len(tests), 1)454 def test_quoting_fields(self):455 # ensure fields with special characters are properly quoted throughout456 rpc_interface.add_test_label('hyphen-label')457 rpc_interface.get_group_counts(458 ['test_attribute_hyphen-attr', 'test_label_hyphen-label',459 'machine_label_hyphen-label',460 'iteration_result_hyphen-result'],461 test_attribute_fields=['hyphen-attr'],462 test_label_fields=['hyphen-label'],463 machine_label_fields=['hyphen-label'],464 iteration_result_fields=['hyphen-result'])...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful