Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fixing Bigtable unit tests after Client re-factor.
Also slightly changing the Client constructor so that
it only called `with_scopes()` one time on the credentials
(was previously calling with `SCOPE=None` and then again with the
custom scope for the instance)
  • Loading branch information
dhermes committed Jul 26, 2017
commit cfcb455c4ed29912f914c0b9396c6820dc9da181
26 changes: 15 additions & 11 deletions bigtable/google/cloud/bigtable/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,17 @@ def __init__(self, project=None, credentials=None,
raise ValueError('A read-only client cannot also perform'
'administrative actions.')

# NOTE: We set the scopes **before** calling the parent constructor.
# It **may** use those scopes in ``with_scopes_if_required``.
self._read_only = bool(read_only)
self._admin = bool(admin)
self.SCOPE = self._get_scopes()

# NOTE: This API has no use for the _http argument, but sending it
# will have no impact since the _http() @property only lazily
# creates a working HTTP object.
super(Client, self).__init__(
project=project, credentials=credentials, _http=None)
self._read_only = bool(read_only)
self._admin = bool(admin)
self.user_agent = user_agent
self.emulator_host = os.getenv(BIGTABLE_EMULATOR)

Expand All @@ -228,21 +232,21 @@ def __init__(self, project=None, credentials=None,
self._operations_stub_internal = _make_operations_stub(self)
self._table_stub_internal = _make_table_stub(self)

self._set_scopes()
def _get_scopes(self):
"""Get the scopes corresponding to admin / read-only state.

def _set_scopes(self):
"""Set the scopes on the current credentials."""
scopes = []
Returns:
Tuple[str, ...]: The tuple of scopes.
"""
if self._read_only:
scopes.append(READ_ONLY_SCOPE)
scopes = (READ_ONLY_SCOPE,)
else:
scopes.append(DATA_SCOPE)
scopes = (DATA_SCOPE,)

if self._admin:
scopes.append(ADMIN_SCOPE)
scopes += (ADMIN_SCOPE,)

self._credentials = google.auth.credentials.with_scopes_if_required(
self._credentials, scopes)
return scopes

def copy(self):
"""Make a copy of this client.
Expand Down
13 changes: 10 additions & 3 deletions bigtable/nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,17 @@ def unit_tests(session, python_version):
session.install('-e', '.')

# Run py.test against the unit tests.
session.run('py.test', '--quiet',
'--cov=google.cloud.bigtable', '--cov=tests.unit', '--cov-append',
'--cov-config=.coveragerc', '--cov-report=', '--cov-fail-under=97',
session.run(
'py.test',
'--quiet',
'--cov=google.cloud.bigtable',
'--cov=tests.unit',
'--cov-append',
'--cov-config=.coveragerc',
'--cov-report=',
'--cov-fail-under=97',
'tests/unit',
*session.posargs
)


Expand Down
Loading