-
Notifications
You must be signed in to change notification settings - Fork 3
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 #57 from dapper91/dev
Dev
- Loading branch information
Showing
7 changed files
with
140 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pytest | ||
from aiohttp import web | ||
from unittest import mock | ||
|
||
import pjrpc.server | ||
from pjrpc.client.backend import aiohttp as async_client | ||
from pjrpc.server.integration import aiohttp as integration | ||
from pjrpc.client.integrations.pytest import PjRpcAiohttpMocker | ||
|
||
methods = pjrpc.server.MethodRegistry() | ||
|
||
|
||
@methods.add | ||
async def div(a, b): | ||
cli = async_client.Client('http://127.0.0.2:8000/api/v1') | ||
return await cli.proxy.div(a, b) | ||
|
||
|
||
@pytest.fixture | ||
def http_app(): | ||
return web.Application() | ||
|
||
|
||
@pytest.fixture | ||
def jsonrpc_app(http_app): | ||
jsonrpc_app = integration.Application('/api/v1', app=http_app) | ||
jsonrpc_app.dispatcher.add_methods(methods) | ||
|
||
return jsonrpc_app | ||
|
||
|
||
async def test_pjrpc_server(aiohttp_client, http_app, jsonrpc_app): | ||
jsonrpc_cli = async_client.Client('/api/v1', session=await aiohttp_client(http_app)) | ||
|
||
with PjRpcAiohttpMocker(passthrough=True) as mocker: | ||
mocker.add('http://127.0.0.2:8000/api/v1', 'div', result=2) | ||
result = await jsonrpc_cli.proxy.div(4, 2) | ||
assert result == 2 | ||
|
||
localhost_calls = mocker.calls['http://127.0.0.2:8000/api/v1'] | ||
assert localhost_calls[('2.0', 'div')].mock_calls == [mock.call(4, 2)] |
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,59 @@ | ||
import pytest | ||
import flask.testing | ||
from unittest import mock | ||
|
||
import pjrpc.server | ||
import werkzeug.test | ||
from pjrpc.client.backend import requests as client | ||
from pjrpc.server.integration import flask as integration | ||
from pjrpc.client.integrations.pytest import PjRpcRequestsMocker | ||
|
||
methods = pjrpc.server.MethodRegistry() | ||
|
||
|
||
@methods.add | ||
def div(a, b): | ||
cli = client.Client('http://127.0.0.2:8000/api/v1') | ||
return cli.proxy.div(a, b) | ||
|
||
|
||
@pytest.fixture() | ||
def http_app(): | ||
return flask.Flask(__name__) | ||
|
||
|
||
@pytest.fixture | ||
def jsonrpc_app(http_app): | ||
json_rpc = integration.JsonRPC('/api/v1') | ||
json_rpc.dispatcher.add_methods(methods) | ||
|
||
json_rpc.init_app(http_app) | ||
|
||
return jsonrpc_app | ||
|
||
|
||
class Response(werkzeug.test.Response): | ||
def raise_for_status(self): | ||
if self.status_code >= 400: | ||
raise Exception('client response error') | ||
|
||
@property | ||
def text(self): | ||
return self.data.decode() | ||
|
||
|
||
@pytest.fixture() | ||
def app_client(http_app): | ||
return flask.testing.FlaskClient(http_app, Response) | ||
|
||
|
||
def test_pjrpc_server(aiohttp_client, http_app, jsonrpc_app, app_client): | ||
with PjRpcRequestsMocker(passthrough=True) as mocker: | ||
jsonrpc_cli = client.Client('/api/v1', session=app_client) | ||
|
||
mocker.add('http://127.0.0.2:8000/api/v1', 'div', result=2) | ||
result = jsonrpc_cli.proxy.div(4, 2) | ||
assert result == 2 | ||
|
||
localhost_calls = mocker.calls['http://127.0.0.2:8000/api/v1'] | ||
assert localhost_calls[('2.0', 'div')].mock_calls == [mock.call(4, 2)] |
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
__description__ = 'Extensible JSON-RPC library' | ||
__url__ = 'https://github.com/dapper91/pjrpc' | ||
|
||
__version__ = '1.4.0' | ||
__version__ = '1.4.1' | ||
|
||
__author__ = 'Dmitry Pershin' | ||
__email__ = '[email protected]' | ||
|
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