Skip to content

Commit 442a7e4

Browse files
committed
Test test_import_destination_type_config
1 parent 1ba72aa commit 442a7e4

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/common/destination/test_reference.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,48 @@ def test_import_destination_config() -> None:
308308
Destination.from_reference(ref=None, destination_name="balh")
309309

310310

311+
@pytest.mark.parametrize(
312+
"destination_type",
313+
["duckdb", "wrong_type"],
314+
ids=["destination_type_duckdb", "destination_type_invalid"],
315+
)
316+
def test_import_destination_type_config(
317+
environment: Dict[str, str],
318+
destination_type: str,
319+
destination_name: str = "my_destination",
320+
) -> None:
321+
environment[f"DESTINATION__{destination_name.upper()}__DESTINATION_TYPE"] = destination_type
322+
323+
if destination_type == "wrong_type":
324+
with pytest.raises(UnknownDestinationModule):
325+
Destination.from_reference(ref=destination_name)
326+
327+
# if destination_name is provided, ref should be a valid destination type
328+
with pytest.raises(UnknownDestinationModule):
329+
Destination.from_reference(
330+
ref=f"dlt.destinations.{destination_type}", destination_name=destination_name
331+
)
332+
333+
# if ref contains dots, it's a module path and should be valid
334+
with pytest.raises(UnknownDestinationModule):
335+
Destination.from_reference(ref=f"dlt.destinations.{destination_type}")
336+
337+
else:
338+
dest = Destination.from_reference(ref=destination_name)
339+
assert dest.destination_type == "dlt.destinations.duckdb"
340+
assert dest.destination_name == destination_name
341+
342+
dest = Destination.from_reference(
343+
ref=f"dlt.destinations.{destination_type}", destination_name=destination_name
344+
)
345+
assert dest.destination_type == "dlt.destinations.duckdb"
346+
assert dest.destination_name == destination_name
347+
348+
dest = Destination.from_reference(ref=f"dlt.destinations.{destination_type}")
349+
assert dest.destination_type == "dlt.destinations.duckdb"
350+
assert dest.destination_name == "duckdb"
351+
352+
311353
def test_destination_config_explicit_credentials() -> None:
312354
# set explicit credentials via reference
313355
dest = Destination.from_reference(

0 commit comments

Comments
 (0)