Skip to content

Commit 53fda3d

Browse files
committed
Updating unit tests for logging API objects.
Change needed to accommodate the changes to the constructor.
1 parent 732e304 commit 53fda3d

File tree

3 files changed

+81
-53
lines changed

3 files changed

+81
-53
lines changed

packages/google-cloud-logging/unit_tests/test__gax.py

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,10 @@ def _getTargetClass(self):
606606

607607
def test_ctor(self):
608608
gax_api = _GAXSinksAPI()
609-
api = self._makeOne(gax_api)
609+
client = object()
610+
api = self._makeOne(gax_api, client)
610611
self.assertIs(api._gax_api, gax_api)
612+
self.assertIs(api._client, client)
611613

612614
def test_list_sinks_no_paging(self):
613615
from google.gax import INITIAL_PAGE
@@ -625,7 +627,7 @@ def test_list_sinks_no_paging(self):
625627
filter=self.FILTER)
626628
response = _GAXPageIterator([sink_pb], page_token=TOKEN)
627629
gax_api = _GAXSinksAPI(_list_sinks_response=response)
628-
api = self._makeOne(gax_api)
630+
api = self._makeOne(gax_api, None)
629631

630632
sinks, token = api.list_sinks(self.PROJECT)
631633

@@ -653,7 +655,7 @@ def test_list_sinks_w_paging(self):
653655
filter=self.FILTER)
654656
response = _GAXPageIterator([sink_pb])
655657
gax_api = _GAXSinksAPI(_list_sinks_response=response)
656-
api = self._makeOne(gax_api)
658+
api = self._makeOne(gax_api, None)
657659

658660
sinks, token = api.list_sinks(
659661
self.PROJECT, page_size=PAGE_SIZE, page_token=TOKEN)
@@ -669,7 +671,7 @@ def test_list_sinks_w_paging(self):
669671
def test_sink_create_error(self):
670672
from google.gax.errors import GaxError
671673
gax_api = _GAXSinksAPI(_random_gax_error=True)
672-
api = self._makeOne(gax_api)
674+
api = self._makeOne(gax_api, None)
673675

674676
with self.assertRaises(GaxError):
675677
api.sink_create(
@@ -679,7 +681,7 @@ def test_sink_create_error(self):
679681
def test_sink_create_conflict(self):
680682
from google.cloud.exceptions import Conflict
681683
gax_api = _GAXSinksAPI(_create_sink_conflict=True)
682-
api = self._makeOne(gax_api)
684+
api = self._makeOne(gax_api, None)
683685

684686
with self.assertRaises(Conflict):
685687
api.sink_create(
@@ -689,7 +691,7 @@ def test_sink_create_conflict(self):
689691
def test_sink_create_ok(self):
690692
from google.logging.v2.logging_config_pb2 import LogSink
691693
gax_api = _GAXSinksAPI()
692-
api = self._makeOne(gax_api)
694+
api = self._makeOne(gax_api, None)
693695

694696
api.sink_create(
695697
self.PROJECT, self.SINK_NAME, self.FILTER, self.DESTINATION_URI)
@@ -706,15 +708,15 @@ def test_sink_create_ok(self):
706708
def test_sink_get_error(self):
707709
from google.cloud.exceptions import NotFound
708710
gax_api = _GAXSinksAPI()
709-
api = self._makeOne(gax_api)
711+
api = self._makeOne(gax_api, None)
710712

711713
with self.assertRaises(NotFound):
712714
api.sink_get(self.PROJECT, self.SINK_NAME)
713715

714716
def test_sink_get_miss(self):
715717
from google.gax.errors import GaxError
716718
gax_api = _GAXSinksAPI(_random_gax_error=True)
717-
api = self._makeOne(gax_api)
719+
api = self._makeOne(gax_api, None)
718720

719721
with self.assertRaises(GaxError):
720722
api.sink_get(self.PROJECT, self.SINK_NAME)
@@ -731,7 +733,7 @@ def test_sink_get_hit(self):
731733
destination=self.DESTINATION_URI,
732734
filter=self.FILTER)
733735
gax_api = _GAXSinksAPI(_get_sink_response=sink_pb)
734-
api = self._makeOne(gax_api)
736+
api = self._makeOne(gax_api, None)
735737

736738
response = api.sink_get(self.PROJECT, self.SINK_NAME)
737739

@@ -744,7 +746,7 @@ def test_sink_get_hit(self):
744746
def test_sink_update_error(self):
745747
from google.gax.errors import GaxError
746748
gax_api = _GAXSinksAPI(_random_gax_error=True)
747-
api = self._makeOne(gax_api)
749+
api = self._makeOne(gax_api, None)
748750

749751
with self.assertRaises(GaxError):
750752
api.sink_update(
@@ -754,7 +756,7 @@ def test_sink_update_error(self):
754756
def test_sink_update_miss(self):
755757
from google.cloud.exceptions import NotFound
756758
gax_api = _GAXSinksAPI()
757-
api = self._makeOne(gax_api)
759+
api = self._makeOne(gax_api, None)
758760

759761
with self.assertRaises(NotFound):
760762
api.sink_update(
@@ -768,7 +770,7 @@ def test_sink_update_hit(self):
768770
destination=self.DESTINATION_URI,
769771
filter=self.FILTER)
770772
gax_api = _GAXSinksAPI(_update_sink_response=response)
771-
api = self._makeOne(gax_api)
773+
api = self._makeOne(gax_api, None)
772774

773775
api.sink_update(
774776
self.PROJECT, self.SINK_NAME, self.FILTER, self.DESTINATION_URI)
@@ -785,22 +787,22 @@ def test_sink_update_hit(self):
785787
def test_sink_delete_error(self):
786788
from google.gax.errors import GaxError
787789
gax_api = _GAXSinksAPI(_random_gax_error=True)
788-
api = self._makeOne(gax_api)
790+
api = self._makeOne(gax_api, None)
789791

790792
with self.assertRaises(GaxError):
791793
api.sink_delete(self.PROJECT, self.SINK_NAME)
792794

793795
def test_sink_delete_miss(self):
794796
from google.cloud.exceptions import NotFound
795797
gax_api = _GAXSinksAPI(_sink_not_found=True)
796-
api = self._makeOne(gax_api)
798+
api = self._makeOne(gax_api, None)
797799

798800
with self.assertRaises(NotFound):
799801
api.sink_delete(self.PROJECT, self.SINK_NAME)
800802

801803
def test_sink_delete_hit(self):
802804
gax_api = _GAXSinksAPI()
803-
api = self._makeOne(gax_api)
805+
api = self._makeOne(gax_api, None)
804806

805807
api.sink_delete(self.PROJECT, self.SINK_NAME)
806808

@@ -821,7 +823,7 @@ def _getTargetClass(self):
821823

822824
def test_ctor(self):
823825
gax_api = _GAXMetricsAPI()
824-
api = self._makeOne(gax_api)
826+
api = self._makeOne(gax_api, None)
825827
self.assertIs(api._gax_api, gax_api)
826828

827829
def test_list_metrics_no_paging(self):
@@ -840,7 +842,7 @@ def test_list_metrics_no_paging(self):
840842
filter=self.FILTER)
841843
response = _GAXPageIterator([metric_pb], page_token=TOKEN)
842844
gax_api = _GAXMetricsAPI(_list_log_metrics_response=response)
843-
api = self._makeOne(gax_api)
845+
api = self._makeOne(gax_api, None)
844846

845847
metrics, token = api.list_metrics(self.PROJECT)
846848

@@ -868,7 +870,7 @@ def test_list_metrics_w_paging(self):
868870
filter=self.FILTER)
869871
response = _GAXPageIterator([metric_pb])
870872
gax_api = _GAXMetricsAPI(_list_log_metrics_response=response)
871-
api = self._makeOne(gax_api)
873+
api = self._makeOne(gax_api, None)
872874

873875
metrics, token = api.list_metrics(
874876
self.PROJECT, page_size=PAGE_SIZE, page_token=TOKEN)
@@ -884,7 +886,7 @@ def test_list_metrics_w_paging(self):
884886
def test_metric_create_error(self):
885887
from google.gax.errors import GaxError
886888
gax_api = _GAXMetricsAPI(_random_gax_error=True)
887-
api = self._makeOne(gax_api)
889+
api = self._makeOne(gax_api, None)
888890

889891
with self.assertRaises(GaxError):
890892
api.metric_create(
@@ -894,7 +896,7 @@ def test_metric_create_error(self):
894896
def test_metric_create_conflict(self):
895897
from google.cloud.exceptions import Conflict
896898
gax_api = _GAXMetricsAPI(_create_log_metric_conflict=True)
897-
api = self._makeOne(gax_api)
899+
api = self._makeOne(gax_api, None)
898900

899901
with self.assertRaises(Conflict):
900902
api.metric_create(
@@ -904,7 +906,7 @@ def test_metric_create_conflict(self):
904906
def test_metric_create_ok(self):
905907
from google.logging.v2.logging_metrics_pb2 import LogMetric
906908
gax_api = _GAXMetricsAPI()
907-
api = self._makeOne(gax_api)
909+
api = self._makeOne(gax_api, None)
908910

909911
api.metric_create(
910912
self.PROJECT, self.METRIC_NAME, self.FILTER, self.DESCRIPTION)
@@ -921,15 +923,15 @@ def test_metric_create_ok(self):
921923
def test_metric_get_error(self):
922924
from google.cloud.exceptions import NotFound
923925
gax_api = _GAXMetricsAPI()
924-
api = self._makeOne(gax_api)
926+
api = self._makeOne(gax_api, None)
925927

926928
with self.assertRaises(NotFound):
927929
api.metric_get(self.PROJECT, self.METRIC_NAME)
928930

929931
def test_metric_get_miss(self):
930932
from google.gax.errors import GaxError
931933
gax_api = _GAXMetricsAPI(_random_gax_error=True)
932-
api = self._makeOne(gax_api)
934+
api = self._makeOne(gax_api, None)
933935

934936
with self.assertRaises(GaxError):
935937
api.metric_get(self.PROJECT, self.METRIC_NAME)
@@ -946,7 +948,7 @@ def test_metric_get_hit(self):
946948
description=self.DESCRIPTION,
947949
filter=self.FILTER)
948950
gax_api = _GAXMetricsAPI(_get_log_metric_response=metric_pb)
949-
api = self._makeOne(gax_api)
951+
api = self._makeOne(gax_api, None)
950952

951953
response = api.metric_get(self.PROJECT, self.METRIC_NAME)
952954

@@ -959,7 +961,7 @@ def test_metric_get_hit(self):
959961
def test_metric_update_error(self):
960962
from google.gax.errors import GaxError
961963
gax_api = _GAXMetricsAPI(_random_gax_error=True)
962-
api = self._makeOne(gax_api)
964+
api = self._makeOne(gax_api, None)
963965

964966
with self.assertRaises(GaxError):
965967
api.metric_update(
@@ -969,7 +971,7 @@ def test_metric_update_error(self):
969971
def test_metric_update_miss(self):
970972
from google.cloud.exceptions import NotFound
971973
gax_api = _GAXMetricsAPI()
972-
api = self._makeOne(gax_api)
974+
api = self._makeOne(gax_api, None)
973975

974976
with self.assertRaises(NotFound):
975977
api.metric_update(
@@ -983,7 +985,7 @@ def test_metric_update_hit(self):
983985
description=self.DESCRIPTION,
984986
filter=self.FILTER)
985987
gax_api = _GAXMetricsAPI(_update_log_metric_response=response)
986-
api = self._makeOne(gax_api)
988+
api = self._makeOne(gax_api, None)
987989

988990
api.metric_update(
989991
self.PROJECT, self.METRIC_NAME, self.FILTER, self.DESCRIPTION)
@@ -1000,22 +1002,22 @@ def test_metric_update_hit(self):
10001002
def test_metric_delete_error(self):
10011003
from google.gax.errors import GaxError
10021004
gax_api = _GAXMetricsAPI(_random_gax_error=True)
1003-
api = self._makeOne(gax_api)
1005+
api = self._makeOne(gax_api, None)
10041006

10051007
with self.assertRaises(GaxError):
10061008
api.metric_delete(self.PROJECT, self.METRIC_NAME)
10071009

10081010
def test_metric_delete_miss(self):
10091011
from google.cloud.exceptions import NotFound
10101012
gax_api = _GAXMetricsAPI(_log_metric_not_found=True)
1011-
api = self._makeOne(gax_api)
1013+
api = self._makeOne(gax_api, None)
10121014

10131015
with self.assertRaises(NotFound):
10141016
api.metric_delete(self.PROJECT, self.METRIC_NAME)
10151017

10161018
def test_metric_delete_hit(self):
10171019
gax_api = _GAXMetricsAPI()
1018-
api = self._makeOne(gax_api)
1020+
api = self._makeOne(gax_api, None)
10191021

10201022
api.metric_delete(self.PROJECT, self.METRIC_NAME)
10211023

packages/google-cloud-logging/unit_tests/test_client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ def _generated_api(*args, **kw):
129129

130130
class _GaxSinksAPI(object):
131131

132-
def __init__(self, _wrapped):
132+
def __init__(self, _wrapped, client):
133133
self._wrapped = _wrapped
134+
self.client = client
134135

135136
creds = _Credentials()
136137
client = self._makeOne(project=self.PROJECT, credentials=creds)
@@ -143,6 +144,7 @@ def __init__(self, _wrapped):
143144

144145
self.assertIsInstance(api, _GaxSinksAPI)
145146
self.assertIs(api._wrapped, wrapped)
147+
self.assertIs(api.client, client)
146148
# API instance is cached
147149
again = client.sinks_api
148150
self.assertIs(again, api)
@@ -176,8 +178,9 @@ def _generated_api(*args, **kw):
176178

177179
class _GaxMetricsAPI(object):
178180

179-
def __init__(self, _wrapped):
181+
def __init__(self, _wrapped, client):
180182
self._wrapped = _wrapped
183+
self.client = client
181184

182185
creds = _Credentials()
183186
client = self._makeOne(project=self.PROJECT, credentials=creds)
@@ -190,6 +193,7 @@ def __init__(self, _wrapped):
190193

191194
self.assertIsInstance(api, _GaxMetricsAPI)
192195
self.assertIs(api._wrapped, wrapped)
196+
self.assertIs(api.client, client)
193197
# API instance is cached
194198
again = client.metrics_api
195199
self.assertIs(again, api)

0 commit comments

Comments
 (0)