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

API Core: fix pytype build #6873

Merged
merged 4 commits into from
Dec 7, 2018
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ generated_python/
cloud-bigtable-client/
googleapis-pb/
grpc_python_venv/
pytype_output/
3 changes: 0 additions & 3 deletions api_core/google/api_core/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,3 @@ def to_api_repr(self):
del resource["bindings"]

return resource


collections_abc.MutableMapping.register(Policy)
2 changes: 1 addition & 1 deletion api_core/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ universal = 1
[pytype]
python_version = 3.6
inputs =
.
google/
exclude =
tests/
33 changes: 23 additions & 10 deletions api_core/tests/unit/test_iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ def test_owners_setter(self):
MEMBER = "user:phred@example.com"
expected = set([MEMBER])
policy = self._make_one()
with warnings.catch_warnings():
warnings.simplefilter("always")

with warnings.catch_warnings(record=True) as warned:
policy.owners = [MEMBER]

warning, = warned
assert warning.category is DeprecationWarning
assert policy[OWNER_ROLE] == expected

def test_editors_getter(self):
Expand All @@ -111,9 +114,12 @@ def test_editors_setter(self):
MEMBER = "user:phred@example.com"
expected = set([MEMBER])
policy = self._make_one()
with warnings.catch_warnings():
warnings.simplefilter("always")

with warnings.catch_warnings(record=True) as warned:
policy.editors = [MEMBER]

warning, = warned
assert warning.category is DeprecationWarning
assert policy[EDITOR_ROLE] == expected

def test_viewers_getter(self):
Expand All @@ -132,9 +138,12 @@ def test_viewers_setter(self):
MEMBER = "user:phred@example.com"
expected = set([MEMBER])
policy = self._make_one()
with warnings.catch_warnings():
warnings.simplefilter("always")

with warnings.catch_warnings(record=True) as warned:
policy.viewers = [MEMBER]

warning, = warned
assert warning.category is DeprecationWarning
assert policy[VIEWER_ROLE] == expected

def test_user(self):
Expand Down Expand Up @@ -240,17 +249,20 @@ def test_to_api_repr_binding_wo_members(self):
assert policy.to_api_repr() == {}

def test_to_api_repr_binding_w_duplicates(self):
import warnings
from google.api_core.iam import OWNER_ROLE

OWNER = "group:cloud-logs@google.com"
policy = self._make_one()
policy.owners = [OWNER, OWNER]
with warnings.catch_warnings(record=True):
policy.owners = [OWNER, OWNER]
assert policy.to_api_repr() == {
"bindings": [{"role": OWNER_ROLE, "members": [OWNER]}]
}

def test_to_api_repr_full(self):
import operator
import warnings
from google.api_core.iam import OWNER_ROLE, EDITOR_ROLE, VIEWER_ROLE

OWNER1 = "group:cloud-logs@google.com"
Expand All @@ -265,9 +277,10 @@ def test_to_api_repr_full(self):
{"role": VIEWER_ROLE, "members": [VIEWER1, VIEWER2]},
]
policy = self._make_one("DEADBEEF", 17)
policy.owners = [OWNER1, OWNER2]
policy.editors = [EDITOR1, EDITOR2]
policy.viewers = [VIEWER1, VIEWER2]
with warnings.catch_warnings(record=True):
policy.owners = [OWNER1, OWNER2]
policy.editors = [EDITOR1, EDITOR2]
policy.viewers = [VIEWER1, VIEWER2]
resource = policy.to_api_repr()
assert resource["etag"] == "DEADBEEF"
assert resource["version"] == 17
Expand Down