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