Skip to content

Commit 31810fe

Browse files
committed
use a fixture for pylint_plugins_test
1 parent 9d0be4e commit 31810fe

File tree

4 files changed

+178
-3
lines changed

4 files changed

+178
-3
lines changed

pylint_plugins/api_models_test.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,19 @@
2525
try:
2626
# TODO: remove this once we remove the Makefile
2727
from . import api_models
28+
from .fixtures.api_models import DEFAULT_PACK_NAME
29+
30+
# FIXTURE_MODULE_ACTION="st2common.models.api.action"
31+
# FIXTURE_MODULE_TRIGGER="st2common.models.api.trigger"
32+
FIXTURE_MODULE_ACTION = "pylint_plugins.fixtures.api_models"
33+
FIXTURE_MODULE_TRIGGER = "pylint_plugins.fixtures.api_models"
2834
except ImportError:
2935
# pylint_plugins is on PYTHONPATH
3036
import api_models
3137

38+
FIXTURE_MODULE_ACTION = "fixtures.api_models"
39+
FIXTURE_MODULE_TRIGGER = "fixtures.api_models"
40+
3241

3342
def test_skiplist_class_gets_skipped():
3443
# roughly based on st2api/st2api/controllers/v1/actionexecutions.py
@@ -135,12 +144,13 @@ class ActionCreateAPI(object):
135144
def test_copied_imported_schema():
136145
code = """
137146
import copy
138-
from st2common.models.api.action import ActionAPI
147+
from %s import ActionAPI
139148
140149
class ActionCreateAPI(object):
141150
schema = copy.deepcopy(ActionAPI.schema)
142151
schema["properties"]["default_files"] = {}
143152
"""
153+
code = code % FIXTURE_MODULE_ACTION
144154

145155
res = parse(code)
146156

@@ -163,13 +173,14 @@ class ActionCreateAPI(object):
163173
def test_indirect_copied_schema():
164174
code = """
165175
import copy
166-
from st2common.models.api.action import ActionAPI
176+
from %s import ActionAPI
167177
168178
REQUIRED_ATTR_SCHEMAS = {"action": copy.deepcopy(ActionAPI.schema)}
169179
170180
class ExecutionAPI(object):
171181
schema = {"properties": {"action": REQUIRED_ATTR_SCHEMAS["action"]}}
172182
"""
183+
code = code % FIXTURE_MODULE_ACTION
173184

174185
res = parse(code)
175186

@@ -187,11 +198,12 @@ class ExecutionAPI(object):
187198

188199
def test_inlined_schema():
189200
code = """
190-
from st2common.models.api.trigger import TriggerAPI
201+
from %s import TriggerAPI
191202
192203
class ActionExecutionAPI(object):
193204
schema = {"properties": {"trigger": TriggerAPI.schema}}
194205
"""
206+
code = code % FIXTURE_MODULE_TRIGGER
195207

196208
res = parse(code)
197209

pylint_plugins/fixtures/BUILD

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
python_test_utils(
2+
sources=["*.py"],
3+
skip_pylint=True,
4+
)

pylint_plugins/fixtures/__init__.py

Whitespace-only changes.

pylint_plugins/fixtures/api_models.py

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# Copyright 2022 The StackStorm Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
import abc
17+
18+
DEFAULT_PACK_NAME = "default"
19+
20+
21+
NotificationSubSchemaAPI = {
22+
"type": "object",
23+
"properties": {
24+
"message": {"type": "string", "description": "Message to use for notification"},
25+
"data": {
26+
"type": "object",
27+
"description": "Data to be sent as part of notification",
28+
},
29+
"routes": {
30+
"type": "array",
31+
"description": "Channels to post notifications to.",
32+
},
33+
"channels": { # Deprecated. Only here for backward compatibility.
34+
"type": "array",
35+
"description": "Channels to post notifications to.",
36+
},
37+
},
38+
"additionalProperties": False,
39+
}
40+
41+
42+
def get_schema(**kwargs):
43+
return {}
44+
45+
46+
# copied from st2common.models.api.base
47+
class BaseAPI(abc.ABC):
48+
schema = abc.abstractproperty
49+
name = None
50+
51+
52+
# copied from st2common.models.api.action
53+
class ActionAPI(BaseAPI):
54+
"""
55+
The system entity that represents a Stack Action/Automation in the system.
56+
"""
57+
58+
schema = {
59+
"title": "Action",
60+
"description": "An activity that happens as a response to the external event.",
61+
"type": "object",
62+
"properties": {
63+
"id": {
64+
"description": "The unique identifier for the action.",
65+
"type": "string",
66+
},
67+
"ref": {
68+
"description": "System computed user friendly reference for the action. \
69+
Provided value will be overridden by computed value.",
70+
"type": "string",
71+
},
72+
"uid": {"type": "string"},
73+
"name": { # used in test
74+
"description": "The name of the action.",
75+
"type": "string",
76+
"required": True,
77+
},
78+
"description": { # used in test
79+
"description": "The description of the action.",
80+
"type": "string",
81+
},
82+
"enabled": {
83+
"description": "Enable or disable the action from invocation.",
84+
"type": "boolean",
85+
"default": True,
86+
},
87+
"runner_type": { # used in test
88+
"description": "The type of runner that executes the action.",
89+
"type": "string",
90+
"required": True,
91+
},
92+
"entry_point": {
93+
"description": "The entry point for the action.",
94+
"type": "string",
95+
"default": "",
96+
},
97+
"pack": {
98+
"description": "The content pack this action belongs to.",
99+
"type": "string",
100+
"default": DEFAULT_PACK_NAME,
101+
},
102+
"parameters": {
103+
"description": "Input parameters for the action.",
104+
"type": "object",
105+
"patternProperties": {r"^\w+$": get_schema()},
106+
"additionalProperties": False,
107+
"default": {},
108+
},
109+
"output_schema": get_schema(description="Action Output Schema"),
110+
"tags": {
111+
"description": "User associated metadata assigned to this object.",
112+
"type": "array",
113+
"items": {"type": "object"},
114+
},
115+
"notify": {
116+
"description": "Notification settings for action.",
117+
"type": "object",
118+
"properties": {
119+
"on-complete": NotificationSubSchemaAPI,
120+
"on-failure": NotificationSubSchemaAPI,
121+
"on-success": NotificationSubSchemaAPI,
122+
},
123+
"additionalProperties": False,
124+
},
125+
"metadata_file": {
126+
"description": "Path to the metadata file relative to the pack directory.",
127+
"type": "string",
128+
"default": "",
129+
},
130+
},
131+
"additionalProperties": False,
132+
}
133+
134+
135+
class TriggerTypeAPI(BaseAPI):
136+
schema = {
137+
"type": "object",
138+
"properties": {
139+
"id": {"type": "string", "default": None},
140+
"ref": {"type": "string"},
141+
"uid": {"type": "string"},
142+
"name": {"type": "string", "required": True},
143+
"pack": {"type": "string"},
144+
"description": {"type": "string"},
145+
"payload_schema": {"type": "object", "default": {}},
146+
"parameters_schema": {"type": "object", "default": {}},
147+
"tags": {
148+
"description": "User associated metadata assigned to this object.",
149+
"type": "array",
150+
"items": {"type": "object"},
151+
},
152+
"metadata_file": {
153+
"description": "Path to the metadata file relative to the pack directory.",
154+
"type": "string",
155+
"default": "",
156+
},
157+
},
158+
"additionalProperties": False,
159+
}

0 commit comments

Comments
 (0)