Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions tests/pytests/unit/netapi/rest_tornado/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import sys

import pytest

import salt.netapi.rest_tornado.saltnado as saltnado
from tests.support.mock import MagicMock


@pytest.fixture
def io_loop(io_loop):
"""
Fail tests on exceptions raised inside IOLoop callbacks.

The legacy AsyncTestCase harness rethrew exceptions raised in scheduled
callbacks; the plain IOLoop only logs them, which would let a broken
completer callback pass a test that no longer exercises anything.
Capture such exceptions and re-raise them at teardown.
"""
captured = []

def capture_callback_exception(callback):
captured.append(sys.exc_info()[1])

io_loop.handle_callback_exception = capture_callback_exception
yield io_loop
if captured:
raise captured[0]


@pytest.fixture
def app_mock():
mock = MagicMock()
mock.opts = {
"syndic_wait": 0.1,
"cachedir": "/tmp/testing/cachedir",
"sock_dir": "/tmp/testing/sock_drawer",
"transport": "zeromq",
"extension_modules": "/tmp/testing/moduuuuules",
"order_masters": False,
"gather_job_timeout": 10.001,
}
return mock


@pytest.fixture
def salt_api_handler(io_loop, app_mock):
# io_loop is requested first so the fresh loop is current before the
# handler is constructed, matching the setUp ordering the legacy
# AsyncTestCase suite relied on.
return saltnado.SaltAPIHandler(app_mock, app_mock)
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
import time

import pytest

import salt.netapi.rest_tornado.saltnado as saltnado_app
from tests.support.mock import MagicMock, patch


@pytest.fixture
def arg_mock():
mock = MagicMock()
mock.opts = {
"syndic_wait": 0.1,
"cachedir": "/tmp/testing/cachedir",
"sock_dir": "/tmp/testing/sock_drawer",
"transport": "zeromq",
"extension_modules": "/tmp/testing/moduuuuules",
"order_masters": False,
"gather_job_timeout": 10.001,
}
return mock
from tests.support.mock import patch


def test__verify_auth(arg_mock):
base_handler = saltnado_app.BaseSaltAPIHandler(arg_mock, arg_mock)
def test__verify_auth(app_mock):
base_handler = saltnado_app.BaseSaltAPIHandler(app_mock, app_mock)
with patch.object(base_handler, "get_cookie", return_value="ABCDEF"):
with patch.object(
base_handler.application.auth,
Expand All @@ -32,8 +15,8 @@ def test__verify_auth(arg_mock):
assert base_handler._verify_auth()


def test__verify_auth_expired(arg_mock):
base_handler = saltnado_app.BaseSaltAPIHandler(arg_mock, arg_mock)
def test__verify_auth_expired(app_mock):
base_handler = saltnado_app.BaseSaltAPIHandler(app_mock, app_mock)
with patch.object(base_handler, "get_cookie", return_value="ABCDEF"):
with patch.object(
base_handler.application.auth,
Expand Down
Loading
Loading