Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #41 from lendingblock/master
Browse files Browse the repository at this point in the history
0.2.5
  • Loading branch information
lsbardel authored Jul 9, 2018
2 parents 44750e8 + bcdc338 commit a45e2d4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion openapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Minimal OpenAPI asynchronous server application
"""
__version__ = '0.2.4'
__version__ = '0.2.5'
5 changes: 4 additions & 1 deletion openapi/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

class OpenApiClient(click.Group):

def __init__(self, spec, setup_app=None, base_path=None, **extra):
def __init__(self, spec, setup_app=None, base_path=None,
commands=None, **extra) -> None:
params = list(extra.pop('params', None) or ())
self.spec = spec
self.debug = get_debug_flag()
Expand All @@ -38,6 +39,8 @@ def __init__(self, spec, setup_app=None, base_path=None, **extra):
)
super().__init__(params=params, **extra)
self.add_command(serve)
for command in commands or ():
self.add_command(command)
self._web = None

def web(self):
Expand Down
6 changes: 4 additions & 2 deletions openapi/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
from .spec.pagination import MAX_PAGINATION_LIMIT


def rest(setup_app=None, base_path=None, **kwargs):
def rest(setup_app=None, base_path=None, commands=None, **kwargs):
"""Create the OpenApi application server
"""
spec = OpenApi(**kwargs)
return OpenApiClient(spec, base_path=base_path, setup_app=setup_app)
return OpenApiClient(
spec, base_path=base_path, commands=commands, setup_app=setup_app
)


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion tests/example/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Task(TaskAdd):
@dataclass
class TaskQuery:
done: bool = data_field()
severity: int = decimal_field(ops=('lt', 'gt'))
severity: int = decimal_field(ops=('lt', 'le', 'gt', 'ge', 'ne'))


@dataclass
Expand Down
16 changes: 16 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from unittest.mock import patch

import click
from click.testing import CliRunner

from openapi.rest import rest
Expand Down Expand Up @@ -27,3 +29,17 @@ def test_serve():
assert mock.call_count == 1
app = mock.call_args[0][0]
assert app.router is not None


def test_commands():
runner = CliRunner()
cli = rest(base_path='/v1', commands=[hello])
result = runner.invoke(cli, ['hello'])
assert result.exit_code == 0
assert result.output.startswith('Hello!')


@click.command('hello')
@click.pass_context
def hello(ctx):
click.echo('Hello!')
13 changes: 10 additions & 3 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ async def test_spec(test_app):
'done',
'severity',
'severity:lt',
'severity:gt'
'severity:le',
'severity:gt',
'severity:ge',
'severity:ne',
}


Expand Down Expand Up @@ -41,8 +44,12 @@ async def assert_query(params, expected):
d.pop('id')
assert body == expected

await assert_query({'severity:gt': 2}, [test2])
await assert_query({'severity:lt': 2}, [test1])
await assert_query({'severity:gt': 1}, [test2])
await assert_query({'severity:ge': 1}, [test1, test2])
await assert_query({'severity:lt': 3}, [test1])
await assert_query({'severity:le': 2}, [test1])
await assert_query({'severity:le': 3}, [test1, test2])
await assert_query({'severity:ne': 3}, [test1])
await assert_query({'severity': 2}, [])
await assert_query({'severity': 1}, [test1])
await assert_query({'severity': 'NULL'}, [test3])

0 comments on commit a45e2d4

Please sign in to comment.