Skip to content
Permalink
Browse files
feat: set a separate user agent for the DB API (#566)
* feat: set a separate user agent for the DB API

* fix test error

* fix the test
  • Loading branch information
Ilya Gurov committed Sep 13, 2021
1 parent c7138ad commit b5f977ebf61527914af3c8356aeeae9418114215
Showing with 14 additions and 3 deletions.
  1. +3 −2 google/cloud/spanner_dbapi/version.py
  2. +11 −1 tests/system/test_dbapi.py
@@ -12,8 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pkg_resources
import platform

PY_VERSION = platform.python_version()
VERSION = "2.2.0a1"
DEFAULT_USER_AGENT = "django_spanner/" + VERSION
VERSION = pkg_resources.get_distribution("google-cloud-spanner").version
DEFAULT_USER_AGENT = "dbapi/" + VERSION
@@ -14,11 +14,12 @@

import hashlib
import pickle
import pkg_resources

import pytest

from google.cloud import spanner_v1
from google.cloud.spanner_dbapi.connection import Connection
from google.cloud.spanner_dbapi.connection import connect, Connection
from . import _helpers

DATABASE_NAME = "dbapi-txn"
@@ -357,3 +358,12 @@ def test_ping(shared_instance, dbapi_database):
conn = Connection(shared_instance, dbapi_database)
conn.validate()
conn.close()


def test_user_agent(shared_instance, dbapi_database):
"""Check that DB API uses an appropriate user agent."""
conn = connect(shared_instance.name, dbapi_database.name)
assert (
conn.instance._client._client_info.user_agent
== "dbapi/" + pkg_resources.get_distribution("google-cloud-spanner").version
)

0 comments on commit b5f977e

Please sign in to comment.