Skip to content

Commit

Permalink
Update tests for when no request body is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruwann committed Jun 20, 2023
1 parent 0f6f4ff commit dbca336
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/decorators/test_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ def handler(**kwargs):
func(**kwargs)

operation = MagicMock(name="operation")
operation.request_body = {}
operation.body_name = lambda _: "body"

with TestContext(operation=operation):
parameter_decorator = SyncParameterDecorator(framework=FlaskFramework)
decorated_handler = parameter_decorator(handler)
decorated_handler(request)
func.assert_called_with(p1="123", body={})
func.assert_called_with(p1="123")


@pytest.mark.skipif(
Expand All @@ -53,13 +54,14 @@ async def handler(**kwargs):
func(**kwargs)

operation = MagicMock(name="operation")
operation.request_body = {}
operation.body_name = lambda _: "body"

with TestContext(operation=operation):
parameter_decorator = AsyncParameterDecorator(framework=StarletteFramework)
decorated_handler = parameter_decorator(handler)
await decorated_handler(request)
func.assert_called_with(p1="123", body={})
func.assert_called_with(p1="123")


def test_sync_injection_with_context():
Expand All @@ -75,13 +77,14 @@ def handler(context_, **kwargs):
context = {"test": "success"}

operation = MagicMock(name="operation")
operation.request_body = {}
operation.body_name = lambda _: "body"

with TestContext(context=context, operation=operation):
parameter_decorator = SyncParameterDecorator(framework=FlaskFramework)
decorated_handler = parameter_decorator(handler)
decorated_handler(request)
func.assert_called_with(context, p1="123", test="success", body={})
func.assert_called_with(context, p1="123", test="success")


@pytest.mark.skipif(
Expand All @@ -101,13 +104,14 @@ async def handler(context_, **kwargs):
context = {"test": "success"}

operation = MagicMock(name="operation")
operation.request_body = {}
operation.body_name = lambda _: "body"

with TestContext(context=context, operation=operation):
parameter_decorator = AsyncParameterDecorator(framework=StarletteFramework)
decorated_handler = parameter_decorator(handler)
await decorated_handler(request)
func.assert_called_with(context, p1="123", test="success", body={})
func.assert_called_with(context, p1="123", test="success")


def test_pythonic_params():
Expand Down

0 comments on commit dbca336

Please sign in to comment.