| 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 |
"""Insecure client-server interoperability as a unit test.""" |
| 15 |
|
| 16 |
import sys |
| 17 |
import unittest |
| 18 |
|
| 19 |
import grpc |
| 20 |
|
| 21 |
from src.proto.grpc.testing import test_pb2_grpc |
| 22 |
from tests.interop import _intraop_test_case |
| 23 |
from tests.interop import server |
| 24 |
from tests.interop import service |
| 25 |
from tests.unit import test_common |
| 26 |
|
| 27 |
|
| 28 |
@unittest.skipIf(sys.version_info[0] < 3, |
| 29 |
'ProtoBuf descriptor has moved on from Python2') |
| 30 |
class InsecureIntraopTest(_intraop_test_case.IntraopTestCase, |
| 31 |
unittest.TestCase): |
| 32 |
|
| 33 |
def setUp(self): |
| 34 |
self.server = test_common.test_server() |
| 35 |
test_pb2_grpc.add_TestServiceServicer_to_server(service.TestService(), |
| 36 |
self.server) |
| 37 |
port = self.server.add_insecure_port('[::]:0') |
| 38 |
self.server.start() |
| 39 |
self.stub = test_pb2_grpc.TestServiceStub( |
| 40 |
grpc.insecure_channel('localhost:{}'.format(port))) |
| 41 |
|
| 42 |
def tearDown(self): |
| 43 |
self.server.stop(None) |
| 44 |
|
| 45 |
|
| 46 |
if __name__ == '__main__': |
| 47 |
unittest.main(verbosity=2) |