Beispiel #1
0
def test_dbt_cloud_run_job_create_task_without_cause():
    dbt_run_job_task = DbtCloudRunJob(account_id=1234, token="xyz", job_id=1234)

    assert dbt_run_job_task.account_id == 1234
    assert dbt_run_job_task.token == "xyz"
    assert dbt_run_job_task.job_id == 1234
    assert dbt_run_job_task.cause is None
Beispiel #2
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",
        ],
    }
Beispiel #3
0
def test_dbt_cloud_run_job_create_task_from_default_env_vars(monkeypatch):
    monkeypatch.setenv("DBT_CLOUD_ACCOUNT_ID", str(1234))
    monkeypatch.setenv("DBT_CLOUD_JOB_ID", str(1234))
    monkeypatch.setenv("DBT_CLOUD_TOKEN", "xyz")
    dbt_run_job_task = DbtCloudRunJob()

    assert dbt_run_job_task.account_id == 1234
    assert dbt_run_job_task.token == "xyz"
    assert dbt_run_job_task.job_id == 1234
    assert dbt_run_job_task.cause is None
Beispiel #4
0
def test_dbt_cloud_run_job_create_task_with_cause():
    dbt_run_job_task = DbtCloudRunJob(
        account_id=1234, token="xyz", job_id=1234, cause="foo"
    )

    assert dbt_run_job_task.account_id == 1234
    assert dbt_run_job_task.token == "xyz"
    assert dbt_run_job_task.job_id == 1234
    assert dbt_run_job_task.cause == "foo"
    assert dbt_run_job_task.domain == "cloud.getdbt.com"
Beispiel #5
0
def test_dbt_cloud_run_job_create_task_from_env_vars(monkeypatch):
    monkeypatch.setenv("ACCOUNT_ID", str(1234))
    monkeypatch.setenv("JOB_ID", str(1234))
    monkeypatch.setenv("TOKEN", "xyz")
    dbt_run_job_task = DbtCloudRunJob(
        account_id_env_var_name="ACCOUNT_ID",
        job_id_env_var_name="JOB_ID",
        token_env_var_name="TOKEN",
    )

    assert dbt_run_job_task.account_id == 1234
    assert dbt_run_job_task.token == "xyz"
    assert dbt_run_job_task.job_id == 1234
    assert dbt_run_job_task.cause is None
Beispiel #6
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",
            ],
        }
Beispiel #7
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()
Beispiel #8
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()
Beispiel #9
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"}
Beispiel #10
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"}
Beispiel #11
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)
Beispiel #12
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)
Beispiel #13
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)