def test_ref_name_check_rules(self): # See man git-check-ref-format for the rules referenced here test_strings = [ ('refs/heads/normal', True), ('refs/heads/.bad', False), # rule 1 ('refs/heads/bad.lock', False), # rule 1 ('refs/heads/good.locked', True), ('refs/heads/go.od', True), ('refs/heads//bad', False), # rule 6 ('refs/heads/b?d', False), # rule 5 ('refs/heads/b[d', False), # rule 5 ('refs/heads/b..ad', False), # rule 3 ('bad', False), # rule 2 ('refs/heads/\nbad', False), # rule 4 ('/refs/heads/bad', False), # rule 6 ('refs/heads/bad/', False), # rule 6 ('refs/heads/bad.', False), # rule 7 ('.refs/heads/bad', False), # rule 1 ('refs/he@{ads/bad', False), # rule 8 ('@', False), # rule 9 ('refs\\heads/bad', False) # rule 10 ] for ref, accepted in test_strings: self.assertEqual( accepted, GerritConnection._checkRefFormat(ref), ref + ' shall be ' + ('accepted' if accepted else 'rejected'))
def run_query(self, files, expected_patches, _ssh_mock): gerrit_config = { 'user': '******', 'server': 'localhost', } driver = GerritDriver() gerrit = GerritConnection(driver, 'review_gerrit', gerrit_config) calls, values = read_fixtures(files) _ssh_mock.side_effect = values result = gerrit.simpleQuery('project:openstack-infra/zuul') _ssh_mock.assert_has_calls(calls) self.assertEqual(len(calls), _ssh_mock.call_count, '_ssh should be called %d times' % len(calls)) self.assertIsNotNone(result, 'Result is not none') self.assertEqual(len(result), expected_patches, 'There must be %d patches.' % expected_patches)
def test_getGitURL(self): gerrit_config = { 'user': '******', 'server': 'localhost', 'password': '******', } # The 1/ in the password ensures we test the url encoding # path; this is the format of password we get from # googlesource.com. driver = GerritDriver() gerrit = GerritConnection(driver, 'review_gerrit', gerrit_config) project = gerrit.source.getProject('org/project') url = gerrit.source.getGitUrl(project) self.assertEqual( 'https://*****:*****@localhost/org/project', url)