Skip to content

Commit f1ce089

Browse files
authored
feat proto: use pre-generated protos in testsuite (#30)
1 parent 90c3e63 commit f1ce089

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

tests/conftest.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,22 @@
66

77
from testsuite.databases.pgsql import discover
88

9-
USERVER_CONFIG_HOOKS = ['_prepare_service_config']
9+
import handlers.hello_pb2_grpc as hello_services # noqa: E402, E501
10+
11+
USERVER_CONFIG_HOOKS = ['prepare_service_config']
1012
pytest_plugins = [
1113
'pytest_userver.plugins.postgresql',
1214
'pytest_userver.plugins.grpc',
1315
]
1416

1517

16-
@pytest.fixture(scope='session')
17-
def hello_protos():
18-
return grpc.protos('hello.proto')
19-
20-
21-
@pytest.fixture(scope='session')
22-
def hello_services():
23-
return grpc.services('hello.proto')
24-
25-
2618
@pytest.fixture
27-
def grpc_service(pgsql, hello_services, grpc_channel, service_client):
19+
def grpc_service(pgsql, grpc_channel, service_client):
2820
return hello_services.HelloServiceStub(grpc_channel)
2921

3022

3123
@pytest.fixture(scope='session')
32-
def mock_grpc_hello_session(
33-
hello_services, grpc_mockserver, create_grpc_mock,
34-
):
24+
def mock_grpc_hello_session(grpc_mockserver, create_grpc_mock):
3525
mock = create_grpc_mock(hello_services.HelloServiceServicer)
3626
hello_services.add_HelloServiceServicer_to_server(
3727
mock.servicer, grpc_mockserver,
@@ -46,7 +36,7 @@ def mock_grpc_server(mock_grpc_hello_session):
4636

4737

4838
@pytest.fixture(scope='session')
49-
def _prepare_service_config(grpc_mockserver_endpoint):
39+
def prepare_service_config(grpc_mockserver_endpoint):
5040
def patch_config(config, config_vars):
5141
components = config['components_manager']['components']
5242
components['hello-client']['endpoint'] = grpc_mockserver_endpoint

tests/test_hello.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import pytest
22

3+
import handlers.hello_pb2 as hello_protos # noqa: E402, E501
4+
35
# Start the tests via `make test-debug` or `make test-release`
46

57

6-
async def test_grpc_client(hello_protos, mock_grpc_server, grpc_service):
8+
async def test_grpc_client(mock_grpc_server, grpc_service):
79
@mock_grpc_server('SayHello')
810
async def mock_say_hello(request, context):
911
assert request.name
@@ -17,13 +19,13 @@ async def mock_say_hello(request, context):
1719
assert mock_say_hello.times_called == 1
1820

1921

20-
async def test_first_time_users(hello_protos, grpc_service):
22+
async def test_first_time_users(grpc_service):
2123
request = hello_protos.HelloRequest(name='userver')
2224
response = await grpc_service.SayHello(request)
2325
assert response.text == 'Hello, userver!\n'
2426

2527

26-
async def test_db_updates(hello_protos, grpc_service):
28+
async def test_db_updates(grpc_service):
2729
request = hello_protos.HelloRequest(name='World')
2830
response = await grpc_service.SayHello(request)
2931
assert response.text == 'Hello, World!\n'
@@ -38,7 +40,7 @@ async def test_db_updates(hello_protos, grpc_service):
3840

3941

4042
@pytest.mark.pgsql('db_1', files=['initial_data.sql'])
41-
async def test_db_initial_data(hello_protos, grpc_service):
43+
async def test_db_initial_data(grpc_service):
4244
request = hello_protos.HelloRequest(name='user-from-initial_data.sql')
4345
response = await grpc_service.SayHello(request)
4446
assert response.text == 'Hi again, user-from-initial_data.sql!\n'

0 commit comments

Comments
 (0)