def _DoTestDeleteGlobalOperationGeneratesCorrectRequest(self, service_version): flag_values = copy.deepcopy(FLAGS) command = operation_cmds.DeleteOperation('deleteoperation', flag_values) expected_project = 'test_project' expected_operation = 'test_operation' flag_values.project = expected_project flag_values.service_version = service_version flag_values.zone = command_base.GLOBAL_SCOPE_NAME command.SetFlags(flag_values) command.SetApi(old_mock_api.CreateMockApi()) command._InitializeContextParser() command._credential = old_mock_api.MockCredential() results, exceptions = command.Handle(expected_operation) self.assertEqual(exceptions, []) self.assertEqual(results, '') # Verify the request self.assertEquals(1, len(command.api.global_operations.requests)) request = command.api.global_operations.requests[0] self.assertEqual('delete', request.method_name) self.assertEqual(expected_project, request.request_payload['project']) self.assertEqual(expected_operation, request.request_payload['operation'])
def _DoTestDeleteRegionOperation(self, flag_values): command = operation_cmds.DeleteOperation('deleteoperation', flag_values) expected_project = 'region-test-project' expected_operation = 'region-test-operation' submitted_region = 'my-test-region' flag_values.project = expected_project flag_values.region = submitted_region command.SetFlags(flag_values) command.SetApi(old_mock_api.CreateMockApi()) command._InitializeContextParser() command._credential = old_mock_api.MockCredential() results, exceptions = command.Handle(expected_operation) self.assertEqual(exceptions, []) self.assertEqual(results, '') api = command.api.region_operations self.assertEquals(1, len(api.requests)) request = api.requests[0] self.assertEqual(submitted_region, request.request_payload['region']) self.assertEqual(expected_project, request.request_payload['project']) self.assertEqual(expected_operation, request.request_payload['operation'])
def _DoTestDeleteOperationGeneratesCorrectRequest(self, service_version): flag_values = copy.deepcopy(FLAGS) command = operation_cmds.DeleteOperation('deleteoperation', flag_values) expected_project = 'test_project' expected_operation = 'test_operation' flag_values.project = expected_project flag_values.service_version = service_version command.SetFlags(flag_values) command.SetApi(old_mock_api.CreateMockApi()) command._InitializeContextParser() command._credential = old_mock_api.MockCredential() submitted_zone = 'myzone' flag_values.zone = submitted_zone results, exceptions = command.Handle(expected_operation) self.assertEqual(exceptions, []) self.assertEqual(results, '') # Verify the request api = command.api.zone_operations self.assertEquals(1, len(api.requests)) request = api.requests[0] self.assertEqual(submitted_zone, request.request_payload['zone']) self.assertEqual(expected_project, request.request_payload['project']) self.assertEqual(expected_operation, request.request_payload['operation'])
def testDeleteMultipleRoutes(self): flag_values = copy.deepcopy(FLAGS) command = route_cmds.DeleteRoute('deleteroute', flag_values) expected_routes = ['test-routes-%02d' % x for x in xrange(100)] flag_values.project = EXPECTED_PROJECT command.SetFlags(flag_values) command.SetApi(old_mock_api.CreateMockApi()) command._InitializeContextParser() command._credential = old_mock_api.MockCredential() results, exceptions = command.Handle(*expected_routes) self.assertEqual(exceptions, []) results = results['items'] self.assertEqual(len(results), len(expected_routes)) for expected_route, result in zip(expected_routes, results): self.assertEqual(result['project'], EXPECTED_PROJECT) self.assertEqual(result['route'], expected_route)
def testDeleteRouteGeneratesCorrectRequest(self): flag_values = copy.deepcopy(FLAGS) command = route_cmds.DeleteRoute('deleteroute', flag_values) expected_route = 'test_route' flag_values.project = EXPECTED_PROJECT command.SetFlags(flag_values) command.SetApi(old_mock_api.CreateMockApi()) command._InitializeContextParser() command._credential = old_mock_api.MockCredential() results, exceptions = command.Handle(expected_route) self.assertEqual(exceptions, []) self.assertEqual(len(results['items']), 1) result = results['items'][0] self.assertEqual(result['project'], EXPECTED_PROJECT) self.assertEqual(result['route'], expected_route)
def testDeleteMultipleSnapshots(self): flag_values = copy.deepcopy(FLAGS) command = snapshot_cmds.DeleteSnapshot('deletesnapshot', flag_values) expected_project = 'test_project' expected_snapshots = ['test-snapshot-%02d' % x for x in xrange(100)] flag_values.project = expected_project command.SetFlags(flag_values) command.SetApi(old_mock_api.CreateMockApi()) command._InitializeContextParser() command._credential = old_mock_api.MockCredential() results, exceptions = command.Handle(*expected_snapshots) self.assertEqual(exceptions, []) results = results['items'] self.assertEqual(len(results), len(expected_snapshots)) for expected_snapshot, result in zip(expected_snapshots, results): self.assertEqual(result['project'], expected_project) self.assertEqual(result['snapshot'], expected_snapshot)
def _DoTestDeleteSnapshotGeneratesCorrectRequest(self, service_version): flag_values = copy.deepcopy(FLAGS) command = snapshot_cmds.DeleteSnapshot('deletesnapshot', flag_values) expected_project = 'test_project' expected_snapshot = 'test_snapshot' flag_values.project = expected_project command.SetFlags(flag_values) command.SetApi(old_mock_api.CreateMockApi()) command._InitializeContextParser() command._credential = old_mock_api.MockCredential() flag_values.service_version = service_version results, exceptions = command.Handle(expected_snapshot) self.assertEquals(exceptions, []) self.assertEquals(len(results['items']), 1) result = results['items'][0] self.assertEqual(result['project'], expected_project) self.assertEqual(result['snapshot'], expected_snapshot)