def test_get_iam_policy(self):
    from google.cloud.storage.iam import STORAGE_OWNER_ROLE
    from google.cloud.storage.iam import STORAGE_EDITOR_ROLE
    from google.cloud.storage.iam import STORAGE_VIEWER_ROLE
    from google.cloud.iam import Policy
    BLOB_NAME = 'blob-name'
    PATH = ('/b/name/o/%s' % (BLOB_NAME,))
    ETAG = 'DEADBEEF'
    VERSION = 17
    OWNER1 = 'user:example@example.com'
    OWNER2 = 'group:example@example.com'
    EDITOR1 = 'domain:google.com'
    EDITOR2 = 'user:example@example.com'
    VIEWER1 = 'serviceAccount:example@example.com'
    VIEWER2 = 'user:example@example.com'
    RETURNED = {'resourceId': PATH, 'etag': ETAG, 'version': VERSION, 'bindings': [{'role': STORAGE_OWNER_ROLE, 'members': [OWNER1, OWNER2]}, {'role': STORAGE_EDITOR_ROLE, 'members': [EDITOR1, EDITOR2]}, {'role': STORAGE_VIEWER_ROLE, 'members': [VIEWER1, VIEWER2]}]}
    after = ({'status': http_client.OK}, RETURNED)
    EXPECTED = {binding['role']: set(binding['members']) for binding in RETURNED['bindings']}
    connection = _Connection(after)
    client = _Client(connection)
    bucket = _Bucket(client=client)
    blob = self._make_one(BLOB_NAME, bucket=bucket)
    policy = blob.get_iam_policy()
    self.assertIsInstance(policy, Policy)
    self.assertEqual(policy.etag, RETURNED['etag'])
    self.assertEqual(policy.version, RETURNED['version'])
    self.assertEqual(dict(policy), EXPECTED)
    kw = connection._requested
    self.assertEqual(len(kw), 1)
    self.assertEqual(kw[0]['method'], 'GET')
    self.assertEqual(kw[0]['path'], ('%s/iam' % (PATH,)))
def test_get_iam_policy(self):
    from google.cloud.storage.iam import STORAGE_OWNER_ROLE
    from google.cloud.storage.iam import STORAGE_EDITOR_ROLE
    from google.cloud.storage.iam import STORAGE_VIEWER_ROLE
    from google.cloud.iam import Policy
    BLOB_NAME = 'blob-name'
    PATH = ('/b/name/o/%s' % (BLOB_NAME,))
    ETAG = 'DEADBEEF'
    VERSION = 17
    OWNER1 = 'user:example@example.com'
    OWNER2 = 'group:example@example.com'
    EDITOR1 = 'domain:google.com'
    EDITOR2 = 'user:example@example.com'
    VIEWER1 = 'serviceAccount:example@example.com'
    VIEWER2 = 'user:example@example.com'
    RETURNED = {'resourceId': PATH, 'etag': ETAG, 'version': VERSION, 'bindings': [{'role': STORAGE_OWNER_ROLE, 'members': [OWNER1, OWNER2]}, {'role': STORAGE_EDITOR_ROLE, 'members': [EDITOR1, EDITOR2]}, {'role': STORAGE_VIEWER_ROLE, 'members': [VIEWER1, VIEWER2]}]}
    after = ({'status': http_client.OK}, RETURNED)
    EXPECTED = {binding['role']: set(binding['members']) for binding in RETURNED['bindings']}
    connection = _Connection(after)
    client = _Client(connection)
    bucket = _Bucket(client=client)
    blob = self._make_one(BLOB_NAME, bucket=bucket)
    policy = blob.get_iam_policy()
    self.assertIsInstance(policy, Policy)
    self.assertEqual(policy.etag, RETURNED['etag'])
    self.assertEqual(policy.version, RETURNED['version'])
    self.assertEqual(dict(policy), EXPECTED)
    kw = connection._requested
    self.assertEqual(len(kw), 1)
    self.assertEqual(kw[0]['method'], 'GET')
    self.assertEqual(kw[0]['path'], ('%s/iam' % (PATH,)))