Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: undeprecate entity factory helpers #101

Merged
merged 2 commits into from Jun 30, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 0 additions & 33 deletions google/api_core/iam.py
Expand Up @@ -74,9 +74,6 @@
_ASSIGNMENT_DEPRECATED_MSG = """\
Assigning to '{}' is deprecated. Use the `policy.bindings` property to modify bindings instead."""

_FACTORY_DEPRECATED_MSG = """\
Factory method {0} is deprecated. Replace with '{0}'."""

_DICT_ACCESS_MSG = """\
Dict access is not supported on policies with version > 1 or with conditional bindings."""

Expand Down Expand Up @@ -316,12 +313,7 @@ def user(email):

Returns:
str: A member string corresponding to the given user.

DEPRECATED: set the role `user:{email}` in the binding instead.
"""
warnings.warn(
_FACTORY_DEPRECATED_MSG.format("user:{email}"), DeprecationWarning,
)
return "user:%s" % (email,)

@staticmethod
Expand All @@ -334,12 +326,7 @@ def service_account(email):
Returns:
str: A member string corresponding to the given service account.

DEPRECATED: set the role `serviceAccount:{email}` in the binding instead.
"""
warnings.warn(
_FACTORY_DEPRECATED_MSG.format("serviceAccount:{email}"),
DeprecationWarning,
)
return "serviceAccount:%s" % (email,)

@staticmethod
Expand All @@ -351,12 +338,7 @@ def group(email):

Returns:
str: A member string corresponding to the given group.

DEPRECATED: set the role `group:{email}` in the binding instead.
"""
warnings.warn(
_FACTORY_DEPRECATED_MSG.format("group:{email}"), DeprecationWarning,
)
return "group:%s" % (email,)

@staticmethod
Expand All @@ -368,12 +350,7 @@ def domain(domain):

Returns:
str: A member string corresponding to the given domain.

DEPRECATED: set the role `domain:{email}` in the binding instead.
"""
warnings.warn(
_FACTORY_DEPRECATED_MSG.format("domain:{email}"), DeprecationWarning,
)
return "domain:%s" % (domain,)

@staticmethod
Expand All @@ -382,12 +359,7 @@ def all_users():

Returns:
str: A member string representing all users.

DEPRECATED: set the role `allUsers` in the binding instead.
"""
warnings.warn(
_FACTORY_DEPRECATED_MSG.format("allUsers"), DeprecationWarning,
)
return "allUsers"

@staticmethod
Expand All @@ -396,12 +368,7 @@ def authenticated_users():

Returns:
str: A member string representing all authenticated users.

DEPRECATED: set the role `allAuthenticatedUsers` in the binding instead.
"""
warnings.warn(
_FACTORY_DEPRECATED_MSG.format("allAuthenticatedUsers"), DeprecationWarning,
)
return "allAuthenticatedUsers"

@classmethod
Expand Down
48 changes: 6 additions & 42 deletions tests/unit/test_iam.py
Expand Up @@ -219,72 +219,36 @@ def test_viewers_setter(self):
assert policy[VIEWER_ROLE] == expected

def test_user(self):
import warnings

EMAIL = "phred@example.com"
MEMBER = "user:%s" % (EMAIL,)
policy = self._make_one()
with warnings.catch_warnings(record=True) as warned:
assert policy.user(EMAIL) == MEMBER

(warning,) = warned
assert warning.category is DeprecationWarning
assert policy.user(EMAIL) == MEMBER

def test_service_account(self):
import warnings

EMAIL = "phred@example.com"
MEMBER = "serviceAccount:%s" % (EMAIL,)
policy = self._make_one()
with warnings.catch_warnings(record=True) as warned:
assert policy.service_account(EMAIL) == MEMBER

(warning,) = warned
assert warning.category is DeprecationWarning
assert policy.service_account(EMAIL) == MEMBER

def test_group(self):
import warnings

EMAIL = "phred@example.com"
MEMBER = "group:%s" % (EMAIL,)
policy = self._make_one()
with warnings.catch_warnings(record=True) as warned:
assert policy.group(EMAIL) == MEMBER

(warning,) = warned
assert warning.category is DeprecationWarning
assert policy.group(EMAIL) == MEMBER

def test_domain(self):
import warnings

DOMAIN = "example.com"
MEMBER = "domain:%s" % (DOMAIN,)
policy = self._make_one()
with warnings.catch_warnings(record=True) as warned:
assert policy.domain(DOMAIN) == MEMBER

(warning,) = warned
assert warning.category is DeprecationWarning
assert policy.domain(DOMAIN) == MEMBER

def test_all_users(self):
import warnings

policy = self._make_one()
with warnings.catch_warnings(record=True) as warned:
assert policy.all_users() == "allUsers"

(warning,) = warned
assert warning.category is DeprecationWarning
assert policy.all_users() == "allUsers"

def test_authenticated_users(self):
import warnings

policy = self._make_one()
with warnings.catch_warnings(record=True) as warned:
assert policy.authenticated_users() == "allAuthenticatedUsers"

(warning,) = warned
assert warning.category is DeprecationWarning
assert policy.authenticated_users() == "allAuthenticatedUsers"

def test_from_api_repr_only_etag(self):
empty = frozenset()
Expand Down