Skip to content

Commit

Permalink
Updated some tests, fixed error with default ProfileConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
tabmra committed Oct 24, 2023
1 parent d1d0d4f commit 11721a9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
5 changes: 0 additions & 5 deletions cosmos/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import contextlib
import tempfile
from dataclasses import dataclass, field
from functools import cached_property
from pathlib import Path
from typing import Any, Iterator, Callable

Expand Down Expand Up @@ -93,10 +92,6 @@ def __init__(
if manifest_path:
self.manifest_path = Path(manifest_path)

@cached_property
def dbt_project_path_parent(self) -> Path | None:
return self.dbt_project_path.parent if self.dbt_project_path else None

def validate_project(self) -> None:
"""
Validates necessary context is present for a project.
Expand Down
5 changes: 1 addition & 4 deletions cosmos/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class DbtToAirflowConverter:
def __init__(
self,
project_config: ProjectConfig,
profile_config: ProfileConfig = None,
profile_config: ProfileConfig,
execution_config: ExecutionConfig = ExecutionConfig(),
render_config: RenderConfig = RenderConfig(),
dag: DAG | None = None,
Expand All @@ -114,9 +114,6 @@ def __init__(
dbt_executable_path = execution_config.dbt_executable_path
node_converters = render_config.node_converters

if not profile_config:
profile_config = ProfileConfig(profiles_yml_filepath=project_config.dbt_project_path / "profiles.yml")

profile_args = {}
if profile_config.profile_mapping:
profile_args = profile_config.profile_mapping.profile_args
Expand Down
10 changes: 10 additions & 0 deletions tests/dbt/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,16 @@ def test_load_via_dbt_ls_without_exclude(project_name):
assert len(dbt_graph.nodes) == 28


def test_load_via_custom_without_project_path():
project_config = ProjectConfig(manifest_path=SAMPLE_MANIFEST, project_name="test")
dbt_graph = DbtGraph(dbt_cmd="/inexistent/dbt", project=project_config)
with pytest.raises(CosmosLoadDbtException) as err_info:
dbt_graph.load_via_custom_parser()

expected = "Unable to load dbt project without project files"
assert err_info.value.args[0] == expected


def test_load_via_dbt_ls_without_profile():
project_config = ProjectConfig(dbt_project_path=DBT_PROJECTS_ROOT_DIR / DBT_PROJECT_NAME)
dbt_graph = DbtGraph(dbt_cmd="/inexistent/dbt", project=project_config)
Expand Down
17 changes: 16 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from cosmos.config import ProjectConfig
from cosmos.config import ProfileConfig, ProjectConfig
from cosmos.exceptions import CosmosValueError


Expand Down Expand Up @@ -113,3 +113,18 @@ def test_is_manifest_available_is_false():
def test_project_name():
dbt_project = ProjectConfig(dbt_project_path=DBT_PROJECTS_ROOT_DIR)
assert dbt_project.project_name == "sample"


def test_profile_config_post_init():
with pytest.raises(CosmosValueError) as err_info:
ProfileConfig(profiles_yml_filepath="/tmp/some-profile", profile_name="test", target_name="test")
assert err_info.value.args[0] == "The file /tmp/some-profile does not exist."


def test_profile_config_validate():
with pytest.raises(CosmosValueError) as err_info:
profile_config = ProfileConfig(profile_name="test", target_name="test")
assert profile_config.validate_profile() is None
assert (
err_info.value.args[0] == "Either profiles_yml_filepath or profile_mapping must be set to render a profile"
)

0 comments on commit 11721a9

Please sign in to comment.