Skip to content

Commit

Permalink
feat: set a separate user agent for the DB API (#566)
Browse files Browse the repository at this point in the history
* 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 b5f977e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions google/cloud/spanner_dbapi/version.py
Expand Up @@ -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
12 changes: 11 additions & 1 deletion tests/system/test_dbapi.py
Expand Up @@ -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"
Expand Down Expand Up @@ -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.