Skip to content

Commit d173efe

Browse files
committed
Reverted _veneer_data_table property, fixed tests
1 parent 7f49237 commit d173efe

File tree

2 files changed

+33
-91
lines changed

2 files changed

+33
-91
lines changed

google/cloud/bigtable/table.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,11 @@ def __init__(self, table_id, instance, mutation_timeout=None, app_profile_id=Non
132132
self._app_profile_id = app_profile_id
133133
self.mutation_timeout = mutation_timeout
134134

135-
# Lazily initialize the table shim to avoid causing constructor errors for instance=None
136-
# that don't exist in the original implementation.
137-
self._table_impl = None
135+
self._table_impl = self._instance._client._veneer_data_client.get_table(
136+
self._instance.instance_id,
137+
self.table_id,
138+
app_profile_id=self._app_profile_id,
139+
)
138140

139141
@property
140142
def name(self):
@@ -166,18 +168,6 @@ def name(self):
166168
project=project, instance=instance_id, table=self.table_id
167169
)
168170

169-
@property
170-
def _veneer_data_table(self):
171-
"""Getter for the data client table representation of this object."""
172-
if self._table_impl is None:
173-
self._table_impl = self._instance._client._veneer_data_client.get_table(
174-
self._instance.instance_id,
175-
self.table_id,
176-
app_profile_id=self._app_profile_id,
177-
)
178-
179-
return self._table_impl
180-
181171
def get_iam_policy(self):
182172
"""Gets the IAM access control policy for this table.
183173

tests/unit/v2_client/test_table.py

Lines changed: 28 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -162,110 +162,62 @@ def _make_table(*args, **kwargs):
162162

163163

164164
def test_table_constructor_defaults():
165-
instance = mock.Mock(spec=[])
166-
167-
table = _make_table(TABLE_ID, instance)
168-
169-
assert table.table_id == TABLE_ID
170-
assert table._instance is instance
171-
assert table.mutation_timeout is None
172-
assert table._app_profile_id is None
173-
174-
175-
def test_table_constructor_explicit():
176-
instance = mock.Mock(spec=[])
177-
mutation_timeout = 123
178-
app_profile_id = "profile-123"
179-
180-
table = _make_table(
181-
TABLE_ID,
182-
instance,
183-
mutation_timeout=mutation_timeout,
184-
app_profile_id=app_profile_id,
185-
)
186-
187-
assert table.table_id == TABLE_ID
188-
assert table._instance is instance
189-
assert table.mutation_timeout == mutation_timeout
190-
assert table._app_profile_id == app_profile_id
191-
192-
193-
def test_table_name():
194-
table_data_client = mock.Mock(spec=["table_path"])
195-
_veneer_data_client = mock.Mock()
196-
client = mock.Mock(
197-
project=PROJECT_ID,
198-
table_data_client=table_data_client,
199-
_veneer_data_client=_veneer_data_client,
200-
spec=["project", "table_data_client", "_veneer_data_client"],
201-
)
202-
instance = mock.Mock(
203-
_client=client,
204-
instance_id=INSTANCE_ID,
205-
spec=["_client", "instance_id"],
206-
)
207-
208-
table = _make_table(TABLE_ID, instance)
209-
210-
assert table.name == table_data_client.table_path.return_value
211-
165+
from google.cloud.bigtable.client import Client
212166

213-
def test_table_veneer_data_table_not_initialized_defaults():
214-
table_data_client = mock.Mock(spec=["table_path"])
215-
_veneer_data_client = mock.Mock()
216-
client = mock.Mock(
217-
project=PROJECT_ID,
218-
table_data_client=table_data_client,
219-
_veneer_data_client=_veneer_data_client,
220-
spec=["project", "table_data_client", "_veneer_data_client"],
221-
)
167+
client = mock.create_autospec(Client)
222168
instance = mock.Mock(
223169
_client=client,
224170
instance_id=INSTANCE_ID,
225171
spec=["_client", "instance_id"],
226172
)
227173

228174
table = _make_table(TABLE_ID, instance)
229-
table._veneer_data_table
230175

231-
_veneer_data_client.get_table.assert_called_once_with(
176+
assert table.table_id == TABLE_ID
177+
assert table._instance is instance
178+
assert table.mutation_timeout is None
179+
assert table._app_profile_id is None
180+
assert table._table_impl is client._veneer_data_client.get_table.return_value
181+
client._veneer_data_client.get_table.assert_called_once_with(
232182
INSTANCE_ID,
233183
TABLE_ID,
234184
app_profile_id=None,
235185
)
236186

237187

238-
def test_table_veneer_data_table_not_initialized_explicit():
239-
table_data_client = mock.Mock(spec=["table_path"])
240-
_veneer_data_client = mock.Mock()
241-
client = mock.Mock(
242-
project=PROJECT_ID,
243-
table_data_client=table_data_client,
244-
_veneer_data_client=_veneer_data_client,
245-
spec=["project", "table_data_client", "_veneer_data_client"],
246-
)
188+
def test_table_constructor_explicit():
189+
from google.cloud.bigtable.client import Client
190+
191+
client = mock.create_autospec(Client)
247192
instance = mock.Mock(
248193
_client=client,
249194
instance_id=INSTANCE_ID,
250195
spec=["_client", "instance_id"],
251196
)
252197

198+
mutation_timeout = 123
253199
app_profile_id = "profile-123"
200+
254201
table = _make_table(
255202
TABLE_ID,
256203
instance,
204+
mutation_timeout=mutation_timeout,
257205
app_profile_id=app_profile_id,
258206
)
259-
table._veneer_data_table
260207

261-
_veneer_data_client.get_table.assert_called_once_with(
208+
assert table.table_id == TABLE_ID
209+
assert table._instance is instance
210+
assert table.mutation_timeout == mutation_timeout
211+
assert table._app_profile_id == app_profile_id
212+
assert table._table_impl is client._veneer_data_client.get_table.return_value
213+
client._veneer_data_client.get_table.assert_called_once_with(
262214
INSTANCE_ID,
263215
TABLE_ID,
264216
app_profile_id=app_profile_id,
265217
)
266218

267219

268-
def test_table_veneer_data_table_initialized():
220+
def test_table_name():
269221
table_data_client = mock.Mock(spec=["table_path"])
270222
_veneer_data_client = mock.Mock()
271223
client = mock.Mock(
@@ -281,9 +233,8 @@ def test_table_veneer_data_table_initialized():
281233
)
282234

283235
table = _make_table(TABLE_ID, instance)
284-
already = table._table_impl = object()
285-
assert table._veneer_data_table is already
286-
_veneer_data_client.get_table.assert_not_called()
236+
237+
assert table.name == table_data_client.table_path.return_value
287238

288239

289240
def _table_row_methods_helper():
@@ -417,8 +368,9 @@ def test_table___ne__same_value():
417368

418369

419370
def test_table___ne__():
420-
table1 = _make_table("table_id1", None)
421-
table2 = _make_table("table_id2", None)
371+
mock_instance = mock.Mock()
372+
table1 = _make_table("table_id1", mock_instance)
373+
table2 = _make_table("table_id2", mock_instance)
422374
assert table1 != table2
423375

424376

@@ -1340,7 +1292,7 @@ def test_table_drop_by_prefix_w_timeout():
13401292
def test_table_mutations_batcher_factory():
13411293
flush_count = 100
13421294
max_row_bytes = 1000
1343-
table = _make_table(TABLE_ID, None)
1295+
table = _make_table(TABLE_ID, mock.Mock())
13441296
mutation_batcher = table.mutations_batcher(
13451297
flush_count=flush_count, max_row_bytes=max_row_bytes
13461298
)

0 commit comments

Comments
 (0)