8000 Fixing Bigtable unit tests after Client re-factor. · googleapis/google-cloud-python@cfcb455 · GitHub
[go: up one dir, main page]

Skip to content

Commit cfcb455

Browse files
committed
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)
1 parent a7bb93d commit cfcb455

File tree

3 files changed

+235
-190
lines changed

3 files changed

+235
-190
lines changed

bigtable/google/cloud/bigtable/client.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,17 @@ def __init__(self, project=None, credentials=None,
211211
raise ValueError('A read-only client cannot also perform'
212212
'administrative actions.')
213213

214+
# NOTE: We set the scopes **before** calling the parent constructor.
215+
# It **may** use those scopes in ``with_scopes_if_required``.
216+
self._read_only = bool(read_only)
217+
self._admin = bool(admin)
218+
self.SCOPE = self._get_scopes()
219+
214220
# NOTE: This API has no use for the _http argument, but sending it
215221
# will have no impact since the _http() @property only lazily
216222
# creates a working HTTP object.
217223
super(Client, self).__init__(
218224
project=project, credentials=credentials, _http=None)
219-
self._read_only = bool(read_only)
220-
self._admin = bool(admin)
221225
self.user_agent = user_agent
222226
self.emulator_host = os.getenv(BIGTABLE_EMULATOR)
223227

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

231-
self._set_scopes()
235+
def _get_scopes(self):
236+
"""Get the scopes corresponding to admin / read-only state.
232237
233-
def< 10000 span class="x"> _set_scopes(self):
234-
"""Set the scopes on the current credentials."""
235-
scopes = []
238+
Returns:
239+
Tuple[str, ...]: The tuple of scopes.
240+
"""
236241
if self._read_only:
237-
scopes.append(READ_ONLY_SCOPE)
242+
scopes = (READ_ONLY_SCOPE,)
238243
else:
239-
scopes.append(DATA_SCOPE)
244+
scopes = (DATA_SCOPE,)
240245

241246
if self._admin:
242-
scopes.append(ADMIN_SCOPE)
247+
scopes += (ADMIN_SCOPE,)
243248

244-
self._credentials = google.auth.credentials.with_scopes_if_required(
245-
self._credentials, scopes)
249+
return scopes
246250

247251
def copy(self):
248252
"""Make a copy of this client.

bigtable/nox.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,17 @@ def unit_tests(session, python_version):
3737
session.install('-e', '.')
3838

3939
# Run py.test against the unit tests.
40-
session.run('py.test', '--quiet',
41-
'--cov=google.cloud.bigtable', '--cov=tests.unit', '--cov-append',
42-
'--cov-config=.coveragerc', '--cov-report=', '--cov-fail-under=97',
40+
session.run(
41+
'py.test',
42+
'--quiet',
43+
'--cov=google.cloud.bigtable',
44+
'--cov=tests.unit',
45+
'--cov-append',
46+
'--cov-config=.coveragerc',
47+
'--cov-report=',
48+
'--cov-fail-under=97',
4349
'tests/unit',
50+
*session.posargs
4451
)
4552

4653

0 commit comments

Comments
 (0)
0