Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlov99 committed Oct 28, 2017
2 parents 105c554 + 334d30e commit 6e92dfe
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 71 deletions.
33 changes: 16 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
language: python
# Use containers instead of full VMs for faster startup.
sudo: false

python: "2.7"

env:
- TOXENV=py26
- TOXENV=py27
- TOXENV=py33
- TOXENV=py34
- TOXENV=pypy
- TOXENV=cov
language: python
python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "pypy"
- "pypy3"

branches:
only:
Expand All @@ -18,10 +19,8 @@ branches:

install: pip install --quiet tox

script: tox

after_script:
- if [ $TOXENV == "cov" ]; then
pip install --quiet coveralls;
coveralls;
fi
script:
# Remove version separator from python version and use it as a key for tox.
# Note: prefix it with 'py' for numbered python vestion.
- if [[ $TRAVIS_PYTHON_VERSION == 2* || $TRAVIS_PYTHON_VERSION == 3* ]]; then tox -e $(echo $TRAVIS_PYTHON_VERSION | sed 's/\.//g;s/^/py/'); fi
- if [[ $TRAVIS_PYTHON_VERSION == 'pypy'* ]]; then tox -e $TRAVIS_PYTHON_VERSION; fi
6 changes: 3 additions & 3 deletions jsonrpc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from .manager import JSONRPCResponseManager
from .dispatcher import Dispatcher

__version = (1, 10, 3)

__version__ = version = '.'.join(map(str, __version))
__project__ = PROJECT = __name__

from .manager import JSONRPCResponseManager
from .dispatcher import Dispatcher

dispatcher = Dispatcher()

# lint_ignore=W0611,W0401
5 changes: 5 additions & 0 deletions jsonrpc/manager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys
import traceback
import json
import logging
from .utils import is_invalid_params
Expand Down Expand Up @@ -113,6 +115,9 @@ def response(**kwargs):
"type": e.__class__.__name__,
"args": e.args,
"message": str(e),
"traceback": ''.join(
traceback.format_exception(*sys.exc_info())
),
}

logger.exception("API Exception: {0}".format(data))
Expand Down
1 change: 1 addition & 0 deletions jsonrpc/tests/test_backend_django/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class TestDjangoBackend(TestCase):
def setUpClass(cls):
os.environ['DJANGO_SETTINGS_MODULE'] = \
'jsonrpc.tests.test_backend_django.settings'
super(TestDjangoBackend, cls).setUpClass()

def test_urls(self):
self.assertTrue(isinstance(api.urls, list))
Expand Down
7 changes: 3 additions & 4 deletions jsonrpc/tests/test_backend_django/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.conf.urls import patterns, url, include
from django.conf.urls import url, include
from jsonrpc.backend.django import api

urlpatterns = patterns(
'',
urlpatterns = [
url(r'', include(api.urls)),
url(r'prefix', include(api.urls)),
)
]
6 changes: 5 additions & 1 deletion jsonrpc/tests/test_backend_flask/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import json
import sys
from mock import patch

if sys.version_info < (3, 3):
from mock import patch
else:
from unittest.mock import patch

if sys.version_info < (2, 7):
import unittest2 as unittest
Expand Down
5 changes: 3 additions & 2 deletions jsonrpc/tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
""" Test base JSON-RPC classes."""
import sys

from ..base import JSONRPCBaseRequest, JSONRPCBaseResponse

if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest

from ..base import JSONRPCBaseRequest, JSONRPCBaseResponse


class TestJSONRPCBaseRequest(unittest.TestCase):

Expand Down
7 changes: 4 additions & 3 deletions jsonrpc/tests/test_bug29.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"""
import sys
import json

from ..manager import JSONRPCResponseManager

if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest
import json
from ..manager import JSONRPCResponseManager


def isjsonequal(json1, json2):
Expand All @@ -30,4 +32,3 @@ def test_none_as_result(self):
response.json,
'{"jsonrpc": "2.0", "result": null, "id": 0}'
))

5 changes: 4 additions & 1 deletion jsonrpc/tests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ def test_del_method(self):

def test_to_dict(self):
d = Dispatcher()
func = lambda: ""

def func():
return ""

d["method"] = func
self.assertEqual(dict(d), {"method": func})

Expand Down
6 changes: 4 additions & 2 deletions jsonrpc/tests/test_examples20.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"""
import sys
import json

from ..manager import JSONRPCResponseManager

if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest
import json
from ..manager import JSONRPCResponseManager


def isjsonequal(json1, json2):
Expand Down
10 changes: 5 additions & 5 deletions jsonrpc/tests/test_jsonrpc1.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import json

import sys
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest

from ..exceptions import JSONRPCInvalidRequestException
from ..jsonrpc1 import (
JSONRPC10Request,
JSONRPC10Response,
)

if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest


class TestJSONRPC10Request(unittest.TestCase):

Expand Down
9 changes: 5 additions & 4 deletions jsonrpc/tests/test_jsonrpc2.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import json
import sys
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest

from ..exceptions import JSONRPCInvalidRequestException
from ..jsonrpc2 import (
Expand All @@ -13,6 +9,11 @@
JSONRPC20BatchResponse,
)

if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest


class TestJSONRPC20Request(unittest.TestCase):

Expand Down
9 changes: 5 additions & 4 deletions jsonrpc/tests/test_jsonrpc_errors.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import json
import sys
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest

from ..exceptions import (
JSONRPCError,
Expand All @@ -16,6 +12,11 @@
JSONRPCDispatchException,
)

if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest


class TestJSONRPCError(unittest.TestCase):
def setUp(self):
Expand Down
42 changes: 27 additions & 15 deletions jsonrpc/tests/test_manager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import os
import sys
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest
from mock import MagicMock

from ..manager import JSONRPCResponseManager
from ..jsonrpc2 import (
Expand All @@ -15,6 +11,16 @@
from ..jsonrpc1 import JSONRPC10Request, JSONRPC10Response
from ..exceptions import JSONRPCDispatchException

if sys.version_info < (3, 3):
from mock import MagicMock
else:
from unittest.mock import MagicMock

if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest


class TestJSONRPCResponseManager(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -122,11 +128,14 @@ def test_server_error(self):
self.assertTrue(isinstance(response, JSONRPC20Response))
self.assertEqual(response.error["message"], "Server error")
self.assertEqual(response.error["code"], -32000)
self.assertEqual(response.error["data"], {
"type": "KeyError",
"args": ('error_explanation',),
"message": "'error_explanation'",
})
self.assertEqual(response.error["data"]['type'], "KeyError")
self.assertEqual(
response.error["data"]['args'], ('error_explanation',))
self.assertEqual(
response.error["data"]['message'], "'error_explanation'")
self.assertIn('traceback', response.error["data"])
self.assertIn(
os.path.basename(__file__), response.error["data"]['traceback'])

def test_notification_calls_method(self):
request = JSONRPC20Request("long_time_method", is_notification=True)
Expand Down Expand Up @@ -155,11 +164,14 @@ def test_type_error_inside_method(self):
self.assertTrue(isinstance(response, JSONRPC20Response))
self.assertEqual(response.error["message"], "Server error")
self.assertEqual(response.error["code"], -32000)
self.assertEqual(response.error["data"], {
"type": "TypeError",
"args": ('TypeError inside method',),
"message": 'TypeError inside method',
})
self.assertEqual(response.error["data"]['type'], "TypeError")
self.assertEqual(
response.error["data"]['args'], ('TypeError inside method',))
self.assertEqual(
response.error["data"]['message'], 'TypeError inside method')
self.assertIn('traceback', response.error["data"])
self.assertIn(
os.path.basename(__file__), response.error["data"]['traceback'])

def test_invalid_params_before_dispatcher_error(self):
request = JSONRPC20Request(
Expand Down
12 changes: 8 additions & 4 deletions jsonrpc/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
""" Test utility functionality."""
from ..utils import JSONSerializable, DatetimeDecimalEncoder, is_invalid_params

import datetime
import decimal
import json
import sys

if sys.version_info < (3, 3):
from mock import patch
else:
from unittest.mock import patch

if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest

from mock import patch

from ..utils import JSONSerializable, DatetimeDecimalEncoder, is_invalid_params


class TestJSONSerializable(unittest.TestCase):

Expand Down
Loading

0 comments on commit 6e92dfe

Please sign in to comment.