Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: undprecate entity factory helpers (#101)
Closes #100
  • Loading branch information
tseaver committed Jun 30, 2021
1 parent d368c4b commit 1fbee03
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 75 deletions.
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 @@ -323,12 +320,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 @@ -341,12 +333,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 @@ -358,12 +345,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 @@ -375,12 +357,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 @@ -389,12 +366,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 @@ -403,12 +375,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 @@ -230,72 +230,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

0 comments on commit 1fbee03

Please sign in to comment.