def test_get_reason_without_blocking_bugs(self): args = check_blockers.parse_args(['check', 'master', '17']) with patch('check_blockers.get_json') as gj: code, reason = check_blockers.get_reason({}, args) self.assertEqual(0, code) self.assertEqual('No blocking bugs', reason) self.assertEqual(0, gj.call_count)
def test_parse_args_update(self): args = check_blockers.parse_args( ['-c', './foo.cred', 'update', 'MASTER', '1234']) self.assertEqual('update', args.command) self.assertEqual('master', args.branch) self.assertEqual('1234', args.build) self.assertEqual('./foo.cred', args.credentials_file)
def test_get_reason_with_blockers_no_match(self): args = check_blockers.parse_args(['check', 'master', '17']) with patch('check_blockers.get_json') as gj: gj.return_value = [{'body': '$$merge$$', 'user': OTHER_USER}] bugs = {'98765': {'self_link': 'https://lp/j/98765'}} code, reason = check_blockers.get_reason(bugs, args) self.assertEqual(1, code) self.assertEqual("Does not match ['fixes-98765']", reason)
def test_get_reason_without_comments(self): args = check_blockers.parse_args(['check', 'master', '17']) with patch('check_blockers.get_json') as gj: gj.return_value = [] bugs = {'98765': {'self_link': 'https://lp/j/98765'}} code, reason = check_blockers.get_reason(bugs, args) self.assertEqual(1, code) self.assertEqual("Does not match ['fixes-98765']", reason) gj.assert_called_with((check_blockers.GH_COMMENTS.format('17')))
def test_get_reason_with_blockers_with_jfdi(self): args = check_blockers.parse_args(['check', 'master', '17']) with patch('check_blockers.get_json') as gj: gj.return_value = [ {'body': '$$merge$$', 'user': OTHER_USER}, {'body': 'la la __JFDI__ ha ha', 'user': OTHER_USER}] bugs = {'98765': {'self_link': 'https://lp/j/98765'}} code, reason = check_blockers.get_reason(bugs, args) self.assertEqual(0, code) self.assertEqual("Engineer says JFDI", reason)
def test_main_block_ci_testing(self): bugs = {} args = check_blockers.parse_args(['block-ci-testing', 'feature']) with patch('check_blockers.get_lp', autospec=True, return_value='lp') as gl: with patch('check_blockers.get_lp_bugs', autospec=True, return_value=bugs) as glb: with patch('check_blockers.get_reason', autospec=True, return_value=(0, 'foo')) as gr: code = check_blockers.main(['block-ci-testing', 'feature']) gl.assert_called_with('check_blockers', credentials_file=None) glb.assert_called_with('lp', 'feature', ['block-ci-testing']) gr.assert_called_with(bugs, args) self.assertEqual(0, code)
def test_get_reason_with_blockers_with_jfdi(self): args = check_blockers.parse_args(['check', 'master', '17']) with patch('check_blockers.get_json') as gj: gj.return_value = [{ 'body': '$$merge$$', 'user': OTHER_USER }, { 'body': 'la la __JFDI__ ha ha', 'user': OTHER_USER }] bugs = {'98765': {'self_link': 'https://lp/j/98765'}} code, reason = check_blockers.get_reason(bugs, args) self.assertEqual(0, code) self.assertEqual("Engineer says JFDI", reason)
def test_main_check(self): bugs = {} args = check_blockers.parse_args(['check', 'master', '17']) with patch('check_blockers.get_lp', autospec=True, return_value='lp') as gl: with patch('check_blockers.get_lp_bugs', autospec=True, return_value=bugs) as glb: with patch('check_blockers.get_reason', autospec=True, return_value=(0, 'foo')) as gr: code = check_blockers.main(['check', 'master', '17']) gl.assert_called_with('check_blockers', credentials_file=None) glb.assert_called_with('lp', 'master', ['blocker']) gr.assert_called_with(bugs, args) self.assertEqual(0, code)
def test_parse_args_check_branch_optional(self): args = check_blockers.parse_args(['check']) self.assertEqual('check', args.command) self.assertEqual('master', args.branch) self.assertIsNone(args.pull_request)
def test_parse_args_block_ci_testing(self): args = check_blockers.parse_args(['block-ci-testing', 'FEATURE']) self.assertEqual('block-ci-testing', args.command) self.assertEqual('feature', args.branch) self.assertIsNone(args.pull_request)
def test_parse_args_check(self): args = check_blockers.parse_args(['check', 'MASTER', '17']) self.assertEqual('check', args.command) self.assertEqual('master', args.branch) self.assertEqual('17', args.pull_request)