-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from dbt-labs/release-1.0
Preparing for release 1.0.0
- Loading branch information
Showing
12 changed files
with
278 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
repos: | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
# Ruff version. | ||
rev: v0.4.9 | ||
rev: v0.8.2 | ||
hooks: | ||
# Run the linter. | ||
- id: ruff | ||
args: [ --select, I, B, --fix ] | ||
args: [ --select, I, --select, B, --fix ] | ||
# Run the formatter. | ||
- id: ruff-format |
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,45 @@ | ||
from beartype.typing import List, Optional, TextIO | ||
from loguru import logger | ||
|
||
from dbt_jobs_as_code.client import DBTCloud | ||
from dbt_jobs_as_code.loader.load import load_job_configuration | ||
from dbt_jobs_as_code.schemas.job import JobDefinition | ||
|
||
|
||
def get_account_id(config_file: Optional[TextIO], account_id: Optional[int]) -> int: | ||
"""Get account ID from either config file or direct input""" | ||
if account_id: | ||
return account_id | ||
elif config_file: | ||
defined_jobs = load_job_configuration(config_file, None).jobs.values() | ||
return list(defined_jobs)[0].account_id | ||
else: | ||
raise ValueError("Either config or account_id must be provided") | ||
|
||
|
||
def check_job_fields(dbt_cloud: DBTCloud, job_ids: List[int]) -> None: | ||
"""Check if there are new fields in job model""" | ||
if not job_ids: | ||
logger.error("We need to provide some job_id to test the import") | ||
return | ||
|
||
logger.info("Checking if there are new fields for jobs") | ||
dbt_cloud.get_job_missing_fields(job_id=job_ids[0]) | ||
|
||
|
||
def fetch_jobs( | ||
dbt_cloud: DBTCloud, job_ids: List[int], project_ids: List[int], environment_ids: List[int] | ||
) -> List[JobDefinition]: | ||
"""Fetch jobs from dbt Cloud based on provided filters""" | ||
logger.info("Getting the jobs definition from dbt Cloud") | ||
|
||
if job_ids and not (project_ids or environment_ids): | ||
# Get jobs one by one if only job_ids provided | ||
cloud_jobs_can_have_none = [dbt_cloud.get_job(job_id=id) for id in job_ids] | ||
return [job for job in cloud_jobs_can_have_none if job is not None] | ||
|
||
# Get all jobs and filter | ||
cloud_jobs = dbt_cloud.get_jobs(project_ids=project_ids, environment_ids=environment_ids) | ||
if job_ids: | ||
cloud_jobs = [job for job in cloud_jobs if job.id in job_ids] | ||
return cloud_jobs |
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
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,61 @@ | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
|
||
from dbt_jobs_as_code.importer import fetch_jobs, get_account_id | ||
from dbt_jobs_as_code.schemas.job import JobDefinition | ||
|
||
|
||
def test_get_account_id(): | ||
# Test account ID from direct input | ||
assert get_account_id(None, 123) == 123 | ||
|
||
# Test missing both inputs | ||
with pytest.raises(ValueError): | ||
get_account_id(None, None) | ||
|
||
|
||
def test_fetch_jobs(): | ||
mock_dbt = Mock() | ||
|
||
# Mock job objects | ||
mock_job1 = JobDefinition( | ||
id=1, | ||
name="Job 1", | ||
project_id=100, | ||
environment_id=200, | ||
account_id=300, | ||
settings={}, | ||
run_generate_sources=False, | ||
execute_steps=[], | ||
generate_docs=False, | ||
schedule={"cron": "0 14 * * 0,1,2,3,4,5,6"}, | ||
triggers={}, | ||
) | ||
mock_job2 = JobDefinition( | ||
id=2, | ||
name="Job 2", | ||
project_id=100, | ||
environment_id=200, | ||
account_id=300, | ||
settings={}, | ||
run_generate_sources=False, | ||
execute_steps=[], | ||
generate_docs=False, | ||
schedule={"cron": "0 14 * * 0,1,2,3,4,5,6"}, | ||
triggers={}, | ||
) | ||
|
||
# Set return values for mocks | ||
mock_dbt.get_job.side_effect = [mock_job1, mock_job2] | ||
mock_dbt.get_jobs.return_value = [mock_job1, mock_job2] | ||
|
||
# Test fetch with only job IDs | ||
jobs = fetch_jobs(mock_dbt, [1, 2], [], []) | ||
assert mock_dbt.get_job.call_count == 2 | ||
assert len(jobs) == 2 | ||
|
||
# Test fetch with project IDs | ||
jobs = fetch_jobs(mock_dbt, [1], [100], []) | ||
mock_dbt.get_jobs.assert_called_with(project_ids=[100], environment_ids=[]) | ||
assert len(jobs) == 1 |
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,27 @@ | ||
import pytest | ||
from pydantic import ValidationError | ||
|
||
from dbt_jobs_as_code.schemas.custom_environment_variable import ( | ||
CustomEnvironmentVariable, | ||
CustomEnvironmentVariablePayload, | ||
) | ||
|
||
|
||
def test_custom_env_var_validation(): | ||
"""Test that environment variable validation works correctly""" | ||
|
||
# Valid cases | ||
valid_var = CustomEnvironmentVariable(name="DBT_TEST_VAR", value="test_value") | ||
assert valid_var.name == "DBT_TEST_VAR" | ||
assert valid_var.value == "test_value" | ||
assert valid_var.type == "job" | ||
|
||
# Test invalid prefix | ||
with pytest.raises(ValidationError) as exc: | ||
CustomEnvironmentVariable(name="TEST_VAR", value="test") | ||
assert "Key must have `DBT_` prefix" in str(exc.value) | ||
|
||
# Test lowercase name | ||
with pytest.raises(ValidationError) as exc: | ||
CustomEnvironmentVariable(name="DBT_test_var", value="test") | ||
assert "Key name must be SCREAMING_SNAKE_CASE" in str(exc.value) |
Oops, something went wrong.