| 1 |
# Copyright 2016 gRPC authors. |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
"""Tests the implementations module of the gRPC Python Beta API.""" |
| 15 |
|
| 16 |
import datetime |
| 17 |
import unittest |
| 18 |
|
| 19 |
from grpc.beta import implementations |
| 20 |
from oauth2client import client as oauth2client_client |
| 21 |
|
| 22 |
from tests.unit import resources |
| 23 |
|
| 24 |
|
| 25 |
class ChannelCredentialsTest(unittest.TestCase): |
| 26 |
|
| 27 |
def test_runtime_provided_root_certificates(self): |
| 28 |
channel_credentials = implementations.ssl_channel_credentials() |
| 29 |
self.assertIsInstance(channel_credentials, |
| 30 |
implementations.ChannelCredentials) |
| 31 |
|
| 32 |
def test_application_provided_root_certificates(self): |
| 33 |
channel_credentials = implementations.ssl_channel_credentials( |
| 34 |
resources.test_root_certificates()) |
| 35 |
self.assertIsInstance(channel_credentials, |
| 36 |
implementations.ChannelCredentials) |
| 37 |
|
| 38 |
|
| 39 |
class CallCredentialsTest(unittest.TestCase): |
| 40 |
|
| 41 |
def test_google_call_credentials(self): |
| 42 |
creds = oauth2client_client.GoogleCredentials( |
| 43 |
'token', 'client_id', 'secret', 'refresh_token', |
| 44 |
datetime.datetime(2008, 6, 24), 'https://refresh.uri.com/', |
| 45 |
'user_agent') |
| 46 |
call_creds = implementations.google_call_credentials(creds) |
| 47 |
self.assertIsInstance(call_creds, implementations.CallCredentials) |
| 48 |
|
| 49 |
def test_access_token_call_credentials(self): |
| 50 |
call_creds = implementations.access_token_call_credentials('token') |
| 51 |
self.assertIsInstance(call_creds, implementations.CallCredentials) |
| 52 |
|
| 53 |
|
| 54 |
if __name__ == '__main__': |
| 55 |
unittest.main(verbosity=2) |