-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spanner/dbapi: pass user_agent+python_version in ClientInfo
`user_agent` being passed directly a spanner.Client(**) has been deprecated in favor of passing in a field `client_info` of type google.api_core.gapic_v1.client_info.ClientInfo in which we can specify: * user_agent * python_version and that results in the following header being sent over the wire: 'x-goog-api-client': 'spanner-django/0.0.1 gl-python/3.7.3 grpc/1.21.1 gax/1.14.3' Fixes #139
- Loading branch information
Showing
3 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2019 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import sys | ||
from unittest import TestCase | ||
|
||
from google.api_core.gapic_v1.client_info import ClientInfo | ||
from spanner.dbapi.version import USER_AGENT, google_client_info | ||
|
||
|
||
class VersionUtils(TestCase): | ||
def test_google_client_info(self): | ||
vers = sys.version_info | ||
got = google_client_info().to_grpc_metadata() | ||
want = ClientInfo( | ||
user_agent=USER_AGENT, | ||
python_version='%d.%d.%d' % (vers.major, vers.minor, vers.micro or 0), | ||
).to_grpc_metadata() | ||
self.assertEqual(got, want) |