10BC0 Increase unit test coverage. · googleapis/google-cloud-python@ab49dde · GitHub
[go: up one dir, main page]

Skip to content

Commit ab49dde

Browse files
committed
Increase unit test coverage.
1 parent e169ec9 commit ab49dde

File tree

9 files changed

+859
-26
lines changed

9 files changed

+859
-26
lines changed

bigquery/google/cloud/bigquery/dataset.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import google.cloud._helpers
2323
from google.cloud.bigquery import _helpers
2424
from google.cloud.bigquery.model import ModelReference
25+
from google.cloud.bigquery.routine import RoutineReference
2526
from google.cloud.bigquery.table import TableReference
2627

2728

@@ -53,6 +54,25 @@ def _get_model_reference(self, model_id):
5354
)
5455

5556

57+
def _get_routine_reference(self, routine_id):
58+
"""Constructs a RoutineReference.
59+
60+
Args:
61+
routine_id (str): the ID of the routine.
62+
63+
Returns:
64+
google.cloud.bigquery.routine.RoutineReference:
65+
A RoutineReference for a routine in this dataset.
66+
"""
67+
return RoutineReference.from_api_repr(
68+
{
69+
"projectId": self.project,
70+
"datasetId": self.dataset_id,
71+
"routineId": routine_id,
72+
}
73+
)
74+
75+
5676
class AccessEntry(object):
5777
"""Represents grant of an access role to an entity.
5878
@@ -224,6 +244,8 @@ def path(self):
224244

225245
model = _get_model_reference
226246

247+
routine = _get_routine_reference
248+
227249
@classmethod
228250
def from_api_repr(cls, resource):
229251
"""Factory: construct a dataset reference given its API representation
@@ -591,6 +613,8 @@ def _build_resource(self, filter_fields):
591613

592614
model = _get_model_reference
593615

616+
routine = _get_routine_reference
617+
594618
def __repr__(self):
595619
return "Dataset({})".format(repr(self.reference))
596620

@@ -672,3 +696,5 @@ def reference(self):
672696
table = _get_table_reference
673697

674698
model = _get_model_reference
699+
700+
routine = _get_routine_reference

bigquery/google/cloud/bigquery/routine.py

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,19 @@ def return_type(self):
189189
https://cloud.google.com/bigquery/docs/reference/rest/v2/routines#resource-routine
190190
"""
191191
resource = self._properties.get(self._PROPERTY_TO_API_FIELD["return_type"])
192+
if not resource:
193+
return resource
192194
output = google.cloud.bigquery_v2.types.StandardSqlDataType()
193195
output = json_format.ParseDict(resource, output, ignore_unknown_fields=True)
194196
return output
195197

196198
@return_type.setter
197199
def return_type(self, value):
198-
self._properties[
199-
self._PROPERTY_TO_API_FIELD["return_type"]
200-
] = json_format.MessageToDict(value)
200+
if value:
201+
resource = json_format.MessageToDict(value)
202+
else:
203+
resource = None
204+
self._properties[self._PROPERTY_TO_API_FIELD["return_type"]] = resource
201205

202206
@property
203207
def imported_libraries(self):
@@ -257,6 +261,11 @@ def _build_resource(self, filter_fields):
257261
"""Generate a resource for ``update``."""
258262
return _helpers._build_resource_from_properties(self, filter_fields)
259263

264+
def __repr__(self):
265+
return "Routine('{}.{}.{}')".format(
266+
self.project, self.dataset_id, self.routine_id
267+
)
268+
260269

261270
class RoutineArgument(object):
262271
"""Input/output argument of a function or a stored procedure.
@@ -328,15 +337,19 @@ def data_type(self):
328337
https://cloud.google.com/bigquery/docs/reference/rest/v2/StandardSqlDataType
329338
"""
330339
resource = self._properties.get(self._PROPERTY_TO_API_FIELD["data_type"])
340+
if not resource:
341+
return resource
331342
output = google.cloud.bigquery_v2.types.StandardSqlDataType()
332343
output = json_format.ParseDict(resource, output, ignore_unknown_fields=True)
333344
return output
334345

335346
@data_type.setter
336347
def data_type(self, value):
337-
self._properties[
338-
self._PROPERTY_TO_API_FIELD["data_type"]
339-
] = json_format.MessageToDict(value)
348+
if value:
349+
resource = json_format.MessageToDict(value)
350+
else:
351+
resource = None
352+
self._properties[self._PROPERTY_TO_API_FIELD["data_type"]] = resource
340353

341354
@classmethod
342355
def from_api_repr(cls, resource):
@@ -354,15 +367,6 @@ def from_api_repr(cls, resource):
354367
ref._properties = resource
355368
return ref
356369

357-
def to_api_repr(self):
358-
"""Construct the API resource representation of this routine argument.
359-
360-
Returns:
361-
Dict[str, object]:
362-
Routine argument represented as an API resource.
363-
"""
364-
return self._properties
365-
366370
def __eq__(self, other):
367371
if not isinstance(other, RoutineArgument):
368372
return NotImplemented
@@ -374,7 +378,7 @@ def __ne__(self, other):
374378
def __repr__(self):
375379
all_properties = [
376380
"{}={}".format(property_name, repr(getattr(self, property_name)))
377-
for property_name in self._PROPERTY_TO_API_FIELD
381+
for property_name in sorted(self._PROPERTY_TO_API_FIELD)
378382
]
379383
return "RoutineArgument({})".format(", ".join(all_properties))
380384

@@ -458,15 +462,6 @@ def from_string(cls, routine_id, default_project=None):
458462
{"projectId": proj, "datasetId": dset, "routineId": routine}
459463
)
460464

461-
def to_api_repr(self):
462-
"""Construct the API resource representation of this routine reference.
463-
464-
Returns:
465-
Dict[str, object]:
466-
Routine reference represented as an API resource.
467-
"""
468-
return self._properties
469-
470465
def __eq__(self, other):
471466
"""Two RoutineReferences are equal if they point to the same routine."""
472467
if not isinstance(other, RoutineReference):

bigquery/samples/update_routine.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def main(client, routine_id):
3535
# Due to a limitation of the API, all fields are required, not just
3636
# those that have been updated.
3737
"arguments",
38+
"language",
3839
"type_",
3940
"return_type",
4041
],

bigquery/tests/unit/routine/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)
0