Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set a separate user agent for the DB API #566

Merged
merged 3 commits into from Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
IlyaFaer marked this conversation as resolved.
Show resolved Hide resolved
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
)