forked from petercable/grpc_requests
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from wesky93/viridianforge/protobuf-4.22-upgrades
Viridianforge/protobuf 4.23 upgrades
- Loading branch information
Showing
10 changed files
with
168 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import multiprocessing | ||
import pytest | ||
import time | ||
|
||
from .test_servers.helloworld_server import HelloWorldServer | ||
|
||
|
||
def helloworld_server_starter(): | ||
server = HelloWorldServer('50051') | ||
server.serve() | ||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def helloworld_server(): | ||
helloworld_server_process = multiprocessing.Process(target=helloworld_server_starter) | ||
helloworld_server_process.start() | ||
time.sleep(1) | ||
yield | ||
helloworld_server_process.terminate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import logging | ||
import pytest | ||
|
||
from ..grpc_requests.client import Client, ServiceClient | ||
|
||
""" | ||
Test cases for ServiceClient | ||
""" | ||
|
||
logger = logging.getLogger('name') | ||
|
||
@pytest.fixture(scope="module") | ||
def helloworld_service_client(): | ||
try: | ||
client = ServiceClient(Client('localhost:50051'), "helloworld.Greeter") | ||
yield client | ||
except: # noqa: E722 | ||
pytest.fail("Could not connect to local HelloWorld server") | ||
|
||
def test_method_names(helloworld_service_client): | ||
method_names = helloworld_service_client.method_names | ||
assert method_names == ('SayHello', 'SayHelloGroup', 'HelloEveryone', 'SayHelloOneByOne') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import logging | ||
import pytest | ||
|
||
from ..grpc_requests.client import StubClient | ||
from .test_protos.helloworld_pb2 import _GREETER | ||
from google.protobuf.json_format import ParseError | ||
|
||
""" | ||
Test cases for reflection based client | ||
""" | ||
|
||
logger = logging.getLogger('name') | ||
|
||
@pytest.fixture(scope="module") | ||
def helloworld_stub_client(): | ||
try: | ||
client = StubClient('localhost:50051', [_GREETER]) | ||
yield client | ||
except: # noqa: E722 | ||
pytest.fail("Could not connect to local HelloWorld server") | ||
|
||
|
||
def test_unary_unary(helloworld_stub_client): | ||
response = helloworld_stub_client.unary_unary('helloworld.Greeter', 'SayHello', {"name": "sinsky"}) | ||
assert type(response) == dict | ||
assert response == {"message": "Hello, sinsky!"} | ||
|
||
def test_empty_body_request(helloworld_stub_client): | ||
response = helloworld_stub_client.unary_unary('helloworld.Greeter', 'SayHello', {}) | ||
logger.warning(f"Response: {response}") | ||
assert type(response) == dict | ||
|
||
def test_nonexistent_service(helloworld_stub_client): | ||
with pytest.raises(ValueError): | ||
helloworld_stub_client.unary_unary('helloworld.Speaker', 'SingHello', {}) | ||
|
||
def test_nonexistent_method(helloworld_stub_client): | ||
with pytest.raises(ValueError): | ||
helloworld_stub_client.unary_unary('helloworld.Greeter', 'SayGoodbye', {}) | ||
|
||
def test_unsupported_argument(helloworld_stub_client): | ||
with pytest.raises(ParseError): | ||
helloworld_stub_client.unary_unary('helloworld.Greeter', 'SayHello', {"foo": "bar"}) | ||
|
||
def test_unary_stream(helloworld_stub_client): | ||
name_list = ["sinsky", "viridianforge", "jack", "harry"] | ||
responses = helloworld_stub_client.unary_stream( | ||
'helloworld.Greeter', | ||
'SayHelloGroup', | ||
{"name": "".join(name_list)} | ||
) | ||
assert all(type(response) == dict for response in responses) | ||
for response, name in zip(responses, name_list): | ||
assert response == {"message": f"Hello, {name}!"} | ||
|
||
def test_stream_unary(helloworld_stub_client): | ||
name_list = ["sinsky", "viridianforge", "jack", "harry"] | ||
response = helloworld_stub_client.stream_unary( | ||
'helloworld.Greeter', | ||
'HelloEveryone', | ||
[{"name": name} for name in name_list] | ||
) | ||
assert type(response) == dict | ||
assert response == {'message': f'Hello, {" ".join(name_list)}!'} | ||
|
||
def test_stream_stream(helloworld_stub_client): | ||
name_list = ["sinsky", "viridianforge", "jack", "harry"] | ||
responses = helloworld_stub_client.stream_stream( | ||
'helloworld.Greeter', | ||
'SayHelloOneByOne', | ||
[{"name": name} for name in name_list] | ||
) | ||
assert all(type(response) == dict for response in responses) | ||
for response, name in zip(responses, name_list): | ||
assert response == {"message": f"Hello, {name}!"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters