forked from gluk-w/django-grpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stan Misiurev
committed
Jan 22, 2019
1 parent
65345fd
commit 28a8b1c
Showing
17 changed files
with
309 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.1.3' | ||
__version__ = '0.1.4' |
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 |
---|---|---|
@@ -1,3 +1,28 @@ | ||
from concurrent import futures | ||
|
||
import grpc | ||
from django.utils.module_loading import import_string | ||
|
||
|
||
def create_server(max_workers, port): | ||
# create a gRPC server | ||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=max_workers)) | ||
|
||
add_servicers(server) | ||
server.add_insecure_port('[::]:%s' % port) | ||
return server | ||
|
||
|
||
def add_servicers(server): | ||
""" | ||
Add servicers to the server | ||
""" | ||
from django.conf import settings | ||
for path in settings.GRPC_SERVICERS: | ||
callback = import_string(path) | ||
callback(server) | ||
|
||
|
||
def extract_handlers(server): | ||
for it in server._state.generic_handlers[0]._method_handlers.values(): | ||
yield it.unary_unary.__name__ | ||
yield it.unary_unary.__qualname__ |
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 |
---|---|---|
|
@@ -6,3 +6,5 @@ codecov>=2.0.0 | |
|
||
|
||
# Additional test requirements go here | ||
pytest | ||
pytest-mock |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[bumpversion] | ||
current_version = 0.1.3 | ||
current_version = 0.1.4 | ||
commit = True | ||
tag = True | ||
|
||
|
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,17 @@ | ||
import threading | ||
from time import sleep | ||
|
||
import pytest | ||
from django.core.management import call_command | ||
|
||
|
||
|
||
@pytest.fixture | ||
def grpc_server_async(): | ||
srv = threading.Thread(target=call_grpc_server_command, args=[{"max_workers": 3, "port": 50080, "autoreload": False}]) | ||
srv.start() | ||
sleep(5) | ||
|
||
yield | ||
|
||
srv.join() |
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,10 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings") | ||
|
||
from django.core.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) |
Empty file.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,46 @@ | ||
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! | ||
import grpc | ||
|
||
from tests.sampleapp import helloworld_pb2 | ||
|
||
|
||
class GreeterStub(object): | ||
"""The greeting service definition. | ||
""" | ||
|
||
def __init__(self, channel): | ||
"""Constructor. | ||
Args: | ||
channel: A grpc.Channel. | ||
""" | ||
self.SayHello = channel.unary_unary( | ||
'/helloworld.Greeter/SayHello', | ||
request_serializer=helloworld_pb2.HelloRequest.SerializeToString, | ||
response_deserializer=helloworld_pb2.HelloReply.FromString, | ||
) | ||
|
||
|
||
class GreeterServicer(object): | ||
"""The greeting service definition. | ||
""" | ||
|
||
def SayHello(self, request, context): | ||
"""Sends a greeting | ||
""" | ||
context.set_code(grpc.StatusCode.UNIMPLEMENTED) | ||
context.set_details('Method not implemented!') | ||
raise NotImplementedError('Method not implemented!') | ||
|
||
|
||
def add_GreeterServicer_to_server(servicer, server): | ||
rpc_method_handlers = { | ||
'SayHello': grpc.unary_unary_rpc_method_handler( | ||
servicer.SayHello, | ||
request_deserializer=helloworld_pb2.HelloRequest.FromString, | ||
response_serializer=helloworld_pb2.HelloReply.SerializeToString, | ||
), | ||
} | ||
generic_handler = grpc.method_handlers_generic_handler( | ||
'helloworld.Greeter', rpc_method_handlers) | ||
server.add_generic_rpc_handlers((generic_handler,)) |
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,7 @@ | ||
from tests.sampleapp import helloworld_pb2_grpc, helloworld_pb2 | ||
|
||
|
||
class Greeter(helloworld_pb2_grpc.GreeterServicer): | ||
def SayHello(self, request, context): | ||
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from tests.sampleapp import helloworld_pb2_grpc | ||
from tests.sampleapp.servicer import Greeter | ||
|
||
|
||
def register_servicer(server): | ||
""" Callback for django_grpc """ | ||
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server) | ||
|
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 was deleted.
Oops, something went wrong.
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,20 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
import threading | ||
from time import sleep | ||
|
||
import pytest | ||
from django.core.management import call_command | ||
|
||
|
||
def call_grpc_server_command(options): | ||
call_command("grpcserver", **options) | ||
|
||
|
||
def test_management_command(mocker): | ||
mocker.patch.object('') | ||
|
||
srv = threading.Thread(target=call_grpc_server_command, args=[{"max_workers": 3, "port": 50080, "autoreload": False}]) | ||
srv.start() | ||
sleep(5) | ||
|
Oops, something went wrong.