def test_invalid_service_info(): """ Test error classes raised when trying to initialize a service with an invalid schema argument. """ with pytest.raises(jsonschema.exceptions.ValidationError): jsonrpcbase.JSONRPCService(schema='test/test_schema.yaml', info={'x': 1})
def test_invalid_service_schema(): """ Test error classes raised when trying to initialize a service with an invalid schema argument. """ with pytest.raises(exceptions.InvalidFileType): jsonrpcbase.JSONRPCService(schema='test/xyz.txt', info=_SERVICE_INFO_PATH)
def test_override_discover_method(): """Test the error case where the user tries to override rpc.discover.""" schema = { "$schema": "http://json-schema.org/draft-07/schema#", "definitions": { "methods": { "rpc.discover": { "params": { "type": "null" } } } } } with pytest.raises(exceptions.InvalidSchemaError): jsonrpcbase.JSONRPCService(info=_SERVICE_INFO_PATH, schema=schema)
import jsonrpcbase import re import requests import time from src.es_client import search from src.utils.config import config from src.utils.logger import logger from src.search2_conversion import convert_params, convert_result from src.exceptions import ElasticsearchError service = jsonrpcbase.JSONRPCService( info={ 'title': 'Search API', 'description': 'Search API layer in front of Elasticsearch for KBase', 'version': config['app_version'], }, schema='rpc-schema.yaml', development=config['dev'], ) def show_indexes(params, meta): """List all index names for our prefix""" prefix = config['index_prefix'] resp = requests.get( config['elasticsearch_url'] + '/_cat/indices/' + prefix + '*?format=json', headers={'Content-Type': 'application/json'}, ) if not resp.ok:
""" jsonrpcbase tests """ import jsonrpcbase from nose.tools import assert_equal, assert_not_equal import six s = jsonrpcbase.JSONRPCService() def subtract(a, b): return a - b def kwargs_subtract(**kwargs): return kwargs['a'] - kwargs['b'] def square(a): return a * a def hello(): return "Hello world!" class Hello(object): def msg(self): return "Hello world!"
def test_empty_schema(): """Test initialization of service with no schema""" s = jsonrpcbase.JSONRPCService(info=_SERVICE_INFO_PATH) assert s.schema['$schema'] == "http://json-schema.org/draft-07/schema#" assert s.schema['definitions'] == {"methods": {"rpc.discover": {}}}
def test_invalid_service_info_path(): """Test valid load of service info""" with pytest.raises(exceptions.InvalidFileType): jsonrpcbase.JSONRPCService(schema='test/test_schema.yaml', info='xyz.txt')
""" jsonrpcbase tests """ import json import jsonrpcbase import jsonschema import pytest import yaml import jsonrpcbase.exceptions as exceptions _SCHEMA_PATH = 'test/test_schema.yaml' _SERVICE_INFO_PATH = 'test/service.json' s = jsonrpcbase.JSONRPCService(info=_SERVICE_INFO_PATH, schema=_SCHEMA_PATH, development=True) def subtract(params, meta): return params[0] - params[1] def kwargs_subtract(params, meta): return params['a'] - params['b'] def square(params, meta): return params[0] * params[0] def hello(params, meta):