Beispiel #1
0
    def testExportWithEntitySpecAndLabels(self):
        output_url_prefix = 'gs://gcs_bucket'
        labels = {'a_key': 'a_value', 'b_key': 'b_value'}
        kinds = ['Customer', 'Orders']
        namespaces = ['APAC', 'EMEA', '(default)']
        expected_namespaces = ['APAC', 'EMEA', '']
        request = admin_api.GetExportEntitiesRequest(
            self.Project(),
            output_url_prefix,
            labels=labels,
            kinds=kinds,
            namespaces=expected_namespaces)

        operation_name = 'export operation name'
        response = operations.GetMessages().GoogleLongrunningOperation(
            done=False, name=operation_name)

        self.mock_datastore_v1.projects.Export.Expect(request,
                                                      response=response)

        actual = self.RunExportTest(labels=labels,
                                    kinds=kinds,
                                    namespaces=namespaces,
                                    output_url_prefix=output_url_prefix)
        self.assertEqual(operation_name, actual.name)
Beispiel #2
0
    def testExportNonAsync(self):
        output_url_prefix = 'gs://gcs_bucket'
        expected_request = admin_api.GetExportEntitiesRequest(
            self.Project(), output_url_prefix)
        operation_name = 'projects/{}/operations/exportoperationname'.format(
            self.Project())
        mock_response = operations.GetMessages().GoogleLongrunningOperation(
            done=False, name=operation_name)
        expected_operation_get = (
            operations.GetMessages().DatastoreProjectsOperationsGetRequest())
        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_datastore_v1.projects.Export.Expect(expected_request,
                                                      response=mock_response)
        self.mock_datastore_v1.projects_operations.Get.Expect(
            expected_operation_get, response=mock_response)
        self.mock_datastore_v1.projects_operations.Get.Expect(
            expected_operation_get, response=mock_response)

        mock_response = operations.GetMessages().GoogleLongrunningOperation(
            done=True, name=operation_name)

        self.mock_datastore_v1.projects_operations.Get.Expect(
            expected_operation_get, response=mock_response)

        # Call RunDatastoreTest directly, because we don't want --async.
        resp = self.RunDatastoreTest('export {}'.format(output_url_prefix))

        self.assertEqual(operation_name, resp.name)
        self.AssertErrContains(
            'Waiting for [{}] to finish'.format(operation_name))
Beispiel #3
0
    def testExport(self):
        output_url_prefix = 'gs://gcs_bucket'
        expected_request = admin_api.GetExportEntitiesRequest(
            self.Project(), output_url_prefix)
        operation_name = 'export operation name'
        mock_response = operations.GetMessages().GoogleLongrunningOperation(
            done=False, name=operation_name)

        self.mock_datastore_v1.projects.Export.Expect(expected_request,
                                                      response=mock_response)

        resp = self.RunExportTest(output_url_prefix=output_url_prefix)
        self.assertEqual(operation_name, resp.name)
Beispiel #4
0
    def testExportFailureThrowsToolHttpException(self):
        output_url_prefix = 'gs://gcs_bucket'
        request = admin_api.GetExportEntitiesRequest(self.Project(),
                                                     output_url_prefix)

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

        self.mock_datastore_v1.projects.Export.Expect(request,
                                                      exception=exception)

        with self.assertRaisesRegex(exceptions.HttpException, 'error_message'):
            self.RunExportTest(output_url_prefix=output_url_prefix)