14 """Tests Face interface compliance of the gRPC Python Beta API.""" 
   28 _SERVER_HOST_OVERRIDE = 
'foo.test.google.fr' 
   30 _PER_RPC_CREDENTIALS_METADATA_KEY = b
'my-call-credentials-metadata-key' 
   31 _PER_RPC_CREDENTIALS_METADATA_VALUE = b
'my-call-credentials-metadata-value' 
   34 _UNARY_UNARY = 
'unary-unary' 
   35 _UNARY_STREAM = 
'unary-stream' 
   36 _STREAM_UNARY = 
'stream-unary' 
   37 _STREAM_STREAM = 
'stream-stream' 
   53             self.
_peer = context.protocol_context().
peer()
 
   55             context.protocol_context().disable_next_response_compression()
 
   63             self.
_peer = context.protocol_context().
peer()
 
   65             context.protocol_context().disable_next_response_compression()
 
   72         for request 
in request_iterator:
 
   75             self.
_peer = context.protocol_context().
peer()
 
   77             context.protocol_context().disable_next_response_compression()
 
   83         for request 
in request_iterator:
 
   85                 self.
_peer = context.protocol_context().
peer()
 
   86                 context.protocol_context().disable_next_response_compression()
 
  120                     raise StopIteration()
 
  130             except StopIteration:
 
  137         (_PER_RPC_CREDENTIALS_METADATA_KEY, _PER_RPC_CREDENTIALS_METADATA_VALUE)
 
  145         method_implementations = {
 
  146             (_GROUP, _UNARY_UNARY):
 
  147                 utilities.unary_unary_inline(self.
_servicer.unary_unary),
 
  148             (_GROUP, _UNARY_STREAM):
 
  149                 utilities.unary_stream_inline(self.
_servicer.unary_stream),
 
  150             (_GROUP, _STREAM_UNARY):
 
  151                 utilities.stream_unary_inline(self.
_servicer.stream_unary),
 
  152             (_GROUP, _STREAM_STREAM):
 
  153                 utilities.stream_stream_inline(self.
_servicer.stream_stream),
 
  157             _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY,
 
  158             _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM,
 
  159             _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY,
 
  160             _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM,
 
  163         server_options = implementations.server_options(
 
  164             thread_pool_size=test_constants.POOL_SIZE)
 
  165         self.
_server = implementations.server(method_implementations,
 
  166                                               options=server_options)
 
  167         server_credentials = implementations.ssl_server_credentials([
 
  169                 resources.private_key(),
 
  170                 resources.certificate_chain(),
 
  173         port = self.
_server.add_secure_port(
'[::]:0', server_credentials)
 
  176             resources.test_root_certificates())
 
  179         channel = test_utilities.not_really_secure_channel(
 
  181         stub_options = implementations.stub_options(
 
  182             thread_pool_size=test_constants.POOL_SIZE)
 
  186                                                           options=stub_options)
 
  193         call_options = interfaces.grpc_call_options(
 
  196                            _UNARY_UNARY)(_REQUEST,
 
  197                                          test_constants.LONG_TIMEOUT,
 
  198                                          protocol_options=call_options)
 
  199         self.assertEqual(_RESPONSE, response)
 
  200         self.assertIsNotNone(self.
_servicer.peer())
 
  201         invocation_metadata = [
 
  202             (metadatum.key, metadatum.value)
 
  203             for metadatum 
in self.
_servicer._invocation_metadata
 
  205         self.assertIn((_PER_RPC_CREDENTIALS_METADATA_KEY,
 
  206                        _PER_RPC_CREDENTIALS_METADATA_VALUE),
 
  210         call_options = interfaces.grpc_call_options(
 
  212         response_iterator = getattr(self.
_dynamic_stub, _UNARY_STREAM)(
 
  214             test_constants.LONG_TIMEOUT,
 
  215             protocol_options=call_options)
 
  217         self.assertIsNotNone(self.
_servicer.peer())
 
  218         invocation_metadata = [
 
  219             (metadatum.key, metadatum.value)
 
  220             for metadatum 
in self.
_servicer._invocation_metadata
 
  222         self.assertIn((_PER_RPC_CREDENTIALS_METADATA_KEY,
 
  223                        _PER_RPC_CREDENTIALS_METADATA_VALUE),
 
  227         call_options = interfaces.grpc_call_options(
 
  232             test_constants.LONG_TIMEOUT,
 
  233             protocol_options=call_options)
 
  234         response_future.protocol_context().disable_next_request_compression()
 
  235         request_iterator.allow()
 
  236         response_future.protocol_context().disable_next_request_compression()
 
  237         request_iterator.allow()
 
  239         self.assertIsNotNone(self.
_servicer.peer())
 
  240         self.assertEqual(_RESPONSE, response_future.result())
 
  241         invocation_metadata = [
 
  242             (metadatum.key, metadatum.value)
 
  243             for metadatum 
in self.
_servicer._invocation_metadata
 
  245         self.assertIn((_PER_RPC_CREDENTIALS_METADATA_KEY,
 
  246                        _PER_RPC_CREDENTIALS_METADATA_VALUE),
 
  250         call_options = interfaces.grpc_call_options(
 
  253         response_iterator = getattr(self.
_dynamic_stub, _STREAM_STREAM)(
 
  255             test_constants.SHORT_TIMEOUT,
 
  256             protocol_options=call_options)
 
  257         response_iterator.protocol_context().disable_next_request_compression()
 
  258         request_iterator.allow()
 
  259         response = 
next(response_iterator)
 
  260         response_iterator.protocol_context().disable_next_request_compression()
 
  261         request_iterator.allow()
 
  263         self.assertIsNotNone(self.
_servicer.peer())
 
  264         self.assertEqual(_RESPONSE, response)
 
  265         invocation_metadata = [
 
  266             (metadatum.key, metadatum.value)
 
  267             for metadatum 
in self.
_servicer._invocation_metadata
 
  269         self.assertIn((_PER_RPC_CREDENTIALS_METADATA_KEY,
 
  270                        _PER_RPC_CREDENTIALS_METADATA_VALUE),
 
  279             (_GROUP, _UNARY_UNARY):
 
  280                 utilities.unary_unary_inline(self.
_servicer.unary_unary),
 
  281             (_GROUP, _UNARY_STREAM):
 
  282                 utilities.unary_stream_inline(self.
_servicer.unary_stream),
 
  283             (_GROUP, _STREAM_UNARY):
 
  284                 utilities.stream_unary_inline(self.
_servicer.stream_unary),
 
  285             (_GROUP, _STREAM_STREAM):
 
  286                 utilities.stream_stream_inline(self.
_servicer.stream_stream),
 
  290             _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY,
 
  291             _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM,
 
  292             _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY,
 
  293             _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM,
 
  297             thread_pool_size=test_constants.POOL_SIZE)
 
  300                 resources.private_key(),
 
  301                 resources.certificate_chain(),
 
  305             resources.test_root_certificates())
 
  307             thread_pool_size=test_constants.POOL_SIZE)
 
  315         channel = test_utilities.not_really_secure_channel(
 
  317         dynamic_stub = implementations.dynamic_stub(channel,
 
  326                 call_options = interfaces.grpc_call_options(
 
  327                     disable_compression=
True)
 
  328                 response = getattr(dynamic_stub,
 
  329                                    _UNARY_UNARY)(_REQUEST,
 
  330                                                  test_constants.LONG_TIMEOUT,
 
  331                                                  protocol_options=call_options)
 
  332                 self.assertEqual(_RESPONSE, response)
 
  333                 self.assertIsNotNone(self.
_servicer.peer())
 
  335         server.stop(test_constants.SHORT_TIMEOUT).
wait()
 
  343             server.stop(test_constants.SHORT_TIMEOUT).
wait()
 
  348             server.add_insecure_port(
'[::]:0')
 
  350                 server.stop(test_constants.SHORT_TIMEOUT)
 
  351             server.stop(test_constants.SHORT_TIMEOUT)
 
  354 if __name__ == 
'__main__':
 
  355     unittest.main(verbosity=2)