Skip to content

Commit 5b807c1

Browse files
committed
Added test for changed --service-root variable
1 parent 9e1bbcb commit 5b807c1

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ tests =
116116
pytest-xdist>=2
117117
pytest-mock>=3.7
118118
pytest>=6
119+
requests
119120
testfixtures>=6.11.0
120121
towncrier>=24.7.0
121122
# Type annotation stubs
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
2+
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
from contextlib import suppress
18+
import json
19+
import pytest
20+
import socket
21+
import subprocess
22+
import requests
23+
from time import sleep
24+
25+
from cylc.flow import __version__ as CYLC_VERSION
26+
27+
28+
@pytest.fixture(scope='module')
29+
def run_cylc_review(request):
30+
port, timeout, service_root = request.param
31+
"""Start a Cylc Review server.
32+
33+
(Clean it up after too)
34+
35+
Yields:
36+
Server process, request to home page as json
37+
"""
38+
39+
proc = subprocess.Popen(
40+
[
41+
'cylc',
42+
'review',
43+
'start',
44+
'--port', port,
45+
f'--service-root={service_root}',
46+
],
47+
stdout=subprocess.PIPE,
48+
stderr=subprocess.STDOUT,
49+
)
50+
51+
# Ensure that home-page is accessible:
52+
timeout_counter = 0
53+
req = None
54+
sleep(1)
55+
while (
56+
getattr(req, 'status_code', 1) != 200
57+
and timeout_counter < timeout
58+
):
59+
sleep(1)
60+
with suppress(Exception):
61+
req = requests.get(
62+
f'http://localhost:{port}/{service_root}-review?form=json'
63+
)
64+
timeout_counter += 1
65+
66+
yield proc, req
67+
proc.terminate()
68+
69+
70+
@pytest.mark.parametrize(
71+
'run_cylc_review',
72+
[["8666", 10, 'foo/cylc']],
73+
indirect=['run_cylc_review']
74+
)
75+
def test_basic_path(run_cylc_review):
76+
"""The CLI --service-root option changes the path to Cylc Review."""
77+
expect = {
78+
'logo': 'cylc-logo.png',
79+
'title': 'Cylc Review',
80+
'host': socket.gethostname(),
81+
'cylc_version': CYLC_VERSION,
82+
'script': '/foo/cylc-review',
83+
}
84+
data = json.loads(run_cylc_review[1].text)
85+
assert data == expect

0 commit comments

Comments
 (0)