diff --git a/google/cloud/spanner_dbapi/version.py b/google/cloud/spanner_dbapi/version.py index b0e48cff0b..63bd687feb 100644 --- a/google/cloud/spanner_dbapi/version.py +++ b/google/cloud/spanner_dbapi/version.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 diff --git a/tests/system/test_dbapi.py b/tests/system/test_dbapi.py index 210a4f5e90..c47aeebd82 100644 --- a/tests/system/test_dbapi.py +++ b/tests/system/test_dbapi.py @@ -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 + )