Debian Codegraph @

src/python/grpcio_tests/tests/unit/beta/_not_found_test.py

raw
1 # Copyright 2015 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 of RPC-method-not-found behavior."""
15
16 import unittest
17
18 from grpc.beta import implementations
19 from grpc.beta import interfaces
20 from grpc.framework.interfaces.face import face
21
22 from tests.unit.framework.common import test_constants
23
24
25 class NotFoundTest(unittest.TestCase):
26
27 def setUp(self):
28 self._server = implementations.server({})
29 port = self._server.add_insecure_port('[::]:0')
30 channel = implementations.insecure_channel('localhost', port)
31 self._generic_stub = implementations.generic_stub(channel)
32 self._server.start()
33
34 def tearDown(self):
35 self._server.stop(0).wait()
36 self._generic_stub = None
37
38 def test_blocking_unary_unary_not_found(self):
39 with self.assertRaises(face.LocalError) as exception_assertion_context:
40 self._generic_stub.blocking_unary_unary('groop',
41 'meffod',
42 b'abc',
43 test_constants.LONG_TIMEOUT,
44 with_call=True)
45 self.assertIs(exception_assertion_context.exception.code,
46 interfaces.StatusCode.UNIMPLEMENTED)
47
48 def test_future_stream_unary_not_found(self):
49 rpc_future = self._generic_stub.future_stream_unary(
50 'grupe', 'mevvod', iter([b'def']), test_constants.LONG_TIMEOUT)
51 with self.assertRaises(face.LocalError) as exception_assertion_context:
52 rpc_future.result()
53 self.assertIs(exception_assertion_context.exception.code,
54 interfaces.StatusCode.UNIMPLEMENTED)
55 self.assertIs(rpc_future.exception().code,
56 interfaces.StatusCode.UNIMPLEMENTED)
57
58
59 if __name__ == '__main__':
60 unittest.main(verbosity=2)