Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions firestore/google/cloud/firestore_v1beta1/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* a :class:`~google.cloud.firestore_v1beta1.client.Client` owns a
:class:`~google.cloud.firestore_v1beta1.document.DocumentReference`
"""
import warnings

from google.cloud.client import ClientWithProject

from google.cloud.firestore_v1beta1 import _helpers
Expand All @@ -47,6 +49,10 @@
)
_ACTIVE_TXN = "There is already an active transaction."
_INACTIVE_TXN = "There is no active transaction."
_V1BETA1_DEPRECATED_MESSAGE = (
"The 'v1beta1' API endpoint is deprecated. "
"The client/library which supports it will be removed in a future release."
)


class Client(ClientWithProject):
Expand Down Expand Up @@ -80,6 +86,7 @@ class Client(ClientWithProject):
_rpc_metadata_internal = None

def __init__(self, project=None, credentials=None, database=DEFAULT_DATABASE):
warnings.warn(_V1BETA1_DEPRECATED_MESSAGE, DeprecationWarning, stacklevel=2)
# NOTE: This API has no use for the _http argument, but sending it
# will have no impact since the _http() @property only lazily
# creates a working HTTP object.
Expand Down
5 changes: 4 additions & 1 deletion firestore/tests/unit/v1beta1/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import unittest

import mock
import pytest


class TestGeoPoint(unittest.TestCase):
Expand Down Expand Up @@ -2077,7 +2078,9 @@ def _make_client(project="quark"):
from google.cloud.firestore_v1beta1.client import Client

credentials = _make_credentials()
return Client(project=project, credentials=credentials)

with pytest.deprecated_call():
return Client(project=project, credentials=credentials)


def _make_field_path(*fields):
Expand Down
5 changes: 4 additions & 1 deletion firestore/tests/unit/v1beta1/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import unittest

import mock
import pytest


class TestWriteBatch(unittest.TestCase):
Expand Down Expand Up @@ -268,4 +269,6 @@ def _make_client(project="seventy-nine"):
from google.cloud.firestore_v1beta1.client import Client

credentials = _make_credentials()
return Client(project=project, credentials=credentials)

with pytest.deprecated_call():
return Client(project=project, credentials=credentials)
77 changes: 57 additions & 20 deletions firestore/tests/unit/v1beta1/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import unittest

import mock
import pytest


class TestClient(unittest.TestCase):
Expand All @@ -41,17 +42,23 @@ def test_constructor(self):
from google.cloud.firestore_v1beta1.client import DEFAULT_DATABASE

credentials = _make_credentials()
client = self._make_one(project=self.PROJECT, credentials=credentials)

with pytest.deprecated_call():
client = self._make_one(project=self.PROJECT, credentials=credentials)

self.assertEqual(client.project, self.PROJECT)
self.assertEqual(client._credentials, credentials)
self.assertEqual(client._database, DEFAULT_DATABASE)

def test_constructor_explicit(self):
credentials = _make_credentials()
database = "now-db"
client = self._make_one(
project=self.PROJECT, credentials=credentials, database=database
)

with pytest.deprecated_call():
client = self._make_one(
project=self.PROJECT, credentials=credentials, database=database
)

self.assertEqual(client.project, self.PROJECT)
self.assertEqual(client._credentials, credentials)
self.assertEqual(client._database, database)
Expand All @@ -63,7 +70,10 @@ def test_constructor_explicit(self):
)
def test__firestore_api_property(self, mock_client):
mock_client.SERVICE_ADDRESS = "endpoint"
client = self._make_default_one()

with pytest.deprecated_call():
client = self._make_default_one()

self.assertIsNone(client._firestore_api_internal)
firestore_api = client._firestore_api
self.assertIs(firestore_api, mock_client.return_value)
Expand All @@ -77,9 +87,12 @@ def test__firestore_api_property(self, mock_client):
def test___database_string_property(self):
credentials = _make_credentials()
database = "cheeeeez"
client = self._make_one(
project=self.PROJECT, credentials=credentials, database=database
)

with pytest.deprecated_call():
client = self._make_one(
project=self.PROJECT, credentials=credentials, database=database
)

self.assertIsNone(client._database_string_internal)
database_string = client._database_string
expected = "projects/{}/databases/{}".format(client.project, client._database)
Expand All @@ -93,9 +106,11 @@ def test___database_string_property(self):
def test___rpc_metadata_property(self):
credentials = _make_credentials()
database = "quanta"
client = self._make_one(
project=self.PROJECT, credentials=credentials, database=database
)

with pytest.deprecated_call():
client = self._make_one(
project=self.PROJECT, credentials=credentials, database=database
)

self.assertEqual(
client._rpc_metadata,
Expand All @@ -106,7 +121,10 @@ def test_collection_factory(self):
from google.cloud.firestore_v1beta1.collection import CollectionReference

collection_id = "users"
client = self._make_default_one()

with pytest.deprecated_call():
client = self._make_default_one()

collection = client.collection(collection_id)

self.assertEqual(collection._path, (collection_id,))
Expand All @@ -116,7 +134,9 @@ def test_collection_factory(self):
def test_collection_factory_nested(self):
from google.cloud.firestore_v1beta1.collection import CollectionReference

client = self._make_default_one()
with pytest.deprecated_call():
client = self._make_default_one()

parts = ("users", "alovelace", "beep")
collection_path = "/".join(parts)
collection1 = client.collection(collection_path)
Expand All @@ -135,7 +155,10 @@ def test_document_factory(self):
from google.cloud.firestore_v1beta1.document import DocumentReference

parts = ("rooms", "roomA")
client = self._make_default_one()

with pytest.deprecated_call():
client = self._make_default_one()

doc_path = "/".join(parts)
document1 = client.document(doc_path)

Expand All @@ -152,7 +175,9 @@ def test_document_factory(self):
def test_document_factory_nested(self):
from google.cloud.firestore_v1beta1.document import DocumentReference

client = self._make_default_one()
with pytest.deprecated_call():
client = self._make_default_one()

parts = ("rooms", "roomA", "shoes", "dressy")
doc_path = "/".join(parts)
document1 = client.document(doc_path)
Expand Down Expand Up @@ -229,7 +254,10 @@ def test_collections(self):
from google.cloud.firestore_v1beta1.collection import CollectionReference

collection_ids = ["users", "projects"]
client = self._make_default_one()

with pytest.deprecated_call():
client = self._make_default_one()

firestore_api = mock.Mock(spec=["list_collection_ids"])
client._firestore_api_internal = firestore_api

Expand Down Expand Up @@ -274,7 +302,10 @@ def _get_all_helper(self, client, references, document_pbs, **kwargs):
return list(snapshots)

def _info_for_get_all(self, data1, data2):
client = self._make_default_one()

with pytest.deprecated_call():
client = self._make_default_one()

document1 = client.document("pineapple", "lamp1")
document2 = client.document("pineapple", "lamp2")

Expand Down Expand Up @@ -427,7 +458,9 @@ def test_get_all_wrong_order(self):
def test_batch(self):
from google.cloud.firestore_v1beta1.batch import WriteBatch

client = self._make_default_one()
with pytest.deprecated_call():
client = self._make_default_one()

batch = client.batch()
self.assertIsInstance(batch, WriteBatch)
self.assertIs(batch._client, client)
Expand All @@ -436,7 +469,9 @@ def test_batch(self):
def test_transaction(self):
from google.cloud.firestore_v1beta1.transaction import Transaction

client = self._make_default_one()
with pytest.deprecated_call():
client = self._make_default_one()

transaction = client.transaction(max_attempts=3, read_only=True)
self.assertIsInstance(transaction, Transaction)
self.assertEqual(transaction._write_pbs, [])
Expand All @@ -456,7 +491,9 @@ def test_it(self):
from google.cloud.firestore_v1beta1.client import Client

credentials = _make_credentials()
client = Client(project="hi-projject", credentials=credentials)

with pytest.deprecated_call():
client = Client(project="hi-projject", credentials=credentials)

reference1 = client.document("a", "b")
reference2 = client.document("a", "b", "c", "d")
Expand Down
4 changes: 3 additions & 1 deletion firestore/tests/unit/v1beta1/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import unittest

import mock
import pytest
import six


Expand Down Expand Up @@ -588,4 +589,5 @@ def _make_client():
from google.cloud.firestore_v1beta1.client import Client

credentials = _make_credentials()
return Client(project="project-project", credentials=credentials)
with pytest.deprecated_call():
return Client(project="project-project", credentials=credentials)
15 changes: 12 additions & 3 deletions firestore/tests/unit/v1beta1/test_cross_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ def _make_client_document(firestore_api, testcase):

# Attach the fake GAPIC to a real client.
credentials = mock.Mock(spec=google.auth.credentials.Credentials)
client = Client(project=project, credentials=credentials)

with pytest.deprecated_call():
client = Client(project=project, credentials=credentials)

client._firestore_api_internal = firestore_api
return client, client.document(doc_path)

Expand Down Expand Up @@ -222,7 +225,10 @@ def test_listen_testprotos(test_proto): # pragma: NO COVER
testname = test_proto.description

credentials = mock.Mock(spec=google.auth.credentials.Credentials)
client = Client(project="project", credentials=credentials)

with pytest.deprecated_call():
client = Client(project="project", credentials=credentials)

modulename = "google.cloud.firestore_v1beta1.watch"
with mock.patch("%s.Watch.ResumableBidiRpc" % modulename, DummyRpc):
with mock.patch(
Expand Down Expand Up @@ -426,7 +432,10 @@ def parse_query(testcase):
_directions = {"asc": Query.ASCENDING, "desc": Query.DESCENDING}

credentials = mock.create_autospec(Credentials)
client = Client("projectID", credentials)

with pytest.deprecated_call():
client = Client("projectID", credentials)

path = parse_path(testcase.coll_path)
collection = client.collection(*path)
query = collection
Expand Down
5 changes: 4 additions & 1 deletion firestore/tests/unit/v1beta1/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import unittest

import mock
import pytest


class TestDocumentReference(unittest.TestCase):
Expand Down Expand Up @@ -824,4 +825,6 @@ def _make_client(project="project-project"):
from google.cloud.firestore_v1beta1.client import Client

credentials = _make_credentials()
return Client(project=project, credentials=credentials)

with pytest.deprecated_call():
return Client(project=project, credentials=credentials)
5 changes: 4 additions & 1 deletion firestore/tests/unit/v1beta1/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import unittest

import mock
import pytest
import six


Expand Down Expand Up @@ -1547,7 +1548,9 @@ def _make_client(project="project-project"):
from google.cloud.firestore_v1beta1.client import Client

credentials = _make_credentials()
return Client(project=project, credentials=credentials)

with pytest.deprecated_call():
return Client(project=project, credentials=credentials)


def _make_order_pb(field_path, direction):
Expand Down
5 changes: 4 additions & 1 deletion firestore/tests/unit/v1beta1/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import unittest

import mock
import pytest


class TestTransaction(unittest.TestCase):
Expand Down Expand Up @@ -955,7 +956,9 @@ def _make_client(project="feral-tom-cat"):
from google.cloud.firestore_v1beta1.client import Client

credentials = _make_credentials()
return Client(project=project, credentials=credentials)

with pytest.deprecated_call():
return Client(project=project, credentials=credentials)


def _make_transaction(txn_id, **txn_kwargs):
Expand Down