@@ -49,13 +49,24 @@ def _make_one(self, *args, **kwargs):
4949 return self ._get_target_class ()(* args , ** kwargs )
5050
5151 def _constructor_test_helper (
52- self , expected_scopes , creds , user_agent = None , expected_creds = None
52+ self ,
53+ expected_scopes ,
54+ creds ,
55+ expected_creds = None ,
56+ client_info = None ,
57+ user_agent = None ,
5358 ):
5459 from google .cloud .spanner_v1 import client as MUT
5560
56- user_agent = user_agent or MUT .DEFAULT_USER_AGENT
61+ kwargs = {}
62+
63+ if client_info is not None :
64+ kwargs ["client_info" ] = expected_client_info = client_info
65+ else :
66+ expected_client_info = MUT ._CLIENT_INFO
67+
5768 client = self ._make_one (
58- project = self .PROJECT , credentials = creds , user_agent = user_agent
69+ project = self .PROJECT , credentials = creds , user_agent = user_agent , ** kwargs
5970 )
6071
6172 expected_creds = expected_creds or creds .with_scopes .return_value
@@ -66,6 +77,7 @@ def _constructor_test_helper(
6677 creds .with_scopes .assert_called_once_with (expected_scopes )
6778
6879 self .assertEqual (client .project , self .PROJECT )
80+ self .assertIs (client ._client_info , expected_client_info )
6981 self .assertEqual (client .user_agent , user_agent )
7082
7183 def test_constructor_default_scopes (self ):
@@ -75,7 +87,8 @@ def test_constructor_default_scopes(self):
7587 creds = _make_credentials ()
7688 self ._constructor_test_helper (expected_scopes , creds )
7789
78- def test_constructor_custom_user_agent_and_timeout (self ):
90+ @mock .patch ("warnings.warn" )
91+ def test_constructor_custom_user_agent_and_timeout (self , mock_warn ):
7992 from google .cloud .spanner_v1 import client as MUT
8093
8194 CUSTOM_USER_AGENT = "custom-application"
@@ -84,6 +97,17 @@ def test_constructor_custom_user_agent_and_timeout(self):
8497 self ._constructor_test_helper (
8598 expected_scopes , creds , user_agent = CUSTOM_USER_AGENT
8699 )
100+ mock_warn .assert_called_once_with (
101+ MUT ._USER_AGENT_DEPRECATED , DeprecationWarning , stacklevel = 2
102+ )
103+
104+ def test_constructor_custom_client_info (self ):
105+ from google .cloud .spanner_v1 import client as MUT
106+
107+ client_info = mock .Mock ()
108+ expected_scopes = (MUT .SPANNER_ADMIN_SCOPE ,)
109+ creds = _make_credentials ()
110+ self ._constructor_test_helper (expected_scopes , creds , client_info = client_info )
87111
88112 def test_constructor_implicit_credentials (self ):
89113 creds = _make_credentials ()
@@ -102,10 +126,13 @@ def test_constructor_credentials_wo_create_scoped(self):
102126 self ._constructor_test_helper (expected_scopes , creds )
103127
104128 def test_instance_admin_api (self ):
105- from google .cloud .spanner_v1 .client import _CLIENT_INFO , SPANNER_ADMIN_SCOPE
129+ from google .cloud .spanner_v1 .client import SPANNER_ADMIN_SCOPE
106130
107131 credentials = _make_credentials ()
108- client = self ._make_one (project = self .PROJECT , credentials = credentials )
132+ client_info = mock .Mock ()
133+ client = self ._make_one (
134+ project = self .PROJECT , credentials = credentials , client_info = client_info
135+ )
109136 expected_scopes = (SPANNER_ADMIN_SCOPE ,)
110137
111138 inst_module = "google.cloud.spanner_v1.client.InstanceAdminClient"
@@ -119,16 +146,19 @@ def test_instance_admin_api(self):
119146 self .assertIs (again , api )
120147
121148 instance_admin_client .assert_called_once_with (
122- credentials = credentials .with_scopes .return_value , client_info = _CLIENT_INFO
149+ credentials = credentials .with_scopes .return_value , client_info = client_info
123150 )
124151
125152 credentials .with_scopes .assert_called_once_with (expected_scopes )
126153
127154 def test_database_admin_api (self ):
128- from google .cloud .spanner_v1 .client import _CLIENT_INFO , SPANNER_ADMIN_SCOPE
155+ from google .cloud .spanner_v1 .client import SPANNER_ADMIN_SCOPE
129156
130157 credentials = _make_credentials ()
131- client = self ._make_one (project = self .PROJECT , credentials = credentials )
158+ client_info = mock .Mock ()
159+ client = self ._make_one (
160+ project = self .PROJECT , credentials = credentials , client_info = client_info
161+ )
132162 expected_scopes = (SPANNER_ADMIN_SCOPE ,)
133163
134164 db_module = "google.cloud.spanner_v1.client.DatabaseAdminClient"
@@ -142,7 +172,7 @@ def test_database_admin_api(self):
142172 self .assertIs (again , api )
143173
144174 database_admin_client .assert_called_once_with (
145- credentials = credentials .with_scopes .return_value , client_info = _CLIENT_INFO
175+ credentials = credentials .with_scopes .return_value , client_info = client_info
146176 )
147177
148178 credentials .with_scopes .assert_called_once_with (expected_scopes )
@@ -152,14 +182,11 @@ def test_copy(self):
152182 # Make sure it "already" is scoped.
153183 credentials .requires_scopes = False
154184
155- client = self ._make_one (
156- project = self .PROJECT , credentials = credentials , user_agent = self .USER_AGENT
157- )
185+ client = self ._make_one (project = self .PROJECT , credentials = credentials )
158186
159187 new_client = client .copy ()
160188 self .assertIs (new_client ._credentials , client ._credentials )
161189 self .assertEqual (new_client .project , client .project )
162- self .assertEqual (new_client .user_agent , client .user_agent )
163190
164191 def test_credentials_property (self ):
165192 credentials = _make_credentials ()
0 commit comments