def get_framework_for_reuse(
    supplier_id: int,
    client: DataAPIClient,
    exclude_framework_slugs: Optional[Container[str]] = None,
) -> Optional[dict]:
    """Given a list of declarations find the most suitable for reuse.

     :param supplier_id: supplier whose declarations we are inspecting
     :param client: data client
     :param exclude_framework_slugs: list of framework slugs to exclude from results
     :return: framework
    """
    declarations = {
        sf['frameworkSlug']: sf
        for sf in client.find_supplier_declarations(supplier_id)
        ['frameworkInterest']
        if sf['onFramework'] and sf.get('allowDeclarationReuse') is not False
    }
    return next(
        (framework for framework in order_frameworks_for_reuse(
            client.find_frameworks()['frameworks'])
         if framework['slug'] in declarations and framework['slug'] not in (
             exclude_framework_slugs or ())), None)
예제 #2
0

if __name__ == "__main__":
    args = docopt(__doc__)
    logging.basicConfig(level=logging.INFO)

    FT_JOB_NAMES = ["functional-tests-preview", "functional-tests-staging"]
    API_USER = os.getenv("DM_JENKINS_API_USER")
    API_TOKEN = os.getenv("DM_JENKINS_API_TOKEN")

    OUTPUT_FILE = args.get("<file>") or "functional_test_report.csv"

    auth = HTTPBasicAuth(API_USER, API_TOKEN)

    # Use staging to get the framework dates because it'll be the same as production
    api_client = DataAPIClient(get_api_endpoint_from_stage("staging"),
                               get_auth_token("api", "staging"))
    frameworks = api_client.find_frameworks()["frameworks"]

    build_data = []
    for job in FT_JOB_NAMES:
        for build in get_job_build_data(job, auth):
            build_data.append(format_build(job, build, frameworks))

    logging.info(f"Writing report to {OUTPUT_FILE}")
    headers = build_data[0].keys()
    with open(OUTPUT_FILE, "w") as f:
        writer = csv.DictWriter(f, headers)
        writer.writeheader()
        writer.writerows(build_data)