示例#1
0
文件: conftest.py 项目: chessdb/api
def client(app):
    """client.

    Args:
        app:
    """
    cwd = pathlib.Path(__file__).parent.parent
    subprocess.check_call(["alembic", "upgrade", "head"], cwd=cwd)
    with testclient.TestClient(app, "http://localhost:12001") as test_client:
        yield test_client
def get_client():
    app = FastAPI()
    oauth2_scheme = OAuth2PasswordBearer(tokenUrl="auth/token")

    def token_auth(token: str = Depends(oauth2_scheme)):
        if not token:
            raise HTTPException(401, "Invalid token")

    router = MemoryCRUDRouter(schema=Potato,
                              dependencies=[Depends(token_auth)])
    app.include_router(router)

    return testclient.TestClient(app)
示例#3
0
def client(app):
    """client.

    Args:
        app:
    """
    cwd = pathlib.Path(__file__).parent.parent
    try:
        subprocess.check_call(["alembic", "upgrade", "head"], cwd=cwd)
    except subprocess.CalledProcessError:
        sys.exit(1)
    with testclient.TestClient(app) as test_client:
        yield test_client
示例#4
0
import ast
import unittest

import fastapi.testclient as tc

from app.main import app

# sys.path.append(os.path.join("..", ".."))

client = tc.TestClient(app)


class AsyncScoringApiTest(unittest.TestCase):
    def test_healthcheck_api(self):
        expected_resp = "OK"
        resp = client.get("/api/v1/healthcheck")

        self.assertEqual(resp.status_code, 200)

        resp_text = ast.literal_eval(resp.text)
        resp_text = resp_text.get("status")
        self.assertEqual(resp_text, expected_resp)
示例#5
0
def get_client(**kwargs):
    app = FastAPI()
    app.include_router(MemoryCRUDRouter(schema=Potato, prefix=URL, **kwargs))

    return testclient.TestClient(app)
示例#6
0
def api_client():
    return testclient.TestClient(api.app)
示例#7
0
def app():
    with testclient.TestClient(main.create_app()) as client:
        yield client