def setUp(self): helpers.patch(self, [ 'daemon.main.load_sanity_check_testcase_ids', 'daemon.main.reset_and_run_testcase', 'daemon.main.update_auth_header', 'daemon.main.load_new_testcases', 'daemon.main.prepare_binary_and_get_version', 'time.sleep' ]) self.mock_os_environment({'RELEASE': 'release-test'}) self.setup_fake_filesystem() self.mock.load_sanity_check_testcase_ids.return_value = [1, 2] self.mock.load_new_testcases.side_effect = [[ main.Testcase(3, 'job'), main.Testcase(4, 'job') ], [main.Testcase(5, 'job')], []]
def test_get_testcase(self): """Tests get testcase.""" resp = mock.Mock() resp.json.return_value = { 'items': [ { 'jobType': 'supported', 'id': 12345 }, { 'jobType': 'unsupported', 'id': 98765 }, { 'jobType': 'support', 'id': 23456 }, { 'jobType': 'supported', 'id': 23456 }, { 'jobType': 'supported', 'id': 30 }, ] } self.mock.post.return_value = resp main.TESTCASE_CACHE[30] = True result = main.load_new_testcases() self.assertEqual([ main.Testcase(12345, 'supported'), main.Testcase(23456, 'support') ], result) self.assert_exact_calls(self.mock.post, [ mock.call('https://clusterfuzz.com/v2/testcases/load', headers={'Authorization': 'Bearer xyzabc'}, json={ 'page': 1, 'reproducible': 'yes' }), mock.call('https://clusterfuzz.com/v2/testcases/load', headers={'Authorization': 'Bearer xyzabc'}, json={ 'page': 2, 'reproducible': 'yes' }) ])
def test_get_testcase(self): """Tests get testcase.""" resp = mock.Mock() resp.json.side_effect = ([{ 'items': [ { 'jobType': 'supported', 'id': 12345 }, { 'jobType': 'unsupported', 'id': 98765 }, { 'jobType': 'support', 'id': 23456 }, { 'jobType': 'supported', 'id': 23456 }, { 'jobType': 'supported', 'id': 1337 }, ] }] * 15 + [{ 'items': [] }]) self.mock.post.return_value = resp main.PROCESSED_TESTCASE_IDS.add(1337) result = main.load_new_testcases() self.assertEqual([ main.Testcase(12345, 'supported'), main.Testcase(23456, 'support') ], result) self.assert_exact_calls(self.mock.post, [ mock.call('https://clusterfuzz.com/v2/testcases/load', headers={'Authorization': 'Bearer xyzabc'}, json={ 'page': page, 'reproducible': 'yes', 'q': 'platform:linux', 'open': 'yes' }) for page in xrange(1, 17) ])
def setUp(self): helpers.patch(self, [ 'daemon.main.load_sanity_check_testcase_ids', 'daemon.main.reset_and_run_testcase', 'daemon.main.update_auth_header', 'daemon.main.load_new_testcases', 'time.sleep' ]) self.setup_fake_filesystem() self.mock.load_sanity_check_testcase_ids.return_value = [1, 2] self.mock.load_new_testcases.side_effect = [[ main.Testcase(3, 'job'), main.Testcase(4, 'job') ], [main.Testcase(5, 'job')]] self.mock.reset_and_run_testcase.side_effect = [ None, None, None, None, SystemExit ]
def test_get_testcase(self): """Tests get testcase.""" self.mock.is_time_valid.side_effect = lambda t: t != 2 self.mock.randint.return_value = 6 self.mock.get_supported_jobtypes.return_value = {'chromium': [ 'supported0', 'supported1']} resp = mock.Mock() resp.json.side_effect = ( [{ 'items': [ {'jobType': 'supported0', 'id': 12345, 'timestamp': 1}, {'jobType': 'supported0', 'id': 555, 'timestamp': 2.2}, {'jobType': 'unsupported', 'id': 98765, 'timestamp': 3}, {'jobType': 'supported1', 'id': 23456, 'timestamp': 4}, {'jobType': 'supported0', 'id': 23456, 'timestamp': 5}, {'jobType': 'supported0', 'id': 1337, 'timestamp': 6}, ] }] * 15 + [{'items': []}] ) self.mock.post.return_value = resp main.PROCESSED_TESTCASE_IDS[1337] = True result = main.load_new_testcases() self.assertEqual( [main.Testcase(12345, 'supported0'), main.Testcase(23456, 'supported1')], result) self.assert_exact_calls(self.mock.post, [ mock.call( 'https://clusterfuzz.com/v2/testcases/load', headers={'Authorization': 'Bearer xyzabc'}, json={'page': page, 'reproducible': 'yes', 'q': 'platform:linux', 'open': 'yes', 'project': 'chromium'}) for page in xrange(1, 17) ])