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