|
1 | 1 | import json
|
2 | 2 | import typing
|
3 | 3 |
|
4 |
| -from model import AddBlueprintInput |
5 |
| -from model import AddBlueprintMutation |
6 |
| -from model import AddBlueprintPayload |
7 |
| -from model import Blueprint |
8 |
| -from model import BlueprintConnection |
9 |
| -from model import BlueprintEdge |
10 |
| -from model import BlueprintsQuery |
11 | 4 | from pydantic import Field
|
12 |
| -from render_models import AllocationStrategy |
13 |
| -from render_models import ClaimResourceMutation |
14 |
| -from render_models import PageInfoSchedule |
15 |
| -from render_models import Resource |
16 |
| -from render_models import ResourcePool |
17 |
| -from render_models import ResourcePoolConnection |
18 |
| -from render_models import ResourcePoolEdge |
19 |
| -from render_models import Schedule |
20 |
| -from render_models import ScheduleConnection |
21 |
| -from render_models import ScheduleEdge |
22 |
| -from render_models import SchedulesFilterInput |
23 |
| -from render_models import SchedulesQuery |
24 |
| -from render_models import SearchPoolsByTagsQuery |
25 |
| -from render_models import TagAnd |
26 |
| -from render_models import TagOr |
27 | 5 |
|
28 | 6 | import graphql_pydantic_converter.graphql_types
|
29 | 7 | from graphql_pydantic_converter.graphql_types import ENUM
|
30 | 8 | from graphql_pydantic_converter.graphql_types import Input
|
31 | 9 | from graphql_pydantic_converter.schema_converter import GraphqlJsonParser
|
32 | 10 |
|
| 11 | +from .model import AddBlueprintInput |
| 12 | +from .model import AddBlueprintMutation |
| 13 | +from .model import AddBlueprintPayload |
| 14 | +from .model import Blueprint |
| 15 | +from .model import BlueprintConnection |
| 16 | +from .model import BlueprintEdge |
| 17 | +from .model import BlueprintsQuery |
| 18 | +from .model import BlueprintsQueryResponse |
| 19 | +from .render_models import AllocationStrategy |
| 20 | +from .render_models import ClaimResourceMutation |
| 21 | +from .render_models import PageInfoSchedule |
| 22 | +from .render_models import Resource |
| 23 | +from .render_models import ResourcePool |
| 24 | +from .render_models import ResourcePoolConnection |
| 25 | +from .render_models import ResourcePoolEdge |
| 26 | +from .render_models import Schedule |
| 27 | +from .render_models import ScheduleConnection |
| 28 | +from .render_models import ScheduleEdge |
| 29 | +from .render_models import SchedulesFilterInput |
| 30 | +from .render_models import SchedulesQuery |
| 31 | +from .render_models import SearchPoolsByTagsQuery |
| 32 | +from .render_models import TagAnd |
| 33 | +from .render_models import TagOr |
| 34 | + |
33 | 35 |
|
34 | 36 | class TestTaskGenerator:
|
35 | 37 | def test_render_json(self) -> None:
|
@@ -131,6 +133,38 @@ class AddDeviceInput(Input):
|
131 | 133 |
|
132 | 134 | assert reference == mutation
|
133 | 135 |
|
| 136 | + json_blueprint = 'tests/blueprint.json' |
| 137 | + |
| 138 | + with open(json_blueprint) as json_file: |
| 139 | + device_import_json = json_file.read() |
| 140 | + template = device_import_json |
| 141 | + |
| 142 | + mutation = AddBlueprintMutation( |
| 143 | + payload=AddBlueprintPayload( |
| 144 | + blueprint=Blueprint( |
| 145 | + id=True, |
| 146 | + name=True, |
| 147 | + template=True |
| 148 | + ) |
| 149 | + ), |
| 150 | + input=AddBlueprintInput( |
| 151 | + name='blueprint', |
| 152 | + template=template, |
| 153 | + ) |
| 154 | + ).render() |
| 155 | + |
| 156 | + reference = ('mutation { addBlueprint ( input: { name: "blueprint", template: "{\n\t\"cli\": ' |
| 157 | + '{\n\t\t\"cli-topology:host\": \"sample-topology\",\n\t\t\"cli-topology:port\": ' |
| 158 | + '\"{{port}}\",\n\t\t\"cli-topology:transport-type\": \"ssh\",\n\t\t\"cli-topology:device-type\": ' |
| 159 | + '\"{{device_type}}\",\n\t\t\"cli-topology:device-version\": ' |
| 160 | + '\"{{device_version}}\",\n\t\t\"cli-topology:password\": ' |
| 161 | + '\"{{password}}\",\n\t\t\"cli-topology:username\": ' |
| 162 | + '\"{{username}}\",\n\t\t\"cli-topology:journal-size\": ' |
| 163 | + '500,\n\t\t\"cli-topology:dry-run-journal-size\": 180,\n\t\t\"cli-topology:parsing-engine\": ' |
| 164 | + '\"tree-parser\"\n\t}\n}" }) { blueprint { id name template } } }') |
| 165 | + |
| 166 | + assert reference == mutation |
| 167 | + |
134 | 168 | def test_render_input_advanced(self) -> None:
|
135 | 169 | query = SearchPoolsByTagsQuery(
|
136 | 170 | tags=TagOr(
|
@@ -202,7 +236,6 @@ def test_render_input_advanced(self) -> None:
|
202 | 236 | assert reference == query_render
|
203 | 237 |
|
204 | 238 | def test_parse_response(self) -> None:
|
205 |
| - from model import BlueprintsQueryResponse |
206 | 239 |
|
207 | 240 | response: typing.Any = {
|
208 | 241 | 'data': {
|
@@ -253,7 +286,9 @@ def test_multiple_query(self) -> None:
|
253 | 286 |
|
254 | 287 | query_second = SchedulesQuery(
|
255 | 288 | payload=ScheduleConnection(
|
| 289 | + __typename=True, |
256 | 290 | pageInfo=PageInfoSchedule(
|
| 291 | + __typename=True, |
257 | 292 | hasNextPage=True,
|
258 | 293 | hasPreviousPage=True,
|
259 | 294 | startCursor=True,
|
@@ -285,9 +320,9 @@ def test_multiple_query(self) -> None:
|
285 | 320 | reference = '{ SearchPoolsByTags ( tags: { matchesAny: [ { matchesAll: [ "root_pool" ] } ] } ) ' \
|
286 | 321 | '{ edges { node { AllocationStrategy { Name } ' \
|
287 | 322 | 'Name PoolProperties PoolType id } } totalCount } schedules ( after: "aaa", first: 10, filter: ' \
|
288 |
| - '{ workflowName: "TEST_A" , workflowVersion: "1" } ) { edges { node { name enabled ' \ |
| 323 | + '{ workflowName: "TEST_A" , workflowVersion: "1" } ) { __typename edges { node { name enabled ' \ |
289 | 324 | 'cronString } cursor } ' \
|
290 |
| - 'pageInfo { hasNextPage hasPreviousPage startCursor endCursor } totalCount } }' |
| 325 | + 'pageInfo { __typename hasNextPage hasPreviousPage startCursor endCursor } totalCount } }' |
291 | 326 |
|
292 | 327 | merged_query = graphql_pydantic_converter.graphql_types.concatenate_queries(queries)
|
293 | 328 | assert reference == merged_query
|
0 commit comments