• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cenobites / flask-jsonrpc / 121
100%
master: 100%

Build:
Build:
LAST BUILD BRANCH: feature/github-actions
DEFAULT BRANCH: master
Ran 13 Jul 2020 05:07PM UTC
Jobs 1
Files 13
Run time 8min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

pending completion
121

push

travis-ci

nycholas
Fix the JSON-RPC method signature (return) validation

The return of method can't be known before the evaluation. The code
bellow will work on validate, but will break on execution:

```
@jsonrpc.method('add(a=int, b=int)')
def add(a: int, b: int):
    ...
    return 0
```

The test:

```
def test_app_create_with_method_without_annotation_on_return():
    app = Flask(__name__, instance_relative_config=True)
    jsonrpc = JSONRPC(app, '/api', enable_web_browsable_api=True)

    # pylint: disable=W0612
    @jsonrpc.method('app.fn1')
    def fn1(s: str):
        return 'Foo {0}'.format(s)

    # pylint: disable=W0612
    @jsonrpc.method('app.fn2')
    def fn2(s: str) -> str:
        return 'Bar {0}'.format(s)

    with app.test_client() as client:
        rv = client.post('/api', json={'id': 1, 'jsonrpc': '2.0', 'method': 'app.fn1', 'params': [':)']})
        assert rv.json == {
            'error': {
                'code': -32602,
                'data': {
                    'message': 'return type of str must be a type; got NoneType instead'
                },
                'message': 'Invalid params',
                'name': 'InvalidParamsError',
            },
            'id': 1,
            'jsonrpc': '2.0',
        }
        assert rv.status_code == 400

        rv = client.post('/api', json={'id': 1, 'jsonrpc': '2.0', 'method': 'app.fn2', 'params': [':)']})
        assert rv.json == {'id': 1, 'jsonrpc': '2.0', 'result': 'Bar :)'}
        assert rv.status_code == 200
```

Resolves: #77
See also: #74

118 of 118 branches covered (100.0%)

384 of 384 relevant lines covered (100.0%)

1.0 hits per line

Jobs
ID Job ID Ran Files Coverage
1 121.1 (FLASK_ENV=TESTING) 13 Jul 2020 05:07PM UTC 0
100.0
Travis Job 121.1
Source Files on build 121
Detailed source file information is not available for this build.
  • Back to Repo
  • Travis Build #121
  • cdd7e4d1 on github
  • Prev Build on hotfix/77-method-validate (#119)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc