def testCloudSdk(self, mock_invoked, mock_version): mock_invoked.return_value = True mock_version.return_value = '500.1' self.assertRegexpMatches(GetUserAgent(['help']), r"google-cloud-sdk/500.1$") mock_invoked.return_value = False mock_version.return_value = '500.1' self.assertRegexpMatches(GetUserAgent(['help']), r"command/help$")
def testCpDaisyChain(self): self.assertRegexpMatches( GetUserAgent(['cp', '-r', '-Z', 'gs://src', 's3://dst']), r"command/cp-DaisyChain") self.assertRegexpMatches( GetUserAgent(['mv', 'gs://src/1.txt', 's3://dst/1.txt']), r"command/mv-DaisyChain") self.assertRegexpMatches( GetUserAgent(['rsync', '-r', 'gs://src', 's3://dst']), r"command/rsync-DaisyChain")
def testHelp(self): self.assertRegexpMatches(GetUserAgent(['help']), r"command/help")
def testInteractiveFlag(self, mock_interactive): mock_interactive.return_value = True self.assertRegexpMatches(GetUserAgent([]), r"interactive/True") mock_interactive.return_value = False self.assertRegexpMatches(GetUserAgent([]), r"interactive/False")
def testAnalyticsFlag(self): self.assertRegexpMatches(GetUserAgent([], False), r"analytics/enabled") self.assertRegexpMatches(GetUserAgent([], True), r"analytics/disabled")
def testCp(self): self.assertRegexpMatches( GetUserAgent(['cp', '-r', '-Z', '1.txt', 'gs://dst']), r"command/cp$")
def testCpCloudToCloud(self, mock_invoked): mock_invoked.return_value = False self.assertRegexpMatches( GetUserAgent(['cp', '-r', 'gs://src', 'gs://dst']), r"command/cp$")
def testRsync(self, mock_invoked): mock_invoked.return_value = False self.assertRegexpMatches(GetUserAgent(['rsync', '1.txt', 'gs://dst']), r"command/rsync$")
def testCpForcedDaisyChain(self): self.assertRegexpMatches( GetUserAgent(['cp', '-D', 'gs://src', 'gs://dst']), r"command/cp$")
def testCpCloudToCloud(self): self.assertRegexpMatches( GetUserAgent(['cp', '-r', 'gs://src', 'gs://dst']), r"command/cp$")
def testMv(self): self.assertRegexpMatches( GetUserAgent(['mv', 'gs://src/1.txt', 'gs://dst/1.txt']), r"command/mv$")
def testRsync(self): self.assertRegexpMatches(GetUserAgent(['rsync', '1.txt', 'gs://dst']), r"command/rsync$")
def testCpEncoding(self): self.assertRegexpMatches(GetUserAgent(['cp', 'öne', 'twö']), r"command/cp$")
def testCpNotEnoughArgs(self): self.assertRegexpMatches(GetUserAgent(['cp']), r"command/cp$") self.assertRegexpMatches(GetUserAgent(['cp', '1.txt']), r"command/cp$") self.assertRegexpMatches(GetUserAgent(['cp', '-r', '1.ts']), r"command/cp$")
def testCpNotEnoughArgs(self, mock_invoked): mock_invoked.return_value = False self.assertRegexpMatches(GetUserAgent(['cp']), r"command/cp$") self.assertRegexpMatches(GetUserAgent(['cp', '1.txt']), r"command/cp$") self.assertRegexpMatches(GetUserAgent(['cp', '-r', '1.ts']), r"command/cp$")
def testCpEncoding(self, mock_invoked): mock_invoked.return_value = False self.assertRegexpMatches(GetUserAgent(['cp', 'öne', 'twö']), r"command/cp$")
def testPassOnInvalidUrlError(self): self.assertRegexpMatches( GetUserAgent(['cp', '-r', '-Z', 'bad://src', 's3://dst']), r"command/cp$")
def testMv(self, mock_invoked): mock_invoked.return_value = False self.assertRegexpMatches( GetUserAgent(['mv', 'gs://src/1.txt', 'gs://dst/1.txt']), r"command/mv$")
def testPassOnInvalidUrlError(self, mock_invoked): mock_invoked.return_value = False self.assertRegexpMatches( GetUserAgent(['cp', '-r', '-Z', 'bad://src', 's3://dst']), r"command/cp$")
def testCpForcedDaisyChain(self, mock_invoked): mock_invoked.return_value = False self.assertRegexpMatches( GetUserAgent(['cp', '-D', 'gs://src', 'gs://dst']), r"command/cp$")
def testRewriteEncryptionKeyAndStorageClass(self, mock_invoked): mock_invoked.return_value = False self.assertRegexpMatches( GetUserAgent(['rewrite', '-k', '-s', 'gs://dst']), r"command/rewrite-k-s$")
try: opts, args = GetArgumentsAndOptions() except CommandException as e: reason = e.reason if e.informational else 'CommandException: %s' % e.reason err = '%s\n' % reason try: text_util.print_to_fd(err, end='', file=sys.stderr) except UnicodeDecodeError: # Can happen when outputting invalid Unicode filenames. sys.stderr.write(err) if e: metrics.LogFatalError(e) sys.exit(1) # This calculated user agent can be stored for use in StorageV1. gslib.USER_AGENT = GetUserAgent(args, metrics.MetricsCollector.IsDisabled()) boto.UserAgent += gslib.USER_AGENT # pylint: disable=g-bad-import-order import httplib2 import oauth2client from google_reauth import reauth_creds from google_reauth import errors as reauth_errors from gslib import context_config from gslib import wildcard_iterator from gslib.cloud_api import AccessDeniedException from gslib.cloud_api import ArgumentException from gslib.cloud_api import BadRequestException from gslib.cloud_api import ProjectIdException from gslib.cloud_api import ServiceException from gslib.command_runner import CommandRunner
def testNoArgs(self): self.assertRegexpMatches(GetUserAgent([]), r"^ gsutil/4_test \([^\)]+\)")