Пример #1
0
  def testExport(self):
    output_uri_prefix = 'gs://gcs_bucket'
    expected_request = admin_api.GetExportDocumentsRequest(
        self.DatabaseResourceName(), output_uri_prefix)
    operation_name = 'export operation name'
    messages = self.mock_firestore_v1.MESSAGES_MODULE
    mock_response = messages.GoogleLongrunningOperation(
        done=False, name=operation_name)
    self.mock_firestore_v1.projects_databases.ExportDocuments.Expect(
        expected_request, response=mock_response)

    resp = self.RunExportTest(output_uri_prefix=output_uri_prefix)
    self.assertEqual(operation_name, resp.name)
Пример #2
0
  def testExportFailureThrowsToolHttpException(self):
    output_uri_prefix = 'gs://gcs_bucket'
    request = admin_api.GetExportDocumentsRequest(self.DatabaseResourceName(),
                                                  output_uri_prefix)

    exception = http_error.MakeHttpError(
        six.moves.http_client.BAD_REQUEST, 'error_message', url='Fake url')

    self.mock_firestore_v1.projects_databases.ExportDocuments.Expect(
        request, exception=exception)

    with self.assertRaisesRegex(exceptions.HttpException, 'error_message'):
      self.RunExportTest(output_uri_prefix=output_uri_prefix)
Пример #3
0
  def testExportWithCollectionIds(self):
    output_uri_prefix = 'gs://gcs_bucket'
    collection_ids = ['Customers', 'Orders']
    request = admin_api.GetExportDocumentsRequest(
        self.DatabaseResourceName(),
        output_uri_prefix,
        collection_ids=collection_ids)

    operation_name = 'export operation name'
    messages = self.mock_firestore_v1.MESSAGES_MODULE
    mock_response = messages.GoogleLongrunningOperation(
        done=False, name=operation_name)

    self.mock_firestore_v1.projects_databases.ExportDocuments.Expect(
        request, response=mock_response)

    actual = self.RunExportTest(
        collection_ids=collection_ids, output_uri_prefix=output_uri_prefix)
    self.assertEqual(operation_name, actual.name)
Пример #4
0
  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))