Skip to content

Commit

Permalink
add TestRuntimeRefResolver and TestRuntimeSourceResolver unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Nov 17, 2023
1 parent 6a37d28 commit 691942a
Showing 1 changed file with 72 additions and 1 deletion.
73 changes: 72 additions & 1 deletion tests/unit/test_providers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest
from unittest import mock

from dbt.context.providers import BaseResolver
from dbt.adapters.base import BaseRelation
from dbt.context.providers import BaseResolver, RuntimeRefResolver, RuntimeSourceResolver
from dbt.contracts.graph.unparsed import Quoting


class TestBaseResolver:
Expand All @@ -26,3 +28,72 @@ def test_resolve_limit(self, resolver, empty, expected_resolve_limit):
resolver.config.args.EMPTY = empty

assert resolver.resolve_limit == expected_resolve_limit


class TestRuntimeRefResolver:
@pytest.fixture
def resolver(self):
mock_db_wrapper = mock.Mock()
mock_db_wrapper.Relation = BaseRelation

return RuntimeRefResolver(
db_wrapper=mock_db_wrapper,
model=mock.Mock(),
config=mock.Mock(),
manifest=mock.Mock(),
)

@pytest.mark.parametrize(
"empty,is_ephemeral_model,expected_limit",
[
(False, False, None),
(True, False, 0),
(False, True, None),
(True, True, 0),
],
)
def test_create_relation_with_empty(self, resolver, empty, is_ephemeral_model, expected_limit):
# setup resolver and input node
resolver.config.args.EMPTY = empty
mock_node = mock.Mock()
mock_node.is_ephemeral_model = is_ephemeral_model

# create limited relation
relation = resolver.create_relation(mock.Mock())
assert relation.limit == expected_limit


class TestRuntimeSourceResolver:
@pytest.fixture
def resolver(self):
mock_db_wrapper = mock.Mock()
mock_db_wrapper.Relation = BaseRelation

return RuntimeSourceResolver(
db_wrapper=mock_db_wrapper,
model=mock.Mock(),
config=mock.Mock(),
manifest=mock.Mock(),
)

@pytest.mark.parametrize(
"empty,expected_limit",
[
(False, None),
(True, 0),
],
)
def test_create_relation_with_empty(self, resolver, empty, expected_limit):
# setup resolver and input source
resolver.config.args.EMPTY = empty

mock_source = mock.Mock()
mock_source.database = "test"
mock_source.schema = "test"
mock_source.identifier = "test"
mock_source.quoting = Quoting()
resolver.manifest.resolve_source.return_value = mock_source

# create limited relation
relation = resolver.resolve("test", "test")
assert relation.limit == expected_limit

0 comments on commit 691942a

Please sign in to comment.