Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for the implicit corotine decoration of XMLRPC methods #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions tests/test_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import datetime
import re

import pytest
from aiohttp import web
Expand All @@ -15,27 +16,39 @@


class XMLRPCMain(handler.XMLRPCView):
def rpc_test(self):
async def rpc_test(self):
return None

def rpc_args(self, *args):
async def rpc_args(self, *args):
return len(args)

def rpc_kwargs(self, **kwargs):
async def rpc_kwargs(self, **kwargs):
return len(kwargs)

def rpc_args_kwargs(self, *args, **kwargs):
async def rpc_args_kwargs(self, *args, **kwargs):
return len(args) + len(kwargs)

def rpc_exception(self):
async def rpc_exception(self):
raise Exception("YEEEEEE!!!")

def rpc_strings(self, s1, s2):
async def rpc_strings(self, s1, s2):
return s1 == s2

def rpc_datetime(self, test_datetime_1, test_datetime_2):
async def rpc_datetime(self, test_datetime_1, test_datetime_2):
return test_datetime_1, test_datetime_2

@staticmethod
def rpc_implicit_coro_yield_from(*args, **kwargs):
async def example(v):
return v

return (yield from example((args, kwargs)))

@staticmethod
def rpc_implicit_coro_fn(*args, **kwargs):
return ((args, kwargs))



def create_app(loop):
app = web.Application(loop=loop)
Expand Down Expand Up @@ -162,3 +175,11 @@ async def test_9_datetime(test_client):
root = etree.fromstring((await resp.read()))
assert root.xpath('//value/dateTime.iso8601/text()')[0] == resp_date
assert root.xpath('//value/dateTime.iso8601/text()')[1] == resp_date


@pytest.mark.parametrize(
"method_name", ["implicit_coro_yield_from", "implicit_coro_fn"]
)
async def test_10_implicit_coro(client, method_name):
result = await getattr(client, method_name)("ham", "spam", eggs="bacon")
assert result == [["ham", "spam"], {"eggs": "bacon"}]