Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _build_client(self):
self.options.p4_client = 'myclient'
self.options.p4_port = 'perforce.example.com:1666'
self.options.p4_passwd = ''
client = PerforceClient(self.P4DiffTestWrapper, options=self.options)
client.p4d_version = (2012, 2)
return client
"""Testing PerforceClient.get_repository_info outside client root"""
SERVER_PATH = 'perforce.example.com:1666'
class TestWrapper(P4Wrapper):
def is_supported(self):
return True
def info(self):
return {
'Client root': '/',
'Server address': SERVER_PATH,
'Server version': 'P4D/FREEBSD60X86_64/2012.2/525804 '
'(2012/09/18)',
}
client = PerforceClient(TestWrapper)
info = client.get_repository_info()
self.assertEqual(info, None)
def test_scan_for_server_counter_with_reviewboard_url_encoded(self):
"""Testing PerforceClient.scan_for_server_counter with encoded reviewboard.url.http:||"""
URL_KEY = 'reviewboard.url.http:||reviewboard.example.com/'
RB_URL = 'http://reviewboard.example.com/'
class TestWrapper(P4Wrapper):
def counters(self):
return {
URL_KEY: '1',
'foo': 'bar',
}
client = PerforceClient(TestWrapper)
url = client.scan_for_server_counter(None)
self.assertEqual(url, RB_URL)
def test_scan_for_server_counter_with_reviewboard_url(self):
"""Testing PerforceClient.scan_for_server_counter with reviewboard.url"""
RB_URL = 'http://reviewboard.example.com/'
class TestWrapper(P4Wrapper):
def counters(self):
return {
'reviewboard.url': RB_URL,
'foo': 'bar',
}
client = PerforceClient(TestWrapper)
url = client.scan_for_server_counter(None)
self.assertEqual(url, RB_URL)
def test_parse_revision_spec_shelved_cln(self):
"""Testing PerforceClient.parse_revision_spec with a shelved changelist"""
class TestWrapper(P4Wrapper):
def change(self, changelist):
return [{
'Change': '12345',
'Date': '2013/12/19 11:32:45',
'User': 'example',
'Status': 'shelved',
'Description': 'My change description\n',
}]
client = PerforceClient(TestWrapper)
revisions = client.parse_revision_spec(['12345'])
self.assertTrue(isinstance(revisions, dict))
self.assertTrue('base' in revisions)
self.assertTrue('tip' in revisions)
self.assertTrue('parent_base' not in revisions)
self.assertEqual(
revisions['base'], PerforceClient.REVISION_CURRENT_SYNC)
self.assertEqual(
revisions['tip'],
PerforceClient.REVISION_PENDING_CLN_PREFIX + '12345')
sys.exit(1)
# Verify that options specific to an SCM Client have not been mis-used.
if (getattr(options, 'change_only', False) and
not repository_info.supports_changesets):
sys.stderr.write('The --change-only option is not valid for the '
'current SCM client.\n')
sys.exit(1)
if (getattr(options, 'parent_branch', None) and
not repository_info.supports_parent_diffs):
sys.stderr.write('The --parent option is not valid for the '
'current SCM client.\n')
sys.exit(1)
if (not isinstance(tool, PerforceClient) and
(getattr(options, 'p4_client', None) or
getattr(options, 'p4_port', None))):
sys.stderr.write('The --p4-client and --p4-port options are not valid '
'for the current SCM client.\n')
sys.exit(1)
return (repository_info, tool)
# TODO: Maybe support a server per remote later? Is that useful?
url = execute([self.git, "config", "--get", "reviewboard.url"],
ignore_errors=True).strip()
if url:
return url
if self.type == "svn":
# Try using the reviewboard:url property on the SVN repo, if it
# exists.
prop = SVNClient().scan_for_server_property(repository_info)
if prop:
return prop
elif self.type == 'perforce':
prop = PerforceClient().scan_for_server(repository_info)
if prop:
return prop
return None