Exemple #1
0
 def __init__(self, app=None, root_path=None):
     super(_TestClient, self).__init__()
     if app is None:
         app = get_current_app()
     adapter = WSGIAdapter(app.wsgi, root_path=root_path)
     self.mount('http://', adapter)
     self.mount('https://', adapter)
     self.headers.update({'User-Agent': 'requests_client'})
Exemple #2
0
def run():
    from apistar.main import get_current_app
    app = get_current_app()

    try:
        click.echo('Running at http://localhost:8080/')
        make_server('', 8080, app.wsgi).serve_forever()
    except KeyboardInterrupt:
        pass
Exemple #3
0
def run(host, port):
    from apistar.main import get_current_app
    app = get_current_app()

    try:
        click.echo('Running at http://{host}:{port}/'.format(host=host,
                                                             port=port))
        make_server(host, port, app.wsgi).serve_forever()
    except KeyboardInterrupt:
        pass
Exemple #4
0
    def __init__(self, app=None, root_path=None, raise_500_exc=True, hostname='testserver'):
        super(_TestClient, self).__init__()
        if app is None:
            app = get_current_app()

        adapter = WSGIAdapter(app.wsgi, root_path=root_path, raise_500_exc=raise_500_exc)
        self.mount('http://', adapter)
        self.mount('https://', adapter)
        self.headers.update({'User-Agent': 'requests_client'})
        self.hostname = hostname
Exemple #5
0
def create_tables() -> None:
    """
    Create SQLAlchemy tables.
    """
    from apistar.main import get_current_app
    from apistar.backends.sqlalchemy import SQLAlchemy
    app = get_current_app()
    db_backend = SQLAlchemy.build(settings=app.settings)
    db_backend.create_tables()
    click.echo("Tables created")
Exemple #6
0
def create_tables():
    """
    Create SQLAlchemy tables.
    """
    from apistar.main import get_current_app
    from apistar.backends import DjangoBackend
    app = get_current_app()
    db_backend = DjangoBackend.build(settings=app.settings)
    db_backend.create_tables()
    click.echo("Tables created")
Exemple #7
0
def schema(format: Format) -> None:  # pragma: nocover
    """
    Output an API Schema.
    """
    from apistar.main import get_current_app
    from apistar.apischema import APISchema
    app = get_current_app()
    schema = APISchema.build(app)
    codec = codecs[format]
    output = codec.encode(schema)
    click.echo(output)
Exemple #8
0
def run(host, port):  # pragma: nocover
    from apistar.main import get_current_app
    app = get_current_app()

    try:
        if not is_running_from_reloader():
            click.echo('Starting up...')
        run_simple(host,
                   port,
                   app.wsgi,
                   use_reloader=True,
                   use_debugger=True,
                   extra_files=['app.py'])
    except KeyboardInterrupt:
        pass
Exemple #9
0
def test(file_or_dir):
    from apistar.main import get_current_app
    app = get_current_app()

    if not file_or_dir:
        file_or_dir = []
        if os.path.exists('tests'):
            file_or_dir.append('tests')
        if os.path.exists('tests.py'):
            file_or_dir.append('tests.py')
        if not file_or_dir:
            raise ConfigurationError(
                "No 'tests/' directory or 'tests.py' module.")

    exitcode = pytest.main(list(file_or_dir))
    if exitcode:
        sys.exit(exitcode)
Exemple #10
0
    def __init__(self, wsgi_or_app=None, root_path=None, raise_500_exc=True):
        super(_TestClient, self).__init__()
        if wsgi_or_app is None:
            wsgi_or_app = get_current_app()

        if hasattr(wsgi_or_app, 'wsgi'):
            # Passed an `App` instance.
            wsgi = wsgi_or_app.wsgi
        else:
            # Passed a WSGI callable.
            wsgi = wsgi_or_app

        adapter = WSGIAdapter(wsgi,
                              root_path=root_path,
                              raise_500_exc=raise_500_exc)
        self.mount('http://', adapter)
        self.mount('https://', adapter)
        self.headers.update({'User-Agent': 'requests_client'})