@@ -29,30 +29,102 @@ def _getTargetClass(self):
2929 def _makeOne (self , * args , ** kw ):
3030 return self ._getTargetClass ()(* args , ** kw )
3131
32- def test_publisher_api (self ):
32+ def test_publisher_api_wo_gax (self ):
3333 from gcloud .pubsub .connection import _PublisherAPI
34+ from gcloud .pubsub import client as MUT
35+ from gcloud ._testing import _Monkey
3436 creds = _Credentials ()
3537 client = self ._makeOne (project = self .PROJECT , credentials = creds )
3638 conn = client .connection = object ()
37- api = client .publisher_api
39+
40+ with _Monkey (MUT , _USE_GAX = False ):
41+ api = client .publisher_api
42+
3843 self .assertIsInstance (api , _PublisherAPI )
3944 self .assertTrue (api ._connection is conn )
4045 # API instance is cached
4146 again = client .publisher_api
4247 self .assertTrue (again is api )
4348
44- def test_subscriber_api (self ):
49+ def test_publisher_api_w_gax (self ):
50+ from gcloud .pubsub import client as MUT
51+ from gcloud ._testing import _Monkey
52+
53+ wrapped = object ()
54+ _called_with = []
55+
56+ def _generated_api (* args , ** kw ):
57+ _called_with .append ((args , kw ))
58+ return wrapped
59+
60+ class _GaxPublisherAPI (object ):
61+
62+ def __init__ (self , _wrapped ):
63+ self ._wrapped = _wrapped
64+
65+ creds = _Credentials ()
66+ client = self ._makeOne (project = self .PROJECT , credentials = creds )
67+
68+ with _Monkey (MUT ,
69+ _USE_GAX = True ,
70+ GeneratedPublisherAPI = _generated_api ,
71+ GAXPublisherAPI = _GaxPublisherAPI ):
72+ api = client .publisher_api
73+
74+ self .assertIsInstance (api , _GaxPublisherAPI )
75+ self .assertTrue (api ._wrapped is wrapped )
76+ # API instance is cached
77+ again = client .publisher_api
78+ self .assertTrue (again is api )
79+
80+ def test_subscriber_api_wo_gax (self ):
4581 from gcloud .pubsub .connection import _SubscriberAPI
82+ from gcloud .pubsub import client as MUT
83+ from gcloud ._testing import _Monkey
4684 creds = _Credentials ()
4785 client = self ._makeOne (project = self .PROJECT , credentials = creds )
4886 conn = client .connection = object ()
49- api = client .subscriber_api
87+
88+ with _Monkey (MUT , _USE_GAX = False ):
89+ api = client .subscriber_api
90+
5091 self .assertIsInstance (api , _SubscriberAPI )
5192 self .assertTrue (api ._connection is conn )
5293 # API instance is cached
5394 again = client .subscriber_api
5495 self .assertTrue (again is api )
5596
97+ def test_subscriber_api_w_gax (self ):
98+ from gcloud .pubsub import client as MUT
99+ from gcloud ._testing import _Monkey
100+
101+ wrapped = object ()
102+ _called_with = []
103+
104+ def _generated_api (* args , ** kw ):
105+ _called_with .append ((args , kw ))
106+ return wrapped
107+
108+ class _GaxSubscriberAPI (object ):
109+
110+ def __init__ (self , _wrapped ):
111+ self ._wrapped = _wrapped
112+
113+ creds = _Credentials ()
114+ client = self ._makeOne (project = self .PROJECT , credentials = creds )
115+
116+ with _Monkey (MUT ,
117+ _USE_GAX = True ,
118+ GeneratedSubscriberAPI = _generated_api ,
119+ GAXSubscriberAPI = _GaxSubscriberAPI ):
120+ api = client .subscriber_api
121+
122+ self .assertIsInstance (api , _GaxSubscriberAPI )
123+ self .assertTrue (api ._wrapped is wrapped )
124+ # API instance is cached
125+ again = client .subscriber_api
126+ self .assertTrue (again is api )
127+
56128 def test_iam_policy_api (self ):
57129 from gcloud .pubsub .connection import _IAMPolicyAPI
58130 creds = _Credentials ()
0 commit comments