コード例 #1
0
def test_it():
    app = make_app()
    client = test.TestClient(app)
    response = client.get("/")

    assert response.status_code == 200
    assert response.json() == {"message": "Welcome to API Star!"}
コード例 #2
0
def client(request):
    if request.param == "asgi":
        app = ASyncApp(routes=routes)
    elif request.param == "wsgi":
        app = App(routes=routes)
    else:
        app = CORSApp(routes=routes)
    return test.TestClient(app)
コード例 #3
0
def test_on_error_loads_the_same_component_instances():
    # Given that I have an app that uses an AComponent and the AEventHooks
    app = App(
        components=[AComponent()],
        event_hooks=[AEventHooks],
        routes=[Route('/uses-a', method='GET', handler=uses_a)],
    )

    # When I call an endpoint that raises an error
    with pytest.raises(RuntimeError):
        test.TestClient(app).get('/uses-a')

    # Then all the instances of A are the same
    assert len(A_INSTANCES) >= 2
    for i in range(1, len(A_INSTANCES)):
        assert A_INSTANCES[i] is A_INSTANCES[i - 1]
コード例 #4
0
ファイル: test_todo.py プロジェクト: mbohal/sandbox_apistar
from apistar import test
from app import APP

CLIENT = test.TestClient(APP)


def test_todo_item_get():
    response = CLIENT.get('/todos/1')
    assert response.status_code == 200
    assert response.json() == {'id': 1, 'task': 'Buy milk'}


def test_todo_item_put():
    response = CLIENT.put('/todos/100', {'task': 'Buy butter'})
    assert response.status_code == 200
    assert response.json() == {'id': 100, 'task': 'Buy butter'}


def test_todo_item_delete():
    response = CLIENT.delete('/todos/23')
    assert response.status_code == 204


def test_todo_collection_post():
    response = CLIENT.post('/todos/',
                           json={
                               'id': 2,
                               'task': 'Buy apples'
                           },
                           allow_redirects=False)
    assert response.status_code == 201
コード例 #5
0
    session.close()
    return created_kitten


app = App(routes=[
    routing.Route('/kittens/create/', 'GET', create_kitten),
    routing.Route('/kittens/', 'GET', list_kittens),
],
          settings={
              "DATABASE": {
                  "URL": environ.get('DB_URL', 'sqlite:///test.db'),
                  "METADATA": Base.metadata
              }
          })

client = test.TestClient(app)
runner = CommandLineRunner(app)


@pytest.fixture
def clear_db(scope="function"):
    yield
    db_backend = SQLAlchemy.build(app.settings)
    db_backend.drop_tables()


def test_list_create(monkeypatch, clear_db):
    def mock_get_current_app():
        return app

    monkeypatch.setattr(apistar.cli, 'get_current_app', mock_get_current_app)
コード例 #6
0
ファイル: test_http.py プロジェクト: dingmaotu/apistar-server
def client(request):
    if request.param == 'asgi':
        app = ASyncApp(routes=routes)
    else:
        app = App(routes=routes)
    return test.TestClient(app)
コード例 #7
0
ファイル: conftest.py プロジェクト: jgirardet/mapistar
def cli_app_no_auth(napp):
    """apistar test client"""

    return test.TestClient(main_app)
コード例 #8
0
ファイル: conftest.py プロジェクト: jgirardet/mapistar
def cli_anonymous(napp):
    """apistar test client"""

    return test.TestClient(main_app)
コード例 #9
0
ファイル: tests.py プロジェクト: wajika/ceryx
import unittest

from apistar import test

from app import app


CLIENT = test.TestClient(app)


class CeryxTestCase(unittest.TestCase):
    def setUp(self):
        self.client = CLIENT

    def test_list_routes(self):
        """
        Assert that listing routes will return a JSON list.
        """
        response = self.client.get('/api/routes')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(type(response.json()), list)

    def test_create_route(self):
        """
        Assert that creating a route, will result in the appropriate route.
        """
        route_data = {
            'source': 'test.dev',
            'target': 'localhost:11235',
        }
        expected_response = {
コード例 #10
0
def client(redis_client):
    client = test.TestClient(app)
    yield client
コード例 #11
0
def client():
    return test.TestClient(app)
コード例 #12
0
def client():
    client = test.TestClient(app)
    yield client
    local.local_memory_sessions = {}