Skip to content

Commit

Permalink
Close test coverage gap
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Grande committed Feb 10, 2023
1 parent 2ed0a6d commit 0a0dcf1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/services/sevenbridges/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -34,6 +35,7 @@
SevenBridgesHook,
SevenBridgesOps,
)
from orca.services.sevenbridges.hook import BaseHook


@pytest.fixture
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions tests/services/sevenbridges/test_hook.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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

0 comments on commit 0a0dcf1

Please sign in to comment.