Skip to content

Commit

Permalink
Add mre tests
Browse files Browse the repository at this point in the history
  • Loading branch information
apiad committed Jan 27, 2018
1 parent 74d7670 commit a0ff498
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = tests.py
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# jsonapi [![Travis](https://img.shields.io/travis/apiad/jsonapi.svg?style=flat-square)](https://travis-ci.org/apiad/jsonapi) [![Coveralls github](https://img.shields.io/coveralls/github/apiad/jsonapi.svg?style=flat-square)](https://coveralls.io/github/apiad/jsonapi?branch=master) [![Codacy grade](https://img.shields.io/codacy/grade/6cfc0cf3ee4b442bae0c43bf54a27a58.svg?style=flat-square)]() [![GitHub tag](https://img.shields.io/github/tag/apiad/jsonapi.svg?style=flat-square&label=current%20version)](https://github.com/apiad/jsonapi/releases) ![Python versions](https://img.shields.io/badge/Python-3.4%2C%203.5%2C%203.6-blue.svg?style=flat-square)
# jsonapi [![Travis](https://img.shields.io/travis/apiad/jsonapi.svg?style=flat-square)](https://travis-ci.org/apiad/jsonapi) [![Coveralls github](https://img.shields.io/coveralls/github/apiad/jsonapi.svg?style=flat-square)](https://coveralls.io/github/apiad/jsonapi?branch=master) ![Codacy grade](https://img.shields.io/codacy/grade/6cfc0cf3ee4b442bae0c43bf54a27a58.svg?style=flat-square) [![GitHub tag](https://img.shields.io/github/tag/apiad/jsonapi.svg?style=flat-square&label=current%20version)](https://github.com/apiad/jsonapi/releases) ![Python versions](https://img.shields.io/badge/Python-3.4%2C%203.5%2C%203.6-blue.svg?style=flat-square)

> A minimalistic JSON API framework in Python with support for **graphql**-style queries.
Expand Down
3 changes: 3 additions & 0 deletions jsonapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def _parse(self, x):
def from_json(s):
return JsonObj(**json.loads(s))

def __repr__(self):
return "JsonObj(**%s)" % str(self.dict())


class JsonApi(JsonObj):
def _query(self, obj, query):
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[pytest]
python_files=tests.py
addopts = --doctest-modules --doctest-glob="*.md" --cov . --cov-report html --cov-report term-missing
26 changes: 26 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import json
from jsonapi import JsonApi, JsonObj


def test_api_input_string():
class TestApi(JsonApi):
def something(self, a, b):
return a.x + b.y

api = TestApi()
query = {
'something': {
'$a': {'x': 10},
'$b': {'y': 20},
}
}

expected_response = {
'something': 30
}

query_str = json.dumps(query)

assert api(query) == expected_response
assert api(query) == api(query_str)
assert json.dumps(api(query), sort_keys=True) == api(query, encode=True, sort_keys=True)

0 comments on commit a0ff498

Please sign in to comment.