Ejemplo n.º 1
0
async def get_deployment_by_id(deployment_id: UUID) -> Deployment:
    db_session = db_session_var.get()
    loop = asyncio.get_running_loop()
    query = db_session.query(deployment_table).filter(
        deployment_table.c.id == deployment_id)
    return [
        Deployment.from_sql_result(row)
        for row in await loop.run_in_executor(None, query.all)
    ][0]
def test_add_deployment_to_db(db_uri, db_session, migrated_db):
    runner = CliRunner()
    deployment_id = uuid.UUID("76587cdd42dc489ea1d220e9b0bc62ca")
    with mock.patch(
            "apd.aggregation.collect.get_deployment_id") as get_deployment_id:
        get_deployment_id.return_value = deployment_id
        runner.invoke(
            apd.aggregation.cli.deployments,
            [
                "add", "http://otherhost", "Other", "--db", db_uri,
                "--api-key", "key"
            ],
        )
    deployments = db_session.query(deployment_table).all()
    assert len(deployments) == 1
    deployment = Deployment.from_sql_result(deployments[0])
    assert deployment.uri == "http://otherhost"
    assert deployment.api_key == "key"
    assert deployment.id == deployment_id