Skip to content

Commit 8496bb2

Browse files
stackstorm-neptrKami
authored andcommitted
Reformat all the code using black tool.
1 parent ef6d6e9 commit 8496bb2

File tree

937 files changed

+54139
-42097
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

937 files changed

+54139
-42097
lines changed

contrib/chatops/actions/format_execution_result.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,51 +23,50 @@
2323

2424
class FormatResultAction(Action):
2525
def __init__(self, config=None, action_service=None):
26-
super(FormatResultAction, self).__init__(config=config, action_service=action_service)
27-
api_url = os.environ.get('ST2_ACTION_API_URL', None)
28-
token = os.environ.get('ST2_ACTION_AUTH_TOKEN', None)
26+
super(FormatResultAction, self).__init__(
27+
config=config, action_service=action_service
28+
)
29+
api_url = os.environ.get("ST2_ACTION_API_URL", None)
30+
token = os.environ.get("ST2_ACTION_AUTH_TOKEN", None)
2931
self.client = Client(api_url=api_url, token=token)
3032
self.jinja = jinja_utils.get_jinja_environment(allow_undefined=True)
31-
self.jinja.tests['in'] = lambda item, list: item in list
33+
self.jinja.tests["in"] = lambda item, list: item in list
3234

3335
path = os.path.dirname(os.path.realpath(__file__))
34-
with open(os.path.join(path, 'templates/default.j2'), 'r') as f:
36+
with open(os.path.join(path, "templates/default.j2"), "r") as f:
3537
self.default_template = f.read()
3638

3739
def run(self, execution_id):
3840
execution = self._get_execution(execution_id)
39-
context = {
40-
'six': six,
41-
'execution': execution
42-
}
41+
context = {"six": six, "execution": execution}
4342
template = self.default_template
4443
result = {"enabled": True}
4544

46-
alias_id = execution['context'].get('action_alias_ref', {}).get('id', None)
45+
alias_id = execution["context"].get("action_alias_ref", {}).get("id", None)
4746
if alias_id:
48-
alias = self.client.managers['ActionAlias'].get_by_id(alias_id)
47+
alias = self.client.managers["ActionAlias"].get_by_id(alias_id)
4948

50-
context.update({
51-
'alias': alias
52-
})
49+
context.update({"alias": alias})
5350

54-
result_params = getattr(alias, 'result', None)
51+
result_params = getattr(alias, "result", None)
5552
if result_params:
56-
if not result_params.get('enabled', True):
53+
if not result_params.get("enabled", True):
5754
result["enabled"] = False
5855
else:
59-
if 'format' in alias.result:
60-
template = alias.result['format']
61-
if 'extra' in alias.result:
62-
result['extra'] = jinja_utils.render_values(alias.result['extra'], context)
56+
if "format" in alias.result:
57+
template = alias.result["format"]
58+
if "extra" in alias.result:
59+
result["extra"] = jinja_utils.render_values(
60+
alias.result["extra"], context
61+
)
6362

64-
result['message'] = self.jinja.from_string(template).render(context)
63+
result["message"] = self.jinja.from_string(template).render(context)
6564

6665
return result
6766

6867
def _get_execution(self, execution_id):
6968
if not execution_id:
70-
raise ValueError('Invalid execution_id provided.')
69+
raise ValueError("Invalid execution_id provided.")
7170
execution = self.client.liveactions.get_by_id(id=execution_id)
7271
if not execution:
7372
return None

contrib/chatops/actions/match.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,16 @@
2323
class MatchAction(Action):
2424
def __init__(self, config=None):
2525
super(MatchAction, self).__init__(config=config)
26-
api_url = os.environ.get('ST2_ACTION_API_URL', None)
27-
token = os.environ.get('ST2_ACTION_AUTH_TOKEN', None)
26+
api_url = os.environ.get("ST2_ACTION_API_URL", None)
27+
token = os.environ.get("ST2_ACTION_AUTH_TOKEN", None)
2828
self.client = Client(api_url=api_url, token=token)
2929

3030
def run(self, text):
3131
alias_match = ActionAliasMatch()
3232
alias_match.command = text
33-
matches = self.client.managers['ActionAlias'].match(alias_match)
34-
return {
35-
'alias': _format_match(matches[0]),
36-
'representation': matches[1]
37-
}
33+
matches = self.client.managers["ActionAlias"].match(alias_match)
34+
return {"alias": _format_match(matches[0]), "representation": matches[1]}
3835

3936

4037
def _format_match(match):
41-
return {
42-
'name': match.name,
43-
'pack': match.pack,
44-
'action_ref': match.action_ref
45-
}
38+
return {"name": match.name, "pack": match.pack, "action_ref": match.action_ref}

contrib/chatops/actions/match_and_execute.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,26 @@
1919
from st2common.runners.base_action import Action
2020
from st2client.models.action_alias import ActionAliasMatch
2121
from st2client.models.aliasexecution import ActionAliasExecution
22-
from st2client.commands.action import (LIVEACTION_STATUS_REQUESTED,
23-
LIVEACTION_STATUS_SCHEDULED,
24-
LIVEACTION_STATUS_RUNNING,
25-
LIVEACTION_STATUS_CANCELING)
22+
from st2client.commands.action import (
23+
LIVEACTION_STATUS_REQUESTED,
24+
LIVEACTION_STATUS_SCHEDULED,
25+
LIVEACTION_STATUS_RUNNING,
26+
LIVEACTION_STATUS_CANCELING,
27+
)
2628
from st2client.client import Client
2729

2830

2931
class ExecuteActionAliasAction(Action):
3032
def __init__(self, config=None):
3133
super(ExecuteActionAliasAction, self).__init__(config=config)
32-
api_url = os.environ.get('ST2_ACTION_API_URL', None)
33-
token = os.environ.get('ST2_ACTION_AUTH_TOKEN', None)
34+
api_url = os.environ.get("ST2_ACTION_API_URL", None)
35+
token = os.environ.get("ST2_ACTION_AUTH_TOKEN", None)
3436
self.client = Client(api_url=api_url, token=token)
3537

3638
def run(self, text, source_channel=None, user=None):
3739
alias_match = ActionAliasMatch()
3840
alias_match.command = text
39-
alias, representation = self.client.managers['ActionAlias'].match(
40-
alias_match)
41+
alias, representation = self.client.managers["ActionAlias"].match(alias_match)
4142

4243
execution = ActionAliasExecution()
4344
execution.name = alias.name
@@ -48,20 +49,20 @@ def run(self, text, source_channel=None, user=None):
4849
execution.notification_route = None
4950
execution.user = user
5051

51-
action_exec_mgr = self.client.managers['ActionAliasExecution']
52+
action_exec_mgr = self.client.managers["ActionAliasExecution"]
5253

5354
execution = action_exec_mgr.create(execution)
54-
self._wait_execution_to_finish(execution.execution['id'])
55-
return execution.execution['id']
55+
self._wait_execution_to_finish(execution.execution["id"])
56+
return execution.execution["id"]
5657

5758
def _wait_execution_to_finish(self, execution_id):
5859
pending_statuses = [
5960
LIVEACTION_STATUS_REQUESTED,
6061
LIVEACTION_STATUS_SCHEDULED,
6162
LIVEACTION_STATUS_RUNNING,
62-
LIVEACTION_STATUS_CANCELING
63+
LIVEACTION_STATUS_CANCELING,
6364
]
64-
action_exec_mgr = self.client.managers['LiveAction']
65+
action_exec_mgr = self.client.managers["LiveAction"]
6566
execution = action_exec_mgr.get_by_id(execution_id)
6667
while execution.status in pending_statuses:
6768
time.sleep(1)

contrib/chatops/tests/test_format_result.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,57 +20,53 @@
2020

2121
from format_execution_result import FormatResultAction
2222

23-
__all__ = [
24-
'FormatResultActionTestCase'
25-
]
23+
__all__ = ["FormatResultActionTestCase"]
2624

2725

2826
class FormatResultActionTestCase(BaseActionTestCase):
2927
action_cls = FormatResultAction
3028

3129
def test_rendering_works_remote_shell_cmd(self):
3230
remote_shell_cmd_execution_model = json.loads(
33-
self.get_fixture_content('remote_cmd_execution.json')
31+
self.get_fixture_content("remote_cmd_execution.json")
3432
)
3533

3634
action = self.get_action_instance()
3735
action._get_execution = mock.MagicMock(
3836
return_value=remote_shell_cmd_execution_model
3937
)
40-
result = action.run(execution_id='57967f9355fc8c19a96d9e4f')
38+
result = action.run(execution_id="57967f9355fc8c19a96d9e4f")
4139
self.assertTrue(result)
42-
self.assertIn('web_url', result['message'])
43-
self.assertIn('Took 2s to complete', result['message'])
40+
self.assertIn("web_url", result["message"])
41+
self.assertIn("Took 2s to complete", result["message"])
4442

4543
def test_rendering_local_shell_cmd(self):
4644
local_shell_cmd_execution_model = json.loads(
47-
self.get_fixture_content('local_cmd_execution.json')
45+
self.get_fixture_content("local_cmd_execution.json")
4846
)
4947

5048
action = self.get_action_instance()
5149
action._get_execution = mock.MagicMock(
5250
return_value=local_shell_cmd_execution_model
5351
)
54-
self.assertTrue(action.run(execution_id='5799522f55fc8c2d33ac03e0'))
52+
self.assertTrue(action.run(execution_id="5799522f55fc8c2d33ac03e0"))
5553

5654
def test_rendering_http_request(self):
5755
http_execution_model = json.loads(
58-
self.get_fixture_content('http_execution.json')
56+
self.get_fixture_content("http_execution.json")
5957
)
6058

6159
action = self.get_action_instance()
62-
action._get_execution = mock.MagicMock(
63-
return_value=http_execution_model
64-
)
65-
self.assertTrue(action.run(execution_id='579955f055fc8c2d33ac03e3'))
60+
action._get_execution = mock.MagicMock(return_value=http_execution_model)
61+
self.assertTrue(action.run(execution_id="579955f055fc8c2d33ac03e3"))
6662

6763
def test_rendering_python_action(self):
6864
python_action_execution_model = json.loads(
69-
self.get_fixture_content('python_action_execution.json')
65+
self.get_fixture_content("python_action_execution.json")
7066
)
7167

7268
action = self.get_action_instance()
7369
action._get_execution = mock.MagicMock(
7470
return_value=python_action_execution_model
7571
)
76-
self.assertTrue(action.run(execution_id='5799572a55fc8c2d33ac03ec'))
72+
self.assertTrue(action.run(execution_id="5799572a55fc8c2d33ac03ec"))

contrib/core/actions/generate_uuid.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@
1818

1919
from st2common.runners.base_action import Action
2020

21-
__all__ = [
22-
'GenerateUUID'
23-
]
21+
__all__ = ["GenerateUUID"]
2422

2523

2624
class GenerateUUID(Action):
2725
def run(self, uuid_type):
28-
if uuid_type == 'uuid1':
26+
if uuid_type == "uuid1":
2927
return str(uuid.uuid1())
30-
elif uuid_type == 'uuid4':
28+
elif uuid_type == "uuid4":
3129
return str(uuid.uuid4())
3230
else:
3331
raise ValueError("Unknown uuid_type. Only uuid1 and uuid4 are supported")

contrib/core/actions/inject_trigger.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717

1818
from st2common.runners.base_action import Action
1919

20-
__all__ = [
21-
'InjectTriggerAction'
22-
]
20+
__all__ = ["InjectTriggerAction"]
2321

2422

2523
class InjectTriggerAction(Action):
@@ -34,8 +32,11 @@ def run(self, trigger, payload=None, trace_tag=None):
3432
# results in a TriggerInstanceDB database object creation or not. The object is created
3533
# inside rulesengine service and could fail due to the user providing an invalid trigger
3634
# reference or similar.
37-
self.logger.debug('Injecting trigger "%s" with payload="%s"' % (trigger, str(payload)))
38-
result = client.webhooks.post_generic_webhook(trigger=trigger, payload=payload,
39-
trace_tag=trace_tag)
35+
self.logger.debug(
36+
'Injecting trigger "%s" with payload="%s"' % (trigger, str(payload))
37+
)
38+
result = client.webhooks.post_generic_webhook(
39+
trigger=trigger, payload=payload, trace_tag=trace_tag
40+
)
4041

4142
return result

contrib/core/actions/pause.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
from st2common.runners.base_action import Action
2121

22-
__all__ = [
23-
'PauseAction'
24-
]
22+
__all__ = ["PauseAction"]
2523

2624

2725
class PauseAction(Action):

contrib/core/tests/test_action_inject_trigger.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,50 +27,46 @@
2727
class InjectTriggerActionTestCase(BaseActionTestCase):
2828
action_cls = InjectTriggerAction
2929

30-
@mock.patch('st2common.services.datastore.BaseDatastoreService.get_api_client')
30+
@mock.patch("st2common.services.datastore.BaseDatastoreService.get_api_client")
3131
def test_inject_trigger_only_trigger_no_payload(self, mock_get_api_client):
3232
mock_api_client = mock.Mock()
3333
mock_get_api_client.return_value = mock_api_client
3434

3535
action = self.get_action_instance()
3636

37-
action.run(trigger='dummy_pack.trigger1')
37+
action.run(trigger="dummy_pack.trigger1")
3838
mock_api_client.webhooks.post_generic_webhook.assert_called_with(
39-
trigger='dummy_pack.trigger1',
40-
payload={},
41-
trace_tag=None
39+
trigger="dummy_pack.trigger1", payload={}, trace_tag=None
4240
)
4341

4442
mock_api_client.webhooks.post_generic_webhook.reset()
4543

46-
@mock.patch('st2common.services.datastore.BaseDatastoreService.get_api_client')
44+
@mock.patch("st2common.services.datastore.BaseDatastoreService.get_api_client")
4745
def test_inject_trigger_trigger_and_payload(self, mock_get_api_client):
4846
mock_api_client = mock.Mock()
4947
mock_get_api_client.return_value = mock_api_client
5048

5149
action = self.get_action_instance()
5250

53-
action.run(trigger='dummy_pack.trigger2', payload={'foo': 'bar'})
51+
action.run(trigger="dummy_pack.trigger2", payload={"foo": "bar"})
5452

5553
mock_api_client.webhooks.post_generic_webhook.assert_called_with(
56-
trigger='dummy_pack.trigger2',
57-
payload={'foo': 'bar'},
58-
trace_tag=None
54+
trigger="dummy_pack.trigger2", payload={"foo": "bar"}, trace_tag=None
5955
)
6056

6157
mock_api_client.webhooks.post_generic_webhook.reset()
6258

63-
@mock.patch('st2common.services.datastore.BaseDatastoreService.get_api_client')
59+
@mock.patch("st2common.services.datastore.BaseDatastoreService.get_api_client")
6460
def test_inject_trigger_trigger_payload_trace_tag(self, mock_get_api_client):
6561
mock_api_client = mock.Mock()
6662
mock_get_api_client.return_value = mock_api_client
6763

6864
action = self.get_action_instance()
6965

70-
action.run(trigger='dummy_pack.trigger3', payload={'foo': 'bar'}, trace_tag='Tag1')
66+
action.run(
67+
trigger="dummy_pack.trigger3", payload={"foo": "bar"}, trace_tag="Tag1"
68+
)
7169

7270
mock_api_client.webhooks.post_generic_webhook.assert_called_with(
73-
trigger='dummy_pack.trigger3',
74-
payload={'foo': 'bar'},
75-
trace_tag='Tag1'
71+
trigger="dummy_pack.trigger3", payload={"foo": "bar"}, trace_tag="Tag1"
7672
)

0 commit comments

Comments
 (0)