Skip to content

Commit

Permalink
Use mock to simulate database failure in "test__templater_dbt_handle_…
Browse files Browse the repository at this point in the history
…database_connection_failure"
  • Loading branch information
Barry Hart committed Jan 7, 2022
1 parent 73c2784 commit 8c37557
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions plugins/sqlfluff-templater-dbt/test/templater_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import glob
import os
import pytest
import logging
from pathlib import Path
from unittest import mock

import pytest

from sqlfluff.core import FluffConfig, Lexer, Linter
from sqlfluff.core.errors import SQLTemplaterSkipFile
Expand All @@ -15,6 +16,7 @@
dbt_templater,
project_dir,
)
from sqlfluff_templater_dbt.templater import DbtFailedToConnectException


def test__templater_dbt_missing(dbt_templater, project_dir): # noqa: F811
Expand Down Expand Up @@ -317,13 +319,16 @@ def test__templater_dbt_handle_exceptions(
assert violations[0].desc().replace("\\", "/").startswith(exception_msg)


@mock.patch("dbt.adapters.postgres.impl.PostgresAdapter.set_relations_cache")
@pytest.mark.dbt_connection_failure
def test__templater_dbt_handle_database_connection_failure(
project_dir, dbt_templater # noqa: F811
set_relations_cache, project_dir, dbt_templater # noqa: F811
):
"""Test the result of a failed database connection."""
from dbt.adapters.factory import get_adapter

set_relations_cache.side_effect = DbtFailedToConnectException("dummy error")

src_fpath = "plugins/sqlfluff-templater-dbt/test/fixtures/dbt/error_models/exception_connect_database.sql"
target_fpath = os.path.abspath(
os.path.join(
Expand Down

0 comments on commit 8c37557

Please sign in to comment.