Skip to content

Commit

Permalink
Merge branch 'add-dbt-docs-support' of github.com-dwreeves:dwreeves/a…
Browse files Browse the repository at this point in the history
…stronomer-cosmos into add-dbt-docs-support
  • Loading branch information
dwreeves committed Dec 2, 2023
2 parents 3867cfc + 59721d6 commit b3be404
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions tests/plugin/test_plugin.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
import pytest
from unittest.mock import patch
from airflow.www.extensions.init_appbuilder import AirflowAppBuilder
from airflow.www.app import cached_app

import pytest
from airflow.exceptions import AirflowConfigException
from airflow.security import permissions
from airflow.utils.db import initdb, resetdb
from airflow.www.app import cached_app
from airflow.www.extensions.init_appbuilder import AirflowAppBuilder
from flask.testing import FlaskClient
from cosmos.plugin import dbt_docs_view
from tests.test_utils.api_connexion_utils import (
create_user,
create_user_scope,
delete_role,
delete_user,
set_user_single_role,
)

@pytest.fixture(autouse=True)
def _db():
initdb()
yield
resetdb(skip_init=True)

from cosmos.plugin import dbt_docs_view

@pytest.fixture(scope="function")
def role(request, app, security_manager):
params = request.param
_role = None
params["mock_roles"] = [{"role": params["name"], "perms": params["permissions"]}]
if params.get("create", True):
security_manager.bulk_sync_roles(params["mock_roles"])
_role = security_manager.find_role(params["name"])
yield _role, params
delete_role(app, params["name"])

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

@pytest.fixture
def app() -> FlaskClient:
app = cached_app(testing=True)
app.config["AUTH_ROLE_PUBLIC"] = "Admin"
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)
return app.test_client()

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",
)

yield app.test_client()

resetdb(skip_init=True)


@patch("cosmos.plugin.conf")
Expand Down

0 comments on commit b3be404

Please sign in to comment.