| 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 |
|
| 18 |
import pytest |
| 19 |
|
| 20 |
from cylc.flow import __version__ |
| 21 |
import cylc.flow.tui.data |
| 22 |
from cylc.flow.tui.data import ( |
| 23 |
_QUERY, |
| 24 |
VersionIncompat, |
| 25 |
generate_mutation, |
| 26 |
get_query, |
| 27 |
) |
| 28 |
|
| 29 |
|
| 30 |
def test_generate_mutation(monkeypatch): |
| 31 |
"""It should produce a GraphQL mutation with the args filled in.""" |
| 32 |
arg_types = { |
| 33 |
'foo': 'String!', |
| 34 |
'bar': '[Int]' |
| 35 |
} |
| 36 |
monkeypatch.setattr(cylc.flow.tui.data, 'ARGUMENT_TYPES', arg_types) |
| 37 |
assert generate_mutation( |
| 38 |
'my_mutation', |
| 39 |
{'foo': 'foo', 'bar': 'bar', 'user': 'user'} |
| 40 |
) == ''' |
| 41 |
mutation($foo: String!, $bar: [Int]) { |
| 42 |
my_mutation (foos: $foo, bars: $bar) { |
| 43 |
result |
| 44 |
} |
| 45 |
} |
| 46 |
''' |
| 47 |
|
| 48 |
|
| 49 |
def test_query_compat(): |
| 50 |
"""It should return a query or raise an exception.""" |
| 51 |
# old version - unsupported |
| 52 |
with pytest.raises(VersionIncompat, match='6.11.4'): |
| 53 |
get_query('6.11.4') |
| 54 |
|
| 55 |
# current version - supported |
| 56 |
assert get_query(__version__) == _QUERY |
| 57 |
|
| 58 |
# future version - supported |
| 59 |
assert get_query('9.0.0') == _QUERY |