Skip to content

Commit

Permalink
Test for , with warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Rossi committed Aug 28, 2020
1 parent eb36a24 commit d03607c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions google/cloud/datastore/client.py
Expand Up @@ -14,6 +14,7 @@
"""Convenience wrapper for invoking APIs/factories w/ a project."""

import os
import warnings

import google.api_core.client_options
from google.auth.credentials import AnonymousCredentials
Expand Down Expand Up @@ -882,6 +883,11 @@ def reserve_ids(self, complete_key, num_ids, retry=None, timeout=None):
Please use either :meth:`reserve_ids_multi` (recommended) or
:meth:`reserve_ids_sequential`.
"""
message = (
"Client.reserve_ids is deprecated. Please use "
"Client.reserve_ids_multi or Client.reserve_ids_sequential",
)
warnings.warn(message, DeprecationWarning)
return self.reserve_ids_sequential(
complete_key, num_ids, retry=retry, timeout=timeout
)
Expand Down
13 changes: 13 additions & 0 deletions tests/system/test_system.py
Expand Up @@ -15,6 +15,7 @@
import datetime
import os
import unittest
import warnings

import requests
import six
Expand Down Expand Up @@ -109,6 +110,18 @@ def test_reserve_ids_sequential(self):
num_ids = 10
Config.CLIENT.reserve_ids_sequential(Config.CLIENT.key("Kind", 1234), num_ids)

def test_reserve_ids(self):
with warnings.catch_warnings(record=True) as warned:
num_ids = 10
Config.CLIENT.reserve_ids(Config.CLIENT.key("Kind", 1234), num_ids)

warned = [
warning
for warning in warned
if "reserve_ids_sequential" in str(warning.message)
]
assert len(warned) == 1

def test_reserve_ids_multi(self):
# Smoke test to make sure it doesn't blow up. No return value or
# verifiable side effect to verify.
Expand Down

0 comments on commit d03607c

Please sign in to comment.