From 0a0dcf1e75dbff30ea0cfb727666881dffd273b5 Mon Sep 17 00:00:00 2001 From: Bruno Grande Date: Thu, 9 Feb 2023 20:37:44 -0800 Subject: [PATCH] Close test coverage gap --- tests/services/sevenbridges/conftest.py | 8 +++++--- tests/services/sevenbridges/test_hook.py | 12 ++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/services/sevenbridges/conftest.py b/tests/services/sevenbridges/conftest.py index 27c9752..a0cc844 100644 --- a/tests/services/sevenbridges/conftest.py +++ b/tests/services/sevenbridges/conftest.py @@ -2,6 +2,7 @@ from unittest.mock import MagicMock import pytest +from airflow.exceptions import AirflowNotFoundException from airflow.models.connection import Connection from sevenbridges.api import ( Actions, @@ -34,6 +35,7 @@ SevenBridgesHook, SevenBridgesOps, ) +from orca.services.sevenbridges.hook import BaseHook @pytest.fixture @@ -125,9 +127,9 @@ def connection(connection_uri): @pytest.fixture def patch_get_connection(mocker, connection): - connection_mock = mocker.patch.object(SevenBridgesHook, "get_connection") - connection_mock.return_value = connection - yield + connection_mock = mocker.patch.object(BaseHook, "get_connection") + connection_mock.side_effect = AirflowNotFoundException + yield connection_mock @pytest.fixture diff --git a/tests/services/sevenbridges/test_hook.py b/tests/services/sevenbridges/test_hook.py index 68e5643..cb8d6a2 100644 --- a/tests/services/sevenbridges/test_hook.py +++ b/tests/services/sevenbridges/test_hook.py @@ -1,6 +1,8 @@ import pytest +from airflow.models.connection import Connection from sevenbridges import Api +from orca.errors import ClientArgsError from orca.services.sevenbridges import SevenBridgesHook, SevenBridgesOps @@ -17,3 +19,13 @@ def test_that_the_client_object_can_be_retrieved_from_hook(self, hook): def test_that_the_ops_object_can_be_retrieved_from_hook(self, hook): assert isinstance(hook.ops, SevenBridgesOps) + + def test_that_a_connection_is_returned_without_airflow(self, hook): + connection = hook.get_connection("foo") + assert isinstance(connection, Connection) + + def test_for_error_without_airflow_or_env(self, hook, patch_get_connection, mocker): + empty_connection = Connection(uri="sbg://") + mocker.patch.object(hook, "connection", empty_connection) + with pytest.raises(ClientArgsError): + hook.ops