-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add unit tests using requests-mock * Add test_mock_job_run unit test * Add test_mock_run_get_status unit test Co-authored-by: Simo Tumelius <[email protected]>
- Loading branch information
1 parent
35c4bc6
commit 3cae73a
Showing
13 changed files
with
276 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .job import DbtCloudJob, DbtCloudRun |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import json | ||
import pytest | ||
from dbt_cloud import DbtCloudJob, DbtCloudRun | ||
|
||
|
||
def load_response(shared_datadir, response_name): | ||
response_file = shared_datadir / f"{response_name}.json" | ||
response_json = response_file.read_text() | ||
return json.loads(response_json) | ||
|
||
|
||
@pytest.fixture | ||
def job_get_response(shared_datadir): | ||
return load_response(shared_datadir, "job_get_response") | ||
|
||
|
||
@pytest.fixture | ||
def job_create_response(shared_datadir): | ||
return load_response(shared_datadir, "job_create_response") | ||
|
||
|
||
@pytest.fixture | ||
def job_run_response(shared_datadir): | ||
return load_response(shared_datadir, "job_run_response") | ||
|
||
|
||
@pytest.fixture | ||
def run_get_response(shared_datadir): | ||
return load_response(shared_datadir, "run_get_response") | ||
|
||
|
||
@pytest.fixture | ||
def project_id(): | ||
return 123457 | ||
|
||
|
||
@pytest.fixture | ||
def environment_id(): | ||
return 49819 | ||
|
||
|
||
@pytest.fixture | ||
def job(): | ||
return DbtCloudJob(api_token="foo", account_id=123456, job_id=43167) | ||
|
||
|
||
@pytest.fixture | ||
def run(job): | ||
return DbtCloudRun(run_id=36053848, **job.dict()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"status": { | ||
"code": 201, | ||
"is_success": true, | ||
"user_message": "Success!", | ||
"developer_message": "" | ||
}, | ||
"data": { | ||
"execution": { | ||
"timeout_seconds": 0 | ||
}, | ||
"generate_docs": false, | ||
"run_generate_sources": false, | ||
"id": 48180, | ||
"account_id": 123456, | ||
"project_id": 123457, | ||
"environment_id": 49819, | ||
"name": "Dummy job", | ||
"dbt_version": null, | ||
"created_at": "2021-12-22T11:23:26.968076+00:00", | ||
"updated_at": "2021-12-22T11:23:26.968094+00:00", | ||
"execute_steps": [ | ||
"dbt seed", | ||
"dbt run" | ||
], | ||
"state": 1, | ||
"deferring_job_definition_id": null, | ||
"lifecycle_webhooks": false, | ||
"lifecycle_webhooks_url": null, | ||
"triggers": { | ||
"github_webhook": false, | ||
"git_provider_webhook": null, | ||
"custom_branch_only": false, | ||
"schedule": false | ||
}, | ||
"settings": { | ||
"threads": 1, | ||
"target_name": "default" | ||
}, | ||
"schedule": { | ||
"cron": "0 * * * *", | ||
"date": { | ||
"type": "every_day" | ||
}, | ||
"time": { | ||
"type": "every_hour", | ||
"interval": 1 | ||
} | ||
}, | ||
"is_deferrable": false, | ||
"generate_sources": false, | ||
"cron_humanized": "Every hour", | ||
"next_run": null, | ||
"next_run_humanized": null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"status": { | ||
"code": 200, | ||
"is_success": true, | ||
"user_message": "Success!", | ||
"developer_message": "" | ||
}, | ||
"data": { | ||
"id": 34929305, | ||
"trigger_id": 35644346, | ||
"account_id": 123456, | ||
"environment_id": 49819, | ||
"project_id": 123457, | ||
"job_definition_id": 43167, | ||
"status": 10, | ||
"dbt_version": "0.21.0", | ||
"git_branch": "main", | ||
"git_sha": "981c5cf1ba299e942c6c277c38c8dec9b0738dd0", | ||
"status_message": null, | ||
"owner_thread_id": null, | ||
"executed_by_thread_id": "dbt-run-34929305-dcmbq", | ||
"deferring_run_id": null, | ||
"artifacts_saved": true, | ||
"artifact_s3_path": "prod/runs/34929305/artifacts/target", | ||
"has_docs_generated": false, | ||
"has_sources_generated": false, | ||
"notifications_sent": true, | ||
"blocked_by": [], | ||
"scribe_enabled": true, | ||
"created_at": "2021-11-26 16:48:41.431645+00:00", | ||
"updated_at": "2021-11-26 16:49:33.078918+00:00", | ||
"dequeued_at": "2021-11-26 16:49:15.670558+00:00", | ||
"started_at": "2021-11-26 16:49:20.535987+00:00", | ||
"finished_at": "2021-11-26 16:49:32.996703+00:00", | ||
"last_checked_at": null, | ||
"last_heartbeat_at": null, | ||
"should_start_at": null, | ||
"trigger": null, | ||
"job": null, | ||
"environment": null, | ||
"run_steps": [], | ||
"status_humanized": "Success", | ||
"in_progress": false, | ||
"is_complete": true, | ||
"is_success": true, | ||
"is_error": false, | ||
"is_cancelled": false, | ||
"href": "REDACTED", | ||
"duration": "00:00:51", | ||
"queued_duration": "00:00:39", | ||
"run_duration": "00:00:12", | ||
"duration_humanized": "51 seconds", | ||
"queued_duration_humanized": "39 seconds", | ||
"run_duration_humanized": "12 seconds", | ||
"created_at_humanized": "1 minute ago", | ||
"finished_at_humanized": "9 seconds ago", | ||
"job_id": 43167 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"status": { | ||
"code": 200, | ||
"is_success": true, | ||
"user_message": "Success!", | ||
"developer_message": "" | ||
}, | ||
"data": { | ||
"id": 36053848, | ||
"trigger_id": 36768889, | ||
"account_id": 123456, | ||
"environment_id": 49819, | ||
"project_id": 123457, | ||
"job_definition_id": 43167, | ||
"status": 10, | ||
"dbt_version": "0.21.0", | ||
"git_branch": "main", | ||
"git_sha": "981c5cf1ba299e942c6c277c38c8dec9b0738dd0", | ||
"status_message": null, | ||
"owner_thread_id": null, | ||
"executed_by_thread_id": "dbt-run-36053848-84vsp", | ||
"deferring_run_id": null, | ||
"artifacts_saved": true, | ||
"artifact_s3_path": "prod/runs/36053848/artifacts/target", | ||
"has_docs_generated": false, | ||
"has_sources_generated": false, | ||
"notifications_sent": true, | ||
"blocked_by": [], | ||
"scribe_enabled": true, | ||
"created_at": "2021-12-07 10:32:24.326116+00:00", | ||
"updated_at": "2021-12-07 10:34:14.507280+00:00", | ||
"dequeued_at": "2021-12-07 10:33:54.599925+00:00", | ||
"started_at": "2021-12-07 10:34:01.982824+00:00", | ||
"finished_at": "2021-12-07 10:34:14.435474+00:00", | ||
"last_checked_at": null, | ||
"last_heartbeat_at": null, | ||
"should_start_at": null, | ||
"trigger": null, | ||
"job": null, | ||
"environment": null, | ||
"run_steps": [], | ||
"status_humanized": "Success", | ||
"in_progress": false, | ||
"is_complete": true, | ||
"is_success": true, | ||
"is_error": false, | ||
"is_cancelled": false, | ||
"href": "REDACTED", | ||
"duration": "00:01:50", | ||
"queued_duration": "00:01:37", | ||
"run_duration": "00:00:12", | ||
"duration_humanized": "1 minute, 50 seconds", | ||
"queued_duration_humanized": "1 minute, 37 seconds", | ||
"run_duration_humanized": "12 seconds", | ||
"created_at_humanized": "2 weeks, 1 day ago", | ||
"finished_at_humanized": "2 weeks, 1 day ago", | ||
"job_id": 43167 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from dbt_cloud.job import DbtCloudJob, DbtCloudJobCreateArgs, DbtCloudJobRunArgs | ||
|
||
|
||
def test_mock_job_get(requests_mock, job, job_get_response): | ||
url = job.get_api_url() + "/" | ||
requests_mock.get(url, json=job_get_response, status_code=200) | ||
response = job.get() | ||
assert response.json() == job_get_response | ||
|
||
|
||
def test_mock_job_create( | ||
requests_mock, job, job_create_response, project_id, environment_id | ||
): | ||
url = job.get_api_url() + "/" | ||
requests_mock.post(url, json=job_create_response, status_code=201) | ||
args = DbtCloudJobCreateArgs( | ||
project_id=project_id, | ||
environment_id=environment_id, | ||
name="Dummy job", | ||
execute_steps=["dbt seed", "dbt run"], | ||
) | ||
response = job.create(args) | ||
assert response.json() == job_create_response | ||
|
||
|
||
def test_mock_job_run(requests_mock, job, job_run_response): | ||
url = job.get_api_url() + "/run/" | ||
requests_mock.post(url, json=job_run_response, status_code=200) | ||
args = DbtCloudJobRunArgs() | ||
response, job_run = job.run(args) | ||
assert response.json() == job_run_response | ||
assert job_run.run_id == job_run_response["data"]["id"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from dbt_cloud.run import DbtCloudRun, DbtCloudRunStatus | ||
|
||
|
||
def test_mock_run_get_status(requests_mock, run, run_get_response): | ||
url = run.get_api_url() + "/" | ||
requests_mock.get(url, json=run_get_response, status_code=200) | ||
response, run_status = run.get_status() | ||
assert response.json() == run_get_response | ||
assert run_status == DbtCloudRunStatus.SUCCESS |