Skip to content

Commit

Permalink
Add target class init test
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Aug 23, 2022
1 parent 39af208 commit 7e1d10a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions samples/sample_tap_sqlite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class SQLiteTap(SQLTap):
DB_PATH_CONFIG,
th.StringType,
description="The path to your SQLite database file(s).",
required=True,
)
).to_dict()

Expand Down
1 change: 1 addition & 0 deletions samples/sample_target_sqlite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class SQLiteTarget(SQLTarget):
DB_PATH_CONFIG,
th.StringType,
description="The path to your SQLite database file(s).",
required=True,
)
).to_dict()

Expand Down
50 changes: 50 additions & 0 deletions tests/core/test_target_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from __future__ import annotations

import json
from contextlib import nullcontext

import pytest
from click.testing import CliRunner

from samples.sample_target_sqlite import SQLiteTarget
from singer_sdk.exceptions import ConfigValidationError


@pytest.mark.parametrize(
"config_dict,expectation,errors",
[
pytest.param(
{},
pytest.raises(ConfigValidationError, match="Config validation failed"),
["'path_to_db' is a required property"],
id="missing_path_to_db",
),
pytest.param(
{"path_to_db": "sqlite://test.db"},
nullcontext(),
[],
id="valid_config",
),
],
)
def test_config_errors(config_dict: dict, expectation, errors: list[str]):
with expectation as exc:
SQLiteTarget(config_dict, validate_config=True)

if isinstance(exc, pytest.ExceptionInfo):
assert exc.value.errors == errors


def test_cli(tmp_path):
"""Test the CLI."""
runner = CliRunner(mix_stderr=False)
result = runner.invoke(SQLiteTarget.cli, ["--help"])
assert result.exit_code == 0
assert "Show this message and exit." in result.output

config_path = tmp_path / "config.json"
config_path.write_text(json.dumps({}))
result = runner.invoke(SQLiteTarget.cli, ["--config", str(config_path)])
assert result.exit_code == 1
assert result.stdout == ""
assert "'path_to_db' is a required property" in result.stderr

0 comments on commit 7e1d10a

Please sign in to comment.