-
-
Notifications
You must be signed in to change notification settings - Fork 775
GET entrypoint of a workflow from st2client #4791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1e8aa64
Add ActionResourceManager and implement GET entrypoint
trstruth eaa0076
Update CHANGELOG to reflect new feature
trstruth fcf6fe0
Add unit tests for the new ActionResourceManager methods
trstruth 622fbfc
Assert correctness of return value and add 404 test
trstruth 150aafe
Use assertRaisesRegexp
trstruth 6a86330
Merge branch 'master' into trstruth/entrypoint
trstruth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # Copyright 2019 Extreme Networks, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from __future__ import absolute_import | ||
|
|
||
| import json | ||
| import logging | ||
| import mock | ||
| import unittest2 | ||
|
|
||
| from tests import base | ||
|
|
||
| from st2client import client | ||
| from st2client.utils import httpclient | ||
|
|
||
|
|
||
| LOG = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| EXECUTION = { | ||
| "id": 12345, | ||
| "action": { | ||
| "ref": "mock.foobar" | ||
| }, | ||
| "status": "failed", | ||
| "result": "non-empty" | ||
| } | ||
|
|
||
| ENTRYPOINT = ( | ||
| "version: 1.0" | ||
|
|
||
| "description: A basic workflow that runs an arbitrary linux command." | ||
|
|
||
| "input:" | ||
| " - cmd" | ||
| " - timeout" | ||
|
|
||
| "tasks:" | ||
| " task1:" | ||
| " action: core.local cmd=<% ctx(cmd) %> timeout=<% ctx(timeout) %>" | ||
| " next:" | ||
| " - when: <% succeeded() %>" | ||
| " publish:" | ||
| " - stdout: <% result().stdout %>" | ||
| " - stderr: <% result().stderr %>" | ||
|
|
||
| "output:" | ||
| " - stdout: <% ctx(stdout) %>" | ||
| ) | ||
|
|
||
|
|
||
| class TestActionResourceManager(unittest2.TestCase): | ||
|
|
||
| @classmethod | ||
| def setUpClass(cls): | ||
| super(TestActionResourceManager, cls).setUpClass() | ||
| cls.client = client.Client() | ||
|
|
||
| @mock.patch.object( | ||
| httpclient.HTTPClient, 'get', | ||
| mock.MagicMock(return_value=base.FakeResponse(json.dumps(ENTRYPOINT), 200, 'OK'))) | ||
| def test_get_action_entry_point_by_ref(self): | ||
| actual_entrypoint = self.client.actions.get_entrypoint(EXECUTION['action']['ref']) | ||
| actual_entrypoint = json.loads(actual_entrypoint) | ||
|
|
||
| endpoint = '/actions/views/entry_point/%s' % EXECUTION['action']['ref'] | ||
| httpclient.HTTPClient.get.assert_called_with(endpoint) | ||
|
|
||
| self.assertEqual(ENTRYPOINT, actual_entrypoint) | ||
|
|
||
| @mock.patch.object( | ||
| httpclient.HTTPClient, 'get', | ||
| mock.MagicMock(return_value=base.FakeResponse(json.dumps(ENTRYPOINT), 200, 'OK'))) | ||
| def test_get_action_entry_point_by_id(self): | ||
| actual_entrypoint = self.client.actions.get_entrypoint(EXECUTION['id']) | ||
| actual_entrypoint = json.loads(actual_entrypoint) | ||
|
|
||
| endpoint = '/actions/views/entry_point/%s' % EXECUTION['id'] | ||
| httpclient.HTTPClient.get.assert_called_with(endpoint) | ||
|
|
||
| self.assertEqual(ENTRYPOINT, actual_entrypoint) | ||
|
|
||
| @mock.patch.object( | ||
| httpclient.HTTPClient, 'get', | ||
| mock.MagicMock(return_value=base.FakeResponse( | ||
| json.dumps({}), 404, '404 Client Error: Not Found' | ||
| ))) | ||
| def test_get_non_existent_action_entry_point(self): | ||
| with self.assertRaisesRegexp(Exception, '404 Client Error: Not Found'): | ||
| self.client.actions.get_entrypoint('nonexistentpack.nonexistentaction') | ||
|
|
||
| endpoint = '/actions/views/entry_point/%s' % 'nonexistentpack.nonexistentaction' | ||
| httpclient.HTTPClient.get.assert_called_with(endpoint) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a unit tests where the status code from the API call is not OK/200.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a commit for this, but not sure if I implemented it correctly, please let me know if I should take a different approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use
assertRaisesRegexpand check that the error message is actually Not Found returned in the FakeResponse? Search forassertRaisesRegexpin st2 and you will see plenty of examples.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m4dcoder sorry for the delay, I've pushed a commit to use that method. Please let me know if it's not correct.