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

Core, BigQuery: refactor 'client_info' support. #7849

Merged
merged 14 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement 'Connection.user_agent' via its '_client_info'.
  • Loading branch information
tseaver committed May 2, 2019
commit 13aa6775299c121ebfcf1f68f0627ca1307658aa
4 changes: 2 additions & 2 deletions core/google/cloud/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ def user_agent(self):
:rtype: str
:returns: user agent
"""
return self._user_agent
return self._client_info.to_user_agent()

@user_agent.setter
def user_agent(self, value):
self._user_agent = value
self._client_info.user_agent = value

@property
def _EXTRA_HEADERS(self):
Expand Down
27 changes: 8 additions & 19 deletions core/tests/unit/test__http.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,42 +48,31 @@ def test_constructor_explicit(self):
def test_user_agent_all_caps_getter_deprecated(self):
client = object()
conn = self._make_one(client)
conn._user_agent = user_agent = 'testing'

with mock.patch.object(warnings, "warn", autospec=True) as warn:
self.assertEqual(conn.USER_AGENT, user_agent)
self.assertEqual(conn.USER_AGENT, conn._client_info.to_user_agent())

warn.assert_called_once_with(mock.ANY, DeprecationWarning, stacklevel=2)

def test_user_agent_all_caps_setter_deprecated(self):
conn = self._make_one(object())
user_agent = 'testing'
user_agent = "testing"

with mock.patch.object(warnings, "warn", autospec=True) as warn:
conn.USER_AGENT = user_agent

self.assertEqual(conn._user_agent, user_agent)
self.assertEqual(conn._client_info.user_agent, user_agent)
warn.assert_called_once_with(mock.ANY, DeprecationWarning, stacklevel=2)

def test_user_agent_getter_default(self):
from pkg_resources import get_distribution

expected = "gcloud-python/{0}".format(
get_distribution("google-cloud-core").version
)
conn = self._make_one(object())
self.assertEqual(conn.user_agent, expected)

def test_user_agent_getter_overridden(self):
def test_user_agent_getter(self):
conn = self._make_one(object())
expected = conn._user_agent = "testing"
self.assertEqual(conn.user_agent, expected)
self.assertEqual(conn.user_agent, conn._client_info.to_user_agent())

def test_user_agent_setter(self):
conn = self._make_one(object())
expected = "testing"
conn.user_agent = expected
self.assertEqual(conn._user_agent, expected)
user_agent = "testing"
conn.user_agent = user_agent
self.assertEqual(conn._client_info.user_agent, user_agent)

def test_extra_headers_all_caps_getter_deprecated(self):
client = object()
Expand Down