-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
15 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 |
---|---|---|
|
@@ -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: | ||
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 |