Example #1
0
def test_published_script():
    here = dirname(__file__)
    fn = join(here, 'cheese_shop_publish.py')
    script = ScriptHandler(fn)
    script.parse()
    funcs = script.tranquilized_functions
    assert len(funcs) == 1
Example #2
0
def tranquilized_funcs():
    here = dirname(__file__)
    fn = join(here, 'cheese_shop.py')
    script = ScriptHandler(fn)
    script.parse()
    funcs = script.tranquilized_functions

    return funcs
Example #3
0
def protected_funcs():
    here = dirname(__file__)
    fn = join(here, 'protected.py')
    script = ScriptHandler(fn)
    script.parse()
    funcs = script.tranquilized_functions

    return funcs
Example #4
0
def error_funcs():
    here = dirname(__file__)
    fn = join(here, 'integer_error.py')
    script = ScriptHandler(fn)
    script.parse()
    funcs = script.tranquilized_functions

    return funcs
Example #5
0
def test_projected_func_without_secret_key():
    here = dirname(__file__)
    fn = join(here, 'protected.py')
    script = ScriptHandler(fn)
    script.parse()
    tranquilized_funcs = script.tranquilized_functions

    with pytest.raises(RuntimeError):
        app = make_app(tranquilized_funcs, 'cheese')
Example #6
0
def test_app_function():
    here = dirname(__file__)
    fn = join(here, 'cheese_shop.py')
    script = ScriptHandler(fn)
    script.parse()
    funcs = script.tranquilized_functions

    app = make_app(funcs, 'cheese')
    assert len(app.blueprints) == 1
Example #7
0
def test_content_length():
    here = dirname(__file__)
    fn = join(here, 'cheese_shop.py')
    script = ScriptHandler(fn)
    script.parse()
    funcs = script.tranquilized_functions

    app = make_app(funcs, 'cheese', max_content_length=1024)
    assert app.config['MAX_CONTENT_LENGTH'] == 1024
Example #8
0
def test_proxy_fix():
    here = dirname(__file__)
    fn = join(here, 'cheese_shop.py')
    script = ScriptHandler(fn)
    script.parse()
    funcs = script.tranquilized_functions

    app = make_app(funcs, 'cheese')
    assert isinstance(app.wsgi_app, ProxyFix)
Example #9
0
def test_projected_func_with_secret_key():
    here = dirname(__file__)
    fn = join(here, 'protected.py')
    script = ScriptHandler(fn)
    script.parse()
    tranquilized_funcs = script.tranquilized_functions

    secret_key = 'tranquilizer'
    app = make_app(tranquilized_funcs, 'cheese', secret_key=secret_key)
    assert app.config['JWT_SECRET_KEY'] == secret_key
Example #10
0
def test_make_resource_docs():
    here = dirname(__file__)
    fn = join(here, 'integer_error.py')
    script = ScriptHandler(fn)
    funcs = script.tranquilized_functions
    ns = Namespace('/', description='Testing Tranquilized API')
    resource = make_resource(funcs[0], ns)
    assert resource.get.__doc__ == 'Make an integer\n\n    '
    assert resource.get.__apidoc__['responses'] == {500: 'ValueError:not an integer'}
Example #11
0
def test_make_resource_method():
    here = dirname(__file__)
    fn = join(here, 'cheese_shop.py')
    script = ScriptHandler(fn)
    funcs = script.tranquilized_functions
    ns = Namespace('/', description='Testing Tranquilized API')
    resource = make_resource(funcs[0], ns)
    assert issubclass(resource, Resource)
    assert hasattr(resource, 'get')
Example #12
0
def build_tranquilize_application(files):
    from tranquilizer.handler import ScriptHandler, NotebookHandler
    from tranquilizer.main import make_app, UnsupportedFileType

    functions = []
    for filename in files:
        extension = filename.split('.')[-1]
        if extension == 'py':
            source = ScriptHandler(filename)
        elif extension == 'ipynb':
            try:
                import nbconvert # noqa
            except ImportError as e: # pragma no cover
                raise ImportError("Please install nbconvert to serve Jupyter Notebooks.") from e

            source = NotebookHandler(filename)
        else:
            raise UnsupportedFileType('{} is not a script (.py) or notebook (.ipynb)'.format(filename))
        functions.extend(source.tranquilized_functions)
    return make_app(functions, 'Panel REST API', prefix='rest/')
Example #13
0
def test_script_handler():
    here = dirname(__file__)
    fn = join(here, 'cheese_shop.py')
    script = ScriptHandler(fn)
    assert script.fn == fn
Example #14
0
def test_script_parser():
    here = dirname(__file__)
    fn = join(here, 'cheese_shop.py')
    script = ScriptHandler(fn)
    script.parse()
    assert [hasattr(script, attr) for attr in ['modules', 'nodes']]