-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'add-dbt-docs-support' of github.com-dwreeves:dwreeves/a…
…stronomer-cosmos into add-dbt-docs-support
- Loading branch information
Showing
1 changed file
with
28 additions
and
31 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,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") | ||
|