def testSetOverwritesExisting(self): config_name = 'projects/{0}/configs/foo'.format(self.Project()) var_name = 'projects/{0}/configs/foo/variables/var1'.format( self.Project()) # Short names due to the long class names hitting 80 characters cr_req = self.messages.RuntimeconfigProjectsConfigsVariablesCreateRequest( parent=config_name, variable=self.messages.Variable( name=var_name, value=b'value1', ), ) cr_exception = base.MakeHttpError(409, 'ALREADY_EXISTS') upd_req = self.messages.Variable( name=var_name, value=b'value1', ) upd_result = self.messages.Variable( name=var_name, state=self.messages.Variable.StateValueValuesEnum.UPDATED, updateTime='2016-04-16T00:00:00Z', value=b'value1', ) self.variable_client.Create.Expect(cr_req, exception=cr_exception) self.variable_client.Update.Expect(upd_req, upd_result) got_result = self.RunRuntimeConfig( 'variables set var1 "value1" --config-name foo') self.assertEqual(util.FormatVariable(upd_result), got_result)
def testDeleteNotFound(self): request = self.messages.RuntimeconfigProjectsConfigsWaitersDeleteRequest( name='projects/{0}/configs/foo/waiters/bar'.format( self.Project()), ) exception = base.MakeHttpError(code=404, status='NOT_FOUND') self.waiter_client.Delete.Expect(request, exception=exception) with self.assertRaises(exceptions.HttpException): self.RunRuntimeConfig('waiters delete bar --config-name foo')
def testDeleteNotFound(self): config_name = 'projects/{0}/configs/foobar'.format(self.Project()) expected_request = self.messages.RuntimeconfigProjectsConfigsDeleteRequest( name=config_name, ) wanted_exception = base.MakeHttpError(code=404, status='NOT_FOUND') self.config_client.Delete.Expect(expected_request, exception=wanted_exception) with self.assertRaises(exceptions.HttpException): self.RunRuntimeConfig('delete foobar')
def testGetValueNotFound(self): var_name = 'projects/{0}/configs/foo/variables/var1'.format( self.Project()) request = self.messages.RuntimeconfigProjectsConfigsVariablesGetRequest( name=var_name, ) exception = base.MakeHttpError(code=404, status='NOT_FOUND') self.variable_client.Get.Expect(request, exception=exception) with self.assertRaises(exceptions.HttpException): self.RunRuntimeConfig('variables get-value var1 --config-name foo', output_enabled=True)
def testUnsetIgnoresNotFound(self): request = self.messages.RuntimeconfigProjectsConfigsVariablesDeleteRequest( name='projects/{0}/configs/foo/variables/var1'.format( self.Project()), recursive=False, ) exception = base.MakeHttpError(code=404, status='NOT_FOUND') self.variable_client.Delete.Expect(request, exception=exception) # Should run without raising. self.RunRuntimeConfig('variables unset var1 --config-name foo')
def testUnsetFailIfAbsentFails(self): request = self.messages.RuntimeconfigProjectsConfigsVariablesDeleteRequest( name='projects/{0}/configs/foo/variables/var1'.format( self.Project()), recursive=False, ) exception = base.MakeHttpError(code=404, status='NOT_FOUND') self.variable_client.Delete.Expect(request, exception=exception) with self.assertRaises(exceptions.HttpException): self.RunRuntimeConfig('variables unset var1 --config-name foo ' '--fail-if-absent')
def testUpdateNotFound(self): config_name = 'projects/{0}/configs/foobar'.format(self.Project()) expected_request = self.messages.RuntimeConfig( name=config_name, description='abcd', ) wanted_exception = base.MakeHttpError(code=404, status='NOT_FOUND') self.config_client.Update.Expect(expected_request, exception=wanted_exception) with self.assertRaises(exceptions.HttpException): self.RunRuntimeConfig('update foobar --description="abcd"')
def testListNotFound(self): config_name = 'projects/{0}/configs/foo'.format(self.Project()) request = self.messages.RuntimeconfigProjectsConfigsWaitersListRequest( parent=config_name, pageSize=self.DEFAULT_PAGE_SIZE, ) exception = base.MakeHttpError(code=404, status='NOT_FOUND') self.waiter_client.List.Expect(request, exception=exception) with self.assertRaises(exceptions.HttpException): result = self.RunRuntimeConfig('waiters list --config-name foo') # Evaluate the returned generator to generate the exception list(result)
def testUnsetNonRecursiveFailure(self): request = self.messages.RuntimeconfigProjectsConfigsVariablesDeleteRequest( name='projects/{0}/configs/foo/variables/var1'.format( self.Project()), recursive=False, ) exception = base.MakeHttpError(code=400, status='FAILED_PRECONDITION', message='Contains children') self.variable_client.Delete.Expect(request, exception=exception) with self.assertRaises(exceptions.HttpException): self.RunRuntimeConfig('variables unset var1 --config-name foo')
def testListNotFound(self): expected_request = self.messages.RuntimeconfigProjectsConfigsListRequest( parent='projects/{0}'.format(self.Project()), pageSize=self.DEFAULT_PAGE_SIZE, ) wanted_exception = base.MakeHttpError(code=404, status='NOT_FOUND') self.config_client.List.Expect(expected_request, exception=wanted_exception) with self.assertRaises(exceptions.HttpException): result = self.RunRuntimeConfig('list') # Evaluate the returned generator to generate the exception list(result)
def testSetFailIfAbsentFails(self): # Tests that --fail-if-absent causees an error if the named # variable does not already exist. var_name = 'projects/{0}/configs/foo/variables/var1'.format( self.Project()) request = self.messages.Variable( name=var_name, value=b'value1', ) exception = base.MakeHttpError(404, 'NOT_FOUND') self.variable_client.Update.Expect(request, exception=exception) with self.assertRaises(exceptions.HttpException): self.RunRuntimeConfig( 'variables set var1 "value1" --config-name foo ' '--fail-if-absent')
def testWatchServerTimeout(self): var_name = 'projects/{0}/configs/foo/variables/var1'.format( self.Project()) request = self.messages.RuntimeconfigProjectsConfigsVariablesWatchRequest( name=var_name, watchVariableRequest=self.messages.WatchVariableRequest( newerThan=None, )) exception = base.MakeHttpError(code=504, status='DEADLINE_EXCEEDED') self.variable_client.Watch.Expect(request, exception=exception) try: self.RunRuntimeConfig('variables watch var1 --config-name foo') except exceptions.OperationTimeoutError as e: self.assertEqual(e.exit_code, 2) # 2 means we timed out else: self.fail('No exceptions.OperationTimeoutError raised')
def testCreateAlreadyExists(self): project_name = 'projects/{0}'.format(self.Project()) config_name = 'projects/{0}/configs/foobar'.format(self.Project()) expected_request = self.messages.RuntimeconfigProjectsConfigsCreateRequest( parent=project_name, runtimeConfig=self.messages.RuntimeConfig( name=config_name, description='baz baz', ), ) wanted_exception = base.MakeHttpError(code=409, status='ALREADY_EXISTS') self.config_client.Create.Expect(expected_request, exception=wanted_exception) with self.assertRaises(exceptions.HttpException): self.RunRuntimeConfig('create foobar --description "baz baz"')
def testWatchNotFound(self): var_name = 'projects/{0}/configs/foo/variables/var1'.format( self.Project()) request = self.messages.RuntimeconfigProjectsConfigsVariablesWatchRequest( name=var_name, watchVariableRequest=self.messages.WatchVariableRequest( newerThan=None, )) exception = base.MakeHttpError(code=404, status='NOT_FOUND') self.variable_client.Watch.Expect(request, exception=exception) try: self.RunRuntimeConfig('variables watch var1 --config-name foo') except api_exceptions.HttpException as e: self.assertEqual(e.exit_code, 1) # 1 means something other than timeout else: self.fail('No HttpException raised')
def testSetFailIfPresentFails(self): # Tests that --fail-if-present causees an error if the named # variable already exists. config_name = 'projects/{0}/configs/foo'.format(self.Project()) var_name = 'projects/{0}/configs/foo/variables/var1'.format( self.Project()) request = self.messages.RuntimeconfigProjectsConfigsVariablesCreateRequest( parent=config_name, variable=self.messages.Variable( name=var_name, value=b'value1', ), ) exception = base.MakeHttpError(409, 'ALREADY_EXISTS') self.variable_client.Create.Expect(request, exception=exception) with self.assertRaises(exceptions.HttpException): self.RunRuntimeConfig( 'variables set var1 "value1" --config-name foo ' '--fail-if-present')
def testCreateAlreadyExists(self): config_name = 'projects/{0}/configs/foo'.format(self.Project()) waiter_name = 'projects/{0}/configs/foo/waiters/bar'.format( self.Project()) request = self.messages.RuntimeconfigProjectsConfigsWaitersCreateRequest( parent=config_name, waiter=self.messages.Waiter( name=waiter_name, timeout='60s', success=self.messages.EndCondition( cardinality=self.messages.Cardinality( path='/success', number=1, ))), ) exception = base.MakeHttpError(code=409, status='ALREADY_EXISTS') self.waiter_client.Create.Expect(request, exception=exception) with self.assertRaises(sdk_exceptions.HttpException): self.RunRuntimeConfig( 'waiters create bar --config-name foo --timeout 1m ' '--success-cardinality-path /success')