Skip to content

Commit

Permalink
Merge pull request #6095 from MetRonnie/set-schema
Browse files Browse the repository at this point in the history
Add "valid for" states to schema def for `cylc set`
  • Loading branch information
oliver-sanders authored May 8, 2024
2 parents 7ec8766 + b179a41 commit f2f333d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cylc/flow/network/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,8 @@ class Meta:
- ``started`` implies ``submitted``.
- ``succeeded`` and ``failed`` imply ``started``.
- custom outputs and ``expired`` do not imply any other outputs.
Valid for: paused, running, stopping workflows.
""")
resolver = partial(mutator, command='set')

Expand Down
24 changes: 24 additions & 0 deletions tests/unit/network/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@

from dataclasses import dataclass
from inspect import isclass
import re

import graphene
import pytest

from cylc.flow.cfgspec.workflow import SPEC as WORKFLOW_SPEC
from cylc.flow.network.schema import (
RUNTIME_FIELD_TO_CFG_MAP,
Mutations,
Runtime,
sort_elements,
SortArgs,
)
from cylc.flow.workflow_status import WorkflowStatus


@dataclass
Expand Down Expand Up @@ -99,3 +103,23 @@ def test_runtime_field_to_cfg_map(field_name: str):
cfg_name = RUNTIME_FIELD_TO_CFG_MAP[field_name]
assert field_name in Runtime.__dict__
assert WORKFLOW_SPEC.get('runtime', '__MANY__', cfg_name)


@pytest.mark.parametrize('mutation', (
pytest.param(attr, id=name)
for name, attr in Mutations.__dict__.items()
if isinstance(attr, graphene.Field)
))
def test_mutations_valid_for(mutation):
"""Check that all mutations have a "Valid for" in their description.
This is needed by the UI to disable mutations that are not valid for the
workflow state.
"""
match = re.search(
r'Valid for:\s(.*)\sworkflows.', mutation.description
)
assert match
valid_states = set(match.group(1).split(', '))
assert valid_states
assert not valid_states.difference(i.value for i in WorkflowStatus)

0 comments on commit f2f333d

Please sign in to comment.