def GetMockListRequest(self, operation_filter=None, page_size=operations.DEFAULT_PAGE_SIZE, page_token=None): return operations.GetMessages( ).FirestoreProjectsDatabasesOperationsListRequest( filter=operation_filter, name='projects/%s/databases/(default)' % (self.Project()), pageSize=page_size, pageToken=page_token)
def testList(self): request = self.GetMockListRequest() operation_name = 'export operation name' operation_list = [ operations.GetMessages().GoogleLongrunningOperation( done=False, name=operation_name) ] response = operations.GetMessages().GoogleLongrunningListOperationsResponse( operations=operation_list) self.mock_firestore_v1.projects_databases_operations.List.Expect( request, response=response) actual = list(self.RunFirestoreTest('operations list')) self.assertEqual(1, len(actual)) self.assertEqual(operation_name, actual[0].name)
def testDeleteAbsolutePath(self): operation_name_full =\ 'projects/my-test-project/databases/(default)/operations/doomed' request = self._GetMockDeleteRequest(operation_name_full) response = operations.GetMessages().Empty() self.mock_firestore_v1.projects_databases_operations.Delete.Expect( request, response=response) self.RunFirestoreTest( 'operations delete {}'.format(operation_name_full))
def testListWithCollectionIdsGetsTranslated(self): expected_filter = 'metadata.collectionIds=a,b' request = self.GetMockListRequest(operation_filter=expected_filter) operation_name = 'export operation name' operation_list = [ operations.GetMessages().GoogleLongrunningOperation( done=False, name=operation_name) ] response = operations.GetMessages().GoogleLongrunningListOperationsResponse( operations=operation_list) self.mock_firestore_v1.projects_databases_operations.List.Expect( request, response=response) actual = list( self.RunFirestoreTest( 'operations list --filter=\'collectionIds:a,b\'')) self.assertEqual(1, len(actual)) self.assertEqual(operation_name, actual[0].name)
def testCancelRelativeResourcePath(self): operation_name_relative = 'doomed' operation_name_full =\ 'projects/my-test-project/databases/(default)/operations/doomed' request = self._GetMockCancelRequest(operation_name_full) response = operations.GetMessages().Empty() self.mock_firestore_v1.projects_databases_operations.Cancel.Expect( request, response=response) self.RunFirestoreTest( 'operations cancel {}'.format(operation_name_relative))
def testExportNonAsync(self): output_uri_prefix = 'gs://gcs_bucket' expected_request = admin_api.GetExportDocumentsRequest( self.DatabaseResourceName(), output_uri_prefix) operation_name = ('projects/{}/databases/(default)/' 'operations/exportoperationname').format(self.Project()) messages = self.mock_firestore_v1.MESSAGES_MODULE mock_export_response = messages.GoogleLongrunningOperation( done=False, name=operation_name) mock_get_response = operations.GetMessages().GoogleLongrunningOperation( done=False, name=operation_name) expected_operation_get = ( operations.GetMessages() .FirestoreProjectsDatabasesOperationsGetRequest()) expected_operation_get.name = operation_name # Expect several calls while done=False, then we get a response from the # command once the export is complete. self.mock_firestore_v1.projects_databases.ExportDocuments.Expect( expected_request, response=mock_export_response) self.mock_firestore_v1.projects_databases_operations.Get.Expect( expected_operation_get, response=mock_get_response) self.mock_firestore_v1.projects_databases_operations.Get.Expect( expected_operation_get, response=mock_get_response) mock_response = operations.GetMessages().GoogleLongrunningOperation( done=True, name=operation_name) self.mock_firestore_v1.projects_databases_operations.Get.Expect( expected_operation_get, response=mock_response) # Call RunDatastoreTest directly, because we don't want --async. resp = self.RunFirestoreTest('export {}'.format(output_uri_prefix)) self.assertEqual(operation_name, resp.name) self.AssertErrContains('Waiting for [{}] to finish'.format(operation_name))
def testGetAbsoluteResource(self): operation_name_full = ( 'projects/my-test-project/databases/(default)/' 'operations/export_operation_name' ) request = self.GetMockGetRequest(operation_name_full) response = operations.GetMessages().GoogleLongrunningOperation( done=False, name=operation_name_full) self.mock_firestore_v1.projects_databases_operations.Get.Expect( request, response=response) actual = self.RunFirestoreTest( 'operations describe %s' % operation_name_full) self.assertEqual(operation_name_full, actual.name)
def _GetMockDeleteRequest(self, name): messages = operations.GetMessages() request = messages.FirestoreProjectsDatabasesOperationsDeleteRequest() request.name = name return request