Exemplo n.º 1
0
def test_dbt_cloud_run_job_raises_failure():
    account_id = 1234
    job_id = 1234

    responses.add(
        responses.POST,
        f"https://cloud.getdbt.com/api/v2/accounts/{account_id}/jobs/{job_id}/run/",
        status=123,
    )

    run_job = DbtCloudRunJob(cause="foo",
                             account_id=account_id,
                             job_id=job_id,
                             token="foo")
    with pytest.raises(TriggerDbtCloudRunFailed):
        run_job.run()
Exemplo n.º 2
0
def test_dbt_cloud_run_job_raises_failure():
    account_id = 1234
    job_id = 1234

    with responses.RequestsMock() as rsps:
        rsps.add(
            responses.POST,
            f"https://cloud.getdbt.com/api/v2/accounts/{account_id}/jobs/{job_id}/run/",
            status=123,
            match=[matchers.header_matcher(USER_AGENT_HEADER)],
        )

        run_job = DbtCloudRunJob(
            cause="foo", account_id=account_id, job_id=job_id, token="foo"
        )
        with pytest.raises(TriggerDbtCloudRunFailed):
            run_job.run()
Exemplo n.º 3
0
def test_dbt_cloud_run_job_trigger_job_with_wait_custom():
    account_id = 1234
    job_id = 1234

    responses.add(
        responses.POST,
        f"https://cloud.corp.getdbt.com/api/v2/accounts/{account_id}/jobs/{job_id}/run/",
        status=200,
        json={"data": {
            "id": 1
        }},
    )

    responses.add(
        responses.GET,
        f"https://cloud.corp.getdbt.com/api/v2/accounts/{account_id}/runs/1/",
        status=200,
        json={
            "data": {
                "id": 1,
                "status": 10,
                "finished_at": "2019-08-24T14:15:22Z"
            }
        },
    )

    responses.add(
        responses.GET,
        f"https://cloud.corp.getdbt.com/api/v2/accounts/{account_id}/runs/1/artifacts/",
        status=200,
        json={"data": ["manifest.json", "run_results.json", "catalog.json"]},
    )

    run_job = DbtCloudRunJob(
        cause="foo",
        account_id=account_id,
        job_id=job_id,
        token="foo",
        wait_for_job_run_completion=True,
        domain="cloud.corp.getdbt.com",
    )
    r = run_job.run()

    assert r == {
        "id":
        1,
        "status":
        10,
        "finished_at":
        "2019-08-24T14:15:22Z",
        "artifact_urls": [
            f"https://cloud.corp.getdbt.com/api/v2/accounts/{account_id}/runs/1/artifacts/manifest.json",
            f"https://cloud.corp.getdbt.com/api/v2/accounts/{account_id}/runs/1/artifacts/run_results.json",
            f"https://cloud.corp.getdbt.com/api/v2/accounts/{account_id}/runs/1/artifacts/catalog.json",
        ],
    }
Exemplo n.º 4
0
def test_dbt_cloud_run_job_trigger_job_with_wait():
    account_id = 1234
    job_id = 1234
    with responses.RequestsMock() as rsps:
        rsps.add(
            responses.POST,
            f"https://cloud.getdbt.com/api/v2/accounts/{account_id}/jobs/{job_id}/run/",
            status=200,
            json={"data": {"id": 1}},
            match=[matchers.header_matcher(USER_AGENT_HEADER)],
        )

        rsps.add(
            responses.GET,
            f"https://cloud.getdbt.com/api/v2/accounts/{account_id}/runs/1/",
            status=200,
            json={
                "data": {"id": 1, "status": 10, "finished_at": "2019-08-24T14:15:22Z"}
            },
            match=[matchers.header_matcher(USER_AGENT_HEADER)],
        )

        rsps.add(
            responses.GET,
            f"https://cloud.getdbt.com/api/v2/accounts/{account_id}/runs/1/artifacts/",
            status=200,
            json={"data": ["manifest.json", "run_results.json", "catalog.json"]},
            match=[matchers.header_matcher(USER_AGENT_HEADER)],
        )

        run_job = DbtCloudRunJob(
            cause="foo",
            account_id=account_id,
            job_id=job_id,
            token="foo",
            wait_for_job_run_completion=True,
        )
        r = run_job.run()

        assert r == {
            "id": 1,
            "status": 10,
            "finished_at": "2019-08-24T14:15:22Z",
            "artifact_urls": [
                f"https://cloud.getdbt.com/api/v2/accounts/{account_id}/runs/1/artifacts/manifest.json",
                f"https://cloud.getdbt.com/api/v2/accounts/{account_id}/runs/1/artifacts/run_results.json",
                f"https://cloud.getdbt.com/api/v2/accounts/{account_id}/runs/1/artifacts/catalog.json",
            ],
        }
Exemplo n.º 5
0
def test_dbt_cloud_run_job_trigger_job():
    account_id = 1234
    job_id = 1234
    with responses.RequestsMock() as rsps:
        rsps.add(
            responses.POST,
            f"https://cloud.getdbt.com/api/v2/accounts/{account_id}/jobs/{job_id}/run/",
            status=200,
            json={"data": {"foo": "bar"}},
            match=[matchers.header_matcher(USER_AGENT_HEADER)],
        )

        run_job = DbtCloudRunJob(
            cause="foo", account_id=account_id, job_id=job_id, token="foo"
        )
        r = run_job.run()

        assert r == {"foo": "bar"}
Exemplo n.º 6
0
def test_dbt_cloud_run_job_trigger_job():
    account_id = 1234
    job_id = 1234

    responses.add(
        responses.POST,
        f"https://cloud.getdbt.com/api/v2/accounts/{account_id}/jobs/{job_id}/run/",
        status=200,
        json={"data": {
            "foo": "bar"
        }},
    )

    run_job = DbtCloudRunJob(cause="foo",
                             account_id=account_id,
                             job_id=job_id,
                             token="foo")
    r = run_job.run()

    assert r == {"foo": "bar"}
Exemplo n.º 7
0
def test_dbt_cloud_run_job_raises_value_error_with_missing_token():
    run_job = DbtCloudRunJob()
    with pytest.raises(ValueError) as exc:
        run_job.run(cause="foo", account_id=1234, job_id=1234)
    assert "token cannot be None." in str(exc)
Exemplo n.º 8
0
def test_dbt_cloud_run_job_raises_value_error_with_missing_account_id():
    run_job = DbtCloudRunJob()
    with pytest.raises(ValueError) as exc:
        run_job.run(cause="foo")
    assert "dbt Cloud Account ID cannot be None." in str(exc)
Exemplo n.º 9
0
def test_dbt_cloud_run_job_raises_value_error_with_missing_cause():
    run_job = DbtCloudRunJob()
    with pytest.raises(ValueError) as exc:
        run_job.run()
    assert "Cause cannot be None." in str(exc)