This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Add missing dbt commands #68
Open
dinigo
wants to merge
5
commits into
gocardless:master
Choose a base branch
from
teamdatatonic:feature/add-missing-operators
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+133
−63
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e779a79
feature: add several missing dbt commands
dinigo 448cdad
test: parametrize Operators tests
dinigo 4f7535b
fix: operators call now supper with it's own type
dinigo 50de1f4
test: fix the type for a test param
dinigo 86d69dc
Merge branch 'master' into feature/add-missing-operators
dinigo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,76 +1,74 @@ | ||
import datetime | ||
from unittest import TestCase, mock | ||
from unittest import mock | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
from airflow import DAG, configuration | ||
from airflow_dbt.hooks.dbt_hook import DbtCliHook | ||
|
||
from airflow_dbt import DbtCliHook | ||
from airflow_dbt.operators.dbt_operator import ( | ||
DbtBaseOperator, | ||
DbtBuildOperator, | ||
DbtCleanOperator, | ||
DbtCompileOperator, | ||
DbtDebugOperator, | ||
DbtDepsOperator, | ||
DbtDocsGenerateOperator, | ||
DbtInitOperator, | ||
DbtListOperator, | ||
DbtParseOperator, | ||
DbtRunOperator, | ||
DbtSeedOperator, | ||
DbtSnapshotOperator, | ||
DbtRunOperator, | ||
DbtSourceOperator, | ||
DbtTestOperator, | ||
DbtDepsOperator, | ||
DbtCleanOperator, | ||
) | ||
|
||
|
||
class TestDbtOperator(TestCase): | ||
def setUp(self): | ||
configuration.conf.load_test_config() | ||
args = { | ||
'owner': 'airflow', | ||
'start_date': datetime.datetime(2020, 2, 27) | ||
} | ||
self.dag = DAG('test_dag_id', default_args=args) | ||
|
||
@mock.patch.object(DbtCliHook, 'run_cli') | ||
def test_dbt_run(self, mock_run_cli): | ||
operator = DbtRunOperator( | ||
task_id='run', | ||
dag=self.dag | ||
) | ||
operator.execute(None) | ||
mock_run_cli.assert_called_once_with('run') | ||
@pytest.fixture | ||
def spy_cli_run(mocker) -> MagicMock: | ||
yield mocker.patch("airflow_dbt.hooks.dbt_hook.DbtCliHook.run_cli") | ||
|
||
@mock.patch.object(DbtCliHook, 'run_cli') | ||
def test_dbt_test(self, mock_run_cli): | ||
operator = DbtTestOperator( | ||
task_id='test', | ||
dag=self.dag | ||
) | ||
operator.execute(None) | ||
mock_run_cli.assert_called_once_with('test') | ||
|
||
@mock.patch.object(DbtCliHook, 'run_cli') | ||
def test_dbt_snapshot(self, mock_run_cli): | ||
operator = DbtSnapshotOperator( | ||
task_id='snapshot', | ||
dag=self.dag | ||
) | ||
operator.execute(None) | ||
mock_run_cli.assert_called_once_with('snapshot') | ||
@pytest.fixture | ||
def mock_dag() -> MagicMock: | ||
configuration.conf.load_test_config() | ||
args = { | ||
'owner': 'airflow', | ||
'start_date': datetime.datetime(2020, 2, 27) | ||
} | ||
yield DAG('test_dag_id', default_args=args) | ||
|
||
@mock.patch.object(DbtCliHook, 'run_cli') | ||
def test_dbt_seed(self, mock_run_cli): | ||
operator = DbtSeedOperator( | ||
task_id='seed', | ||
dag=self.dag | ||
) | ||
operator.execute(None) | ||
mock_run_cli.assert_called_once_with('seed') | ||
|
||
@mock.patch.object(DbtCliHook, 'run_cli') | ||
def test_dbt_deps(self, mock_run_cli): | ||
operator = DbtDepsOperator( | ||
task_id='deps', | ||
dag=self.dag | ||
) | ||
operator.execute(None) | ||
mock_run_cli.assert_called_once_with('deps') | ||
|
||
@mock.patch.object(DbtCliHook, 'run_cli') | ||
def test_dbt_clean(self, mock_run_cli): | ||
operator = DbtCleanOperator( | ||
task_id='clean', | ||
dag=self.dag | ||
) | ||
operator.execute(None) | ||
mock_run_cli.assert_called_once_with('clean') | ||
@pytest.mark.parametrize( | ||
['operator', 'expected_command'], | ||
[ | ||
(DbtRunOperator, ['run']), | ||
(DbtTestOperator, ['test']), | ||
(DbtSnapshotOperator, ['snapshot']), | ||
(DbtDocsGenerateOperator, ['docs', 'generate']), | ||
(DbtSeedOperator, ['seed']), | ||
(DbtDepsOperator, ['deps']), | ||
(DbtBuildOperator, ['build']), | ||
(DbtCleanOperator, ['clean']), | ||
(DbtCompileOperator, ['compile']), | ||
(DbtDebugOperator, ['debug']), | ||
(DbtInitOperator, ['init']), | ||
(DbtListOperator, ['list']), | ||
(DbtParseOperator, ['parse']), | ||
(DbtListOperator, ['list']), | ||
(DbtSourceOperator, ['source']), | ||
] | ||
) | ||
@mock.patch.object(DbtCliHook, 'run_cli') | ||
def test_operators_commands( | ||
spy_cli_run, | ||
operator: DbtBaseOperator, | ||
expected_command: [str], | ||
mock_dag, | ||
): | ||
"""Every operator passess down to the execution the correct dbt command""" | ||
task_id = 'test_dbt_' + '_'.join(expected_command) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. flake8 complains about an extra space here |
||
operator = operator(task_id=task_id, dag=mock_dag) | ||
operator.execute(None) | ||
spy_cli_run.assert_called_once_with(*expected_command) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flake8 complains about too long line here