Skip to content

Commit

Permalink
Tests: auto-patch to avoid loading user/site configs
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed Jul 2, 2024
1 parent f6a05fc commit 77fc181
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
22 changes: 13 additions & 9 deletions cylc/uiserver/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,6 @@ class CylcUIServer(ExtensionApp):
cylc gui --no-browser # Start the server but don't open the browser
''') # type: ignore[assignment]
config_file_paths = get_conf_dir_hierarchy(
[
SITE_CONF_ROOT, # site configuration
USER_CONF_ROOT, # user configuration
], filename=False
)
# Next include currently needed for directory making
config_file_paths.insert(0, str(Path(uis_pkg).parent)) # packaged config
config_file_paths.reverse()
# TODO: Add a link to the access group table mappings in cylc documentation
# https://github.com/cylc/cylc-uiserver/issues/466
AUTH_DESCRIPTION = '''
Expand Down Expand Up @@ -348,6 +339,19 @@ class CylcUIServer(ExtensionApp):
default_value=False,
)

@property
def config_file_paths(self):
ret = get_conf_dir_hierarchy(
[
SITE_CONF_ROOT, # site configuration
USER_CONF_ROOT, # user configuration
], filename=False
)
# Next include currently needed for directory making
ret.insert(0, str(Path(uis_pkg).parent)) # packaged config
ret.reverse()
return ret

@validate('ui_build_dir')
def _check_ui_build_dir_exists(self, proposed):
if proposed['value'].exists():
Expand Down
16 changes: 6 additions & 10 deletions cylc/uiserver/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Test code and fixtures."""

from getpass import getuser
import inspect
import logging
from pathlib import Path
from shutil import rmtree
from socket import gethostname
from tempfile import TemporaryDirectory
from uuid import uuid4

import pytest
from tornado.web import HTTPError
from traitlets.config import Config
import zmq

Expand All @@ -47,6 +44,7 @@
from cylc.flow.parsec.config import ParsecConfig
from cylc.flow.parsec.validate import cylc_config_validate


class AsyncClientFixture(WorkflowRuntimeClient):
pattern = zmq.REQ
host = ''
Expand Down Expand Up @@ -223,7 +221,7 @@ def mock_authentication_yossarian(monkeypatch):
def jp_server_config(jp_template_dir):
"""Config to turn the CylcUIServer extension on.
Auto-loading, add as an argument in the test function to activate.
Overrides jupyter server fixture of the same name.
"""
config = {
"ServerApp": {
Expand All @@ -235,12 +233,9 @@ def jp_server_config(jp_template_dir):
return config


@pytest.fixture
def patch_conf_files(monkeypatch):
"""Auto-patches the CylcUIServer to prevent it loading config files.
Auto-loading, add as an argument in the test function to activate.
"""
@pytest.fixture(autouse=True)
def patch_conf_files(monkeypatch: pytest.MonkeyPatch):
"""Auto-patches the CylcUIServer to prevent it loading config files."""
monkeypatch.setattr(
'cylc.uiserver.app.CylcUIServer.config_file_paths', []
)
Expand Down Expand Up @@ -364,6 +359,7 @@ def workflow_run_dir(request):
if not request.session.testsfailed:
rmtree(run_dir)


@pytest.fixture
def mock_glbl_cfg(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
"""A Pytest fixture for fiddling global config values.
Expand Down
4 changes: 1 addition & 3 deletions cylc/uiserver/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@pytest.mark.integration
@pytest.mark.usefixtures("mock_authentication_yossarian")
async def test_cylc_handler(patch_conf_files, jp_fetch):
async def test_cylc_handler(jp_fetch):
"""The Cylc endpoints have been added and work."""
resp = await jp_fetch(
'cylc', 'userprofile', method='GET'
Expand Down Expand Up @@ -60,7 +60,6 @@ async def test_cylc_handler(patch_conf_files, jp_fetch):
]
)
async def test_authorised_and_authenticated(
patch_conf_files,
jp_fetch,
endpoint,
code,
Expand Down Expand Up @@ -95,7 +94,6 @@ async def test_authorised_and_authenticated(
]
)
async def test_unauthorised(
patch_conf_files,
jp_fetch,
endpoint,
code,
Expand Down

0 comments on commit 77fc181

Please sign in to comment.