From 01401f00b0befc57e32c5ba096a7df90aafbe0d0 Mon Sep 17 00:00:00 2001 From: Wayne Manselle Date: Mon, 27 Nov 2023 20:21:11 -0800 Subject: [PATCH 1/2] Doc fix, new test --- .github/workflows/test.yaml | 2 +- src/examples/README.md | 2 +- src/tests/reflection_client_test.py | 9 +++++++++ .../test_servers/helloworld/helloworld_server.py | 11 ++++++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ffe41d2..994aa52 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ '3.7', '3.8', '3.9', '3.10', '3.11' ] + python-version: [ '3.7', '3.8', '3.9', '3.10', '3.11', '3.12' ] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} diff --git a/src/examples/README.md b/src/examples/README.md index 763787e..663a70a 100644 --- a/src/examples/README.md +++ b/src/examples/README.md @@ -25,7 +25,7 @@ header. ```python from grpc_requests import Client -metadata = [{"authorization", f"bearer {my_bearer_token}"] +metadata = [("authorization", f"bearer {my_bearer_token}")] client = Client.get_by_endpoint("my.supercool.hostname:443", ssl=True, metadata=metadata) health_response = client.request('grpc.health.v1.Health', 'Check', {}, metadata=metadata) diff --git a/src/tests/reflection_client_test.py b/src/tests/reflection_client_test.py index adc1d2f..c8ac2d5 100644 --- a/src/tests/reflection_client_test.py +++ b/src/tests/reflection_client_test.py @@ -26,6 +26,15 @@ def client_tester_reflection_client(): except: # noqa: E722 pytest.fail("Could not connect to local Test server") +def test_metadata_usage(helloworld_reflection_client): + response = helloworld_reflection_client.request( + 'helloworld.Greeter', 'SayHello', + {"name": "sinsky"}, + metadata=[('password', '12345')] + ) + assert isinstance(response, dict) + assert response == {"message": "Hello, sinsky, password accepted!"} + def test_unary_unary(helloworld_reflection_client): response = helloworld_reflection_client.request('helloworld.Greeter', 'SayHello', {"name": "sinsky"}) diff --git a/src/tests/test_servers/helloworld/helloworld_server.py b/src/tests/test_servers/helloworld/helloworld_server.py index 1dd398d..d62cc3a 100644 --- a/src/tests/test_servers/helloworld/helloworld_server.py +++ b/src/tests/test_servers/helloworld/helloworld_server.py @@ -13,7 +13,16 @@ def SayHello(self, request, context): Unary-Unary Sends a HelloReply based on a HelloRequest. """ - return HelloReply(message=f"Hello, {request.name}!") + authorized = False + if context.invocation_metadata(): + for key, value in context.invocation_metadata(): + if key == "password" and value == "12345": + authorized = True + + if authorized: + return HelloReply(message=f"Hello, {request.name}, password accepted!") + else: + return HelloReply(message=f"Hello, {request.name}!") def SayHelloGroup(self, request, context): """ From b284e5bd4e315ad82f368f1b1906665882af594d Mon Sep 17 00:00:00 2001 From: Wayne Manselle Date: Mon, 27 Nov 2023 20:33:31 -0800 Subject: [PATCH 2/2] Update setup.cfg --- setup.cfg | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 801b719..79f3e78 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,8 +3,10 @@ name = grpc_requests # Version needs regex in setup.py. url = https://github.com/wesky93/grpc_requests license = Apache License 2.0 -maintainer = wesky93 -maintainer_email = wesky93@gmail.com +author = wesky93 +author_email = wesky93@gmail.com +maintainer = ViridianForge +maintainer_email = wayne@viridianforge.tech description = grpc for Humans. grpc reflection support client long_description = file: README.md, CHANGELOG.md long_description_content_type = text/markdown @@ -19,6 +21,7 @@ classifiers = Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 Topic :: Software Development :: Libraries :: Python Modules