Skip to content

Commit

Permalink
fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dwreeves committed Dec 2, 2023
2 parents 0c4c83f + 26518d0 commit b74e402
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
5 changes: 5 additions & 0 deletions docs/configuration/hosting-docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,8 @@ For example, if your dbt project directory is ``/usr/local/airflow/dags/my_dbt_p
.. code-block:: shell
AIRFLOW__COSMOS__DBT_DOCS_DIR="/usr/local/airflow/dags/my_dbt_project/target"
Using docs out of local storage has the downside that some values in the dbt docs can become stale unless the docs are periodically refreshed and redeployed:

- Counts of the numbers of rows.
- The compiled SQL for incremental models before and after the first run.
32 changes: 11 additions & 21 deletions tests/plugin/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,65 +12,55 @@


@pytest.fixture(scope="module")
@patch("airflow.www.auth.managers.fab.fab_auth_manager.FabAuthManager.get_user")
def app(mock_user) -> FlaskClient:
def app() -> FlaskClient:
initdb()

app = cached_app(testing=True)
app.config["AUTH_ROLE_PUBLIC"] = "pytest_role"
appbuilder: AirflowAppBuilder = app.extensions["appbuilder"]

if dbt_docs_view not in appbuilder.baseviews:
appbuilder._check_and_init(dbt_docs_view)
appbuilder.register_blueprint(dbt_docs_view)

if not appbuilder.sm.find_role("pytest_role"):
appbuilder.sm.add_role("pytest_role", permissions=[(permissions.ACTION_CAN_READ, )])

if not appbuilder.sm.find_user("pytest_user"):
mock_user.return_value = appbuilder.sm.add_user(
username="pytest_user",
first_name="J.",
last_name="Doe",
email="[email protected]",
role="pytest_role",
password="pw",
)
appbuilder.sm.add_role("pytest_role", permissions=[(permissions.ACTION_CAN_READ,)])

yield app.test_client()

resetdb(skip_init=True)


@patch("cosmos.plugin.conf")
@patch("cosmos.plugin.conf.get")
@patch("cosmos.plugin.open_file")
def test_dbt_docs(mock_open_file, mock_conf, app):
mock_conf.get.return_value = "some_value"
mock_conf.return_value = "some_value"
response = app.get("/cosmos/dbt_docs")
assert mock_open_file.assert_called_once()
assert response.status_code == 200


@patch("cosmos.plugin.conf")
@patch("cosmos.plugin.conf.get")
def test_dbt_docs_not_set_up(mock_conf, app):
mock_conf.get.side_effect = AirflowConfigException
mock_conf.side_effect = AirflowConfigException
response = app.get("/cosmos/dbt_docs")
assert response.status_code == 500


@patch("cosmos.plugin.conf")
@patch("cosmos.plugin.conf.get")
@patch("cosmos.plugin.open_file")
@pytest.mark.parametrize("artifact", ["dbt_docs_index.html", "manifest.json", "catalog.json"])
def test_dbt_docs_artifact(mock_open_file, mock_conf, app, artifact):
mock_conf.get.return_value = "some_value"
mock_conf.return_value = "some_value"
response = app.get(f"/cosmos/{artifact}")
assert mock_open_file.assert_called_once()
assert response.status_code == 200


@patch("cosmos.plugin.conf")
@patch("cosmos.plugin.conf.get")
@patch("cosmos.plugin.open_file")
@pytest.mark.parametrize("artifact", ["dbt_docs_index.html", "manifest.json", "catalog.json"])
def test_dbt_docs_artifact_missing(mock_open_file, mock_conf, app, artifact):
mock_conf.get.side_effect = AirflowConfigException
mock_conf.side_effect = AirflowConfigException
response = app.get(f"/cosmos/{artifact}")
assert response.status_code == 404

0 comments on commit b74e402

Please sign in to comment.