Skip to content

Commit

Permalink
Merge pull request #39 from wesky93/develop
Browse files Browse the repository at this point in the history
Doc fixes
  • Loading branch information
ViridianForge authored Nov 28, 2023
2 parents cd3a020 + 4e34842 commit 262608a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
7 changes: 5 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [email protected]
author = wesky93
author_email = [email protected]
maintainer = ViridianForge
maintainer_email = [email protected]
description = grpc for Humans. grpc reflection support client
long_description = file: README.md, CHANGELOG.md
long_description_content_type = text/markdown
Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion src/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/tests/reflection_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down
11 changes: 10 additions & 1 deletion src/tests/test_servers/helloworld/helloworld_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 262608a

Please sign in to comment.