diff --git a/firestore/google/cloud/firestore_v1beta1/client.py b/firestore/google/cloud/firestore_v1beta1/client.py index 26f061c7419c..50036f0adb30 100644 --- a/firestore/google/cloud/firestore_v1beta1/client.py +++ b/firestore/google/cloud/firestore_v1beta1/client.py @@ -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 @@ -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): @@ -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. diff --git a/firestore/tests/unit/v1beta1/test__helpers.py b/firestore/tests/unit/v1beta1/test__helpers.py index c4b3828e8cd8..3059482cd07a 100644 --- a/firestore/tests/unit/v1beta1/test__helpers.py +++ b/firestore/tests/unit/v1beta1/test__helpers.py @@ -18,6 +18,7 @@ import unittest import mock +import pytest class TestGeoPoint(unittest.TestCase): @@ -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): diff --git a/firestore/tests/unit/v1beta1/test_batch.py b/firestore/tests/unit/v1beta1/test_batch.py index 613bd48ee5b6..831424751594 100644 --- a/firestore/tests/unit/v1beta1/test_batch.py +++ b/firestore/tests/unit/v1beta1/test_batch.py @@ -15,6 +15,7 @@ import unittest import mock +import pytest class TestWriteBatch(unittest.TestCase): @@ -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) diff --git a/firestore/tests/unit/v1beta1/test_client.py b/firestore/tests/unit/v1beta1/test_client.py index f8f14ee1e57a..4aa5a36efb71 100644 --- a/firestore/tests/unit/v1beta1/test_client.py +++ b/firestore/tests/unit/v1beta1/test_client.py @@ -17,6 +17,7 @@ import unittest import mock +import pytest class TestClient(unittest.TestCase): @@ -41,7 +42,10 @@ 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) @@ -49,9 +53,12 @@ def test_constructor(self): 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) @@ -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) @@ -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) @@ -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, @@ -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,)) @@ -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) @@ -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) @@ -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) @@ -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 @@ -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") @@ -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) @@ -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, []) @@ -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") diff --git a/firestore/tests/unit/v1beta1/test_collection.py b/firestore/tests/unit/v1beta1/test_collection.py index beea3d2b8b9f..2bc7695ae940 100644 --- a/firestore/tests/unit/v1beta1/test_collection.py +++ b/firestore/tests/unit/v1beta1/test_collection.py @@ -17,6 +17,7 @@ import unittest import mock +import pytest import six @@ -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) diff --git a/firestore/tests/unit/v1beta1/test_cross_language.py b/firestore/tests/unit/v1beta1/test_cross_language.py index bbcb39a19393..d04b71436ff6 100644 --- a/firestore/tests/unit/v1beta1/test_cross_language.py +++ b/firestore/tests/unit/v1beta1/test_cross_language.py @@ -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) @@ -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( @@ -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 diff --git a/firestore/tests/unit/v1beta1/test_document.py b/firestore/tests/unit/v1beta1/test_document.py index 54f63187c168..f9aca713449a 100644 --- a/firestore/tests/unit/v1beta1/test_document.py +++ b/firestore/tests/unit/v1beta1/test_document.py @@ -16,6 +16,7 @@ import unittest import mock +import pytest class TestDocumentReference(unittest.TestCase): @@ -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) diff --git a/firestore/tests/unit/v1beta1/test_query.py b/firestore/tests/unit/v1beta1/test_query.py index e213e38639e4..455a56b7f7ec 100644 --- a/firestore/tests/unit/v1beta1/test_query.py +++ b/firestore/tests/unit/v1beta1/test_query.py @@ -17,6 +17,7 @@ import unittest import mock +import pytest import six @@ -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): diff --git a/firestore/tests/unit/v1beta1/test_transaction.py b/firestore/tests/unit/v1beta1/test_transaction.py index 3259e3e227e3..1797007495f5 100644 --- a/firestore/tests/unit/v1beta1/test_transaction.py +++ b/firestore/tests/unit/v1beta1/test_transaction.py @@ -15,6 +15,7 @@ import unittest import mock +import pytest class TestTransaction(unittest.TestCase): @@ -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):