| 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 |
"""Test of gRPC Python's application-layer API.""" |
| 15 |
|
| 16 |
import logging |
| 17 |
import unittest |
| 18 |
|
| 19 |
import grpc |
| 20 |
|
| 21 |
from tests.unit import _from_grpc_import_star |
| 22 |
|
| 23 |
|
| 24 |
class AllTest(unittest.TestCase): |
| 25 |
|
| 26 |
def testAll(self): |
| 27 |
expected_grpc_code_elements = ( |
| 28 |
'FutureTimeoutError', |
| 29 |
'FutureCancelledError', |
| 30 |
'Future', |
| 31 |
'ChannelConnectivity', |
| 32 |
'Compression', |
| 33 |
'StatusCode', |
| 34 |
'Status', |
| 35 |
'RpcError', |
| 36 |
'RpcContext', |
| 37 |
'Call', |
| 38 |
'ChannelCredentials', |
| 39 |
'CallCredentials', |
| 40 |
'AuthMetadataContext', |
| 41 |
'AuthMetadataPluginCallback', |
| 42 |
'AuthMetadataPlugin', |
| 43 |
'ServerCertificateConfiguration', |
| 44 |
'ServerCredentials', |
| 45 |
'UnaryUnaryMultiCallable', |
| 46 |
'UnaryStreamMultiCallable', |
| 47 |
'StreamUnaryMultiCallable', |
| 48 |
'StreamStreamMultiCallable', |
| 49 |
'UnaryUnaryClientInterceptor', |
| 50 |
'UnaryStreamClientInterceptor', |
| 51 |
'StreamUnaryClientInterceptor', |
| 52 |
'StreamStreamClientInterceptor', |
| 53 |
'Channel', |
| 54 |
'ServicerContext', |
| 55 |
'RpcMethodHandler', |
| 56 |
'HandlerCallDetails', |
| 57 |
'GenericRpcHandler', |
| 58 |
'ServiceRpcHandler', |
| 59 |
'Server', |
| 60 |
'ServerInterceptor', |
| 61 |
'LocalConnectionType', |
| 62 |
'local_channel_credentials', |
| 63 |
'local_server_credentials', |
| 64 |
'alts_channel_credentials', |
| 65 |
'alts_server_credentials', |
| 66 |
'unary_unary_rpc_method_handler', |
| 67 |
'unary_stream_rpc_method_handler', |
| 68 |
'stream_unary_rpc_method_handler', |
| 69 |
'ClientCallDetails', |
| 70 |
'stream_stream_rpc_method_handler', |
| 71 |
'method_handlers_generic_handler', |
| 72 |
'ssl_channel_credentials', |
| 73 |
'metadata_call_credentials', |
| 74 |
'access_token_call_credentials', |
| 75 |
'composite_call_credentials', |
| 76 |
'composite_channel_credentials', |
| 77 |
'compute_engine_channel_credentials', |
| 78 |
'ssl_server_credentials', |
| 79 |
'ssl_server_certificate_configuration', |
| 80 |
'dynamic_ssl_server_credentials', |
| 81 |
'channel_ready_future', |
| 82 |
'insecure_channel', |
| 83 |
'secure_channel', |
| 84 |
'intercept_channel', |
| 85 |
'server', |
| 86 |
'protos', |
| 87 |
'services', |
| 88 |
'protos_and_services', |
| 89 |
'xds_channel_credentials', |
| 90 |
'xds_server_credentials', |
| 91 |
'insecure_server_credentials', |
| 92 |
) |
| 93 |
|
| 94 |
self.assertCountEqual(expected_grpc_code_elements, |
| 95 |
_from_grpc_import_star.GRPC_ELEMENTS) |
| 96 |
|
| 97 |
|
| 98 |
class ChannelConnectivityTest(unittest.TestCase): |
| 99 |
|
| 100 |
def testChannelConnectivity(self): |
| 101 |
self.assertSequenceEqual(( |
| 102 |
grpc.ChannelConnectivity.IDLE, |
| 103 |
grpc.ChannelConnectivity.CONNECTING, |
| 104 |
grpc.ChannelConnectivity.READY, |
| 105 |
grpc.ChannelConnectivity.TRANSIENT_FAILURE, |
| 106 |
grpc.ChannelConnectivity.SHUTDOWN, |
| 107 |
), tuple(grpc.ChannelConnectivity)) |
| 108 |
|
| 109 |
|
| 110 |
class ChannelTest(unittest.TestCase): |
| 111 |
|
| 112 |
def test_secure_channel(self): |
| 113 |
channel_credentials = grpc.ssl_channel_credentials() |
| 114 |
channel = grpc.secure_channel('google.com:443', channel_credentials) |
| 115 |
channel.close() |
| 116 |
|
| 117 |
|
| 118 |
if __name__ == '__main__': |
| 119 |
logging.basicConfig() |
| 120 |
unittest.main(verbosity=2) |