Skip to content
This repository has been archived by the owner on Mar 20, 2018. It is now read-only.

Commit

Permalink
Remove references to grpc.beta (#127)
Browse files Browse the repository at this point in the history
Also bump dependency on grpc, protobuf to non-rc versions.
  • Loading branch information
geigerj authored Sep 9, 2016
1 parent d59635e commit 9a42e3b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 44 deletions.
2 changes: 1 addition & 1 deletion google/gax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import collections


__version__ = '0.12.5'
__version__ = '0.13.0'


INITIAL_PAGE = object()
Expand Down
15 changes: 7 additions & 8 deletions google/gax/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"""Adapts the grpc surface."""

from __future__ import absolute_import
from grpc.beta import implementations
from grpc.beta.interfaces import StatusCode
import grpc
from grpc import StatusCode
from grpc.framework.interfaces.face import face
from . import auth

Expand Down Expand Up @@ -82,8 +82,8 @@ def grpc_auth(dummy_context, callback):
def _make_channel_creds(auth_func, ssl_creds):
"""Converts the auth func into the composite creds expected by grpc."""
grpc_auth_func = _make_grpc_auth_func(auth_func)
call_creds = implementations.metadata_call_credentials(grpc_auth_func)
return implementations.composite_channel_credentials(ssl_creds, call_creds)
call_creds = grpc.metadata_call_credentials(grpc_auth_func)
return grpc.composite_channel_credentials(ssl_creds, call_creds)


def create_stub(generated_create_stub, service_path, port, ssl_creds=None,
Expand All @@ -108,15 +108,14 @@ def create_stub(generated_create_stub, service_path, port, ssl_creds=None,
"""
if channel is None:
if ssl_creds is None:
ssl_creds = implementations.ssl_channel_credentials(
None, None, None)
ssl_creds = grpc.ssl_channel_credentials()
if metadata_transformer is None:
if scopes is None:
scopes = []
metadata_transformer = auth.make_auth_func(scopes)

channel_creds = _make_channel_creds(metadata_transformer, ssl_creds)
channel = implementations.secure_channel(
service_path, port, channel_creds)
target = '{}:{}'.format(service_path, port)
channel = grpc.secure_channel(target, channel_creds)

return generated_create_stub(channel)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@

install_requires = [
'future>=0.15.2',
'grpcio>=1.0rc1',
'grpcio>=1.0.0',
'ply==3.8',
'protobuf>=3.0.0b3',
'protobuf>=3.0.0',
'oauth2client>=1.5.2',
]

Expand Down
9 changes: 1 addition & 8 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,4 @@ pytest>=2.8.3
pytest-cov>=1.8.1
pytest-timeout>=1.0.0
unittest2>=1.1.0

# TODO: remove this line when grpcio goes to 1.0.0. This is only necessary
# because pip (running in Travis CI) will not install the release candidate
# when it gets pulled in as a dependency of grpcio-tools, below, which causes
# build failure in Python 3 environments
grpcio>=1.0.0rc1

grpcio-tools>=1.0.0rc2
grpcio-tools>=1.0.0
53 changes: 28 additions & 25 deletions test/test_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,41 @@ class TestCreateStub(unittest2.TestCase):
FAKE_SERVICE_PATH = 'service_path'
FAKE_PORT = 10101

@mock.patch('grpc.beta.implementations.composite_channel_credentials')
@mock.patch('grpc.beta.implementations.ssl_channel_credentials')
@mock.patch('grpc.beta.implementations.secure_channel')
@mock.patch('grpc.composite_channel_credentials')
@mock.patch('grpc.ssl_channel_credentials')
@mock.patch('grpc.secure_channel')
@mock.patch('google.gax.auth.make_auth_func')
def test_creates_a_stub_ok_with_no_scopes(
self, auth, chan, chan_creds, comp):
got_channel = grpc.create_stub(
_fake_create_stub, self.FAKE_SERVICE_PATH, self.FAKE_PORT)
chan_creds.assert_called_once_with(None, None, None)
chan.assert_called_once_with(self.FAKE_SERVICE_PATH, self.FAKE_PORT,
comp.return_value)
chan_creds.assert_called_once_with()
chan.assert_called_once_with(
'{}:{}'.format(self.FAKE_SERVICE_PATH, self.FAKE_PORT),
comp.return_value)
auth.assert_called_once_with([])
self.assertEqual(got_channel, chan.return_value)

@mock.patch('grpc.beta.implementations.composite_channel_credentials')
@mock.patch('grpc.beta.implementations.ssl_channel_credentials')
@mock.patch('grpc.beta.implementations.secure_channel')
@mock.patch('grpc.composite_channel_credentials')
@mock.patch('grpc.ssl_channel_credentials')
@mock.patch('grpc.secure_channel')
@mock.patch('google.gax.auth.make_auth_func')
def test_creates_a_stub_ok_with_scopes(
self, auth, chan, chan_creds, comp):
fake_scopes = ['dummy', 'scopes']
grpc.create_stub(
_fake_create_stub, self.FAKE_SERVICE_PATH, self.FAKE_PORT,
scopes=fake_scopes)
chan_creds.assert_called_once_with(None, None, None)
chan.assert_called_once_with(self.FAKE_SERVICE_PATH, self.FAKE_PORT,
comp.return_value)
chan_creds.assert_called_once_with()
chan.assert_called_once_with(
'{}:{}'.format(self.FAKE_SERVICE_PATH, self.FAKE_PORT),
comp.return_value)
auth.assert_called_once_with(fake_scopes)

@mock.patch('grpc.beta.implementations.metadata_call_credentials')
@mock.patch('grpc.beta.implementations.composite_channel_credentials')
@mock.patch('grpc.beta.implementations.ssl_channel_credentials')
@mock.patch('grpc.beta.implementations.secure_channel')
@mock.patch('grpc.metadata_call_credentials')
@mock.patch('grpc.composite_channel_credentials')
@mock.patch('grpc.ssl_channel_credentials')
@mock.patch('grpc.secure_channel')
@mock.patch('google.gax.auth.make_auth_func')
def test_creates_a_stub_with_given_channel(
self, auth, chan, chan_creds, comp, md):
Expand All @@ -93,29 +95,30 @@ def test_creates_a_stub_with_given_channel(
self.assertFalse(comp.called)
self.assertFalse(md.called)

@mock.patch('grpc.beta.implementations.metadata_call_credentials')
@mock.patch('grpc.beta.implementations.composite_channel_credentials')
@mock.patch('grpc.beta.implementations.ssl_channel_credentials')
@mock.patch('grpc.beta.implementations.secure_channel')
@mock.patch('grpc.metadata_call_credentials')
@mock.patch('grpc.composite_channel_credentials')
@mock.patch('grpc.ssl_channel_credentials')
@mock.patch('grpc.secure_channel')
@mock.patch('google.gax.auth.make_auth_func')
def test_creates_a_stub_ok_with_given_creds(self, auth, chan, chan_creds,
comp, md):
fake_creds = object()
got_channel = grpc.create_stub(
_fake_create_stub, self.FAKE_SERVICE_PATH, self.FAKE_PORT,
ssl_creds=fake_creds)
chan.assert_called_once_with(self.FAKE_SERVICE_PATH, self.FAKE_PORT,
comp.return_value)
chan.assert_called_once_with(
'{}:{}'.format(self.FAKE_SERVICE_PATH, self.FAKE_PORT),
comp.return_value)
auth.assert_called_once_with([])
self.assertTrue(chan.called)
self.assertFalse(chan_creds.called)
self.assertTrue(comp.called)
self.assertTrue(md.called)
self.assertEqual(got_channel, chan.return_value)

@mock.patch('grpc.beta.implementations.composite_channel_credentials')
@mock.patch('grpc.beta.implementations.ssl_channel_credentials')
@mock.patch('grpc.beta.implementations.secure_channel')
@mock.patch('grpc.composite_channel_credentials')
@mock.patch('grpc.ssl_channel_credentials')
@mock.patch('grpc.secure_channel')
@mock.patch('google.gax.auth.make_auth_func')
def test_creates_a_stub_ok_with_given_auth_func(self, auth, dummy_chan,
dummy_chan_creds, dummy_md):
Expand Down

0 comments on commit 9a42e3b

Please sign in to comment.