From f0d3f2e092a154a59ace8dfe6c10a1e00a0af516 Mon Sep 17 00:00:00 2001 From: Eyal Date: Tue, 4 Feb 2020 14:45:26 +0200 Subject: [PATCH] Remove some pycharm warnings * Mutable default arg * Use of reserved names as parameters * Missing requirements * Unused parameters * use static method * Doc errors Change-Id: Iaf7efa263398005ba1fa7261c894c85cb2fbcf47 --- doc/source/conf.py | 3 +-- doc/source/installation.rst | 1 + mistral_tempest_tests/README.rst | 1 + mistral_tempest_tests/services/base.py | 4 +-- .../services/v2/mistral_client.py | 8 ++++-- .../tests/api/v2/test_action_executions.py | 3 --- .../tests/api/v2/test_actions.py | 9 ++++--- .../tests/api/v2/test_executions.py | 6 ++--- .../tests/api/v2/test_workflows.py | 26 +++++++------------ .../v2/test_multi_vim_authentication.py | 4 ++- .../engine/actions/v2/test_ssh_actions.py | 3 ++- requirements.txt | 1 + 12 files changed, 35 insertions(+), 34 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index c3cdb16..2e65783 100755 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -23,7 +23,6 @@ sys.path.insert(0, os.path.abspath('../..')) extensions = [ 'sphinx.ext.autodoc', 'openstackdocstheme', - #'sphinx.ext.intersphinx', ] # autodoc generation is a bit aggressive and a nuisance when doing heavy @@ -78,4 +77,4 @@ latex_documents = [ ] # Example configuration for intersphinx: refer to the Python standard library. -#intersphinx_mapping = {'http://docs.python.org/': None} +# intersphinx_mapping = {'http://docs.python.org/': None} diff --git a/doc/source/installation.rst b/doc/source/installation.rst index e914e6c..cb477fc 100644 --- a/doc/source/installation.rst +++ b/doc/source/installation.rst @@ -11,3 +11,4 @@ At the command line:: $ git clone https://opendev.org/openstack/mistral-tempest-plugin $ cd mistral-tempest-plugin/ $ pip install -e . + diff --git a/mistral_tempest_tests/README.rst b/mistral_tempest_tests/README.rst index 1a517fa..4a62873 100644 --- a/mistral_tempest_tests/README.rst +++ b/mistral_tempest_tests/README.rst @@ -23,3 +23,4 @@ Alternatively, to run mistral tempest plugin tests using tox, go to tempest dire And, to run a specific test:: $ tox -eall-plugin mistral_tempest_tests.tests.api.v2.test_mistral_basic_v2.WorkbookTestsV2.test_get_workbook + diff --git a/mistral_tempest_tests/services/base.py b/mistral_tempest_tests/services/base.py index 1e3f02e..dee81ac 100644 --- a/mistral_tempest_tests/services/base.py +++ b/mistral_tempest_tests/services/base.py @@ -93,8 +93,8 @@ class MistralClientBase(rest_client.RestClient): return self.delete('{obj}/{name}'.format(obj=obj, name=name)) - def get_object(self, obj, id): - resp, body = self.get('{obj}/{id}'.format(obj=obj, id=id)) + def get_object(self, obj, _id): + resp, body = self.get('{obj}/{id}'.format(obj=obj, id=_id)) return resp, jsonutils.loads(body) diff --git a/mistral_tempest_tests/services/v2/mistral_client.py b/mistral_tempest_tests/services/v2/mistral_client.py index c9f3b37..4a3c2ce 100644 --- a/mistral_tempest_tests/services/v2/mistral_client.py +++ b/mistral_tempest_tests/services/v2/mistral_client.py @@ -37,7 +37,9 @@ class MistralClientV2(base.MistralClientBase): return self.get(url_path, headers=headers) - def post_json(self, url_path, obj, extra_headers={}): + def post_json(self, url_path, obj, extra_headers=None): + if extra_headers is None: + extra_headers = {} headers = {"Content-Type": "application/json"} headers = dict(headers, **extra_headers) return self.post(url_path, @@ -195,7 +197,9 @@ class MistralClientV2(base.MistralClientBase): return [t for t in all_tasks if t['workflow_name'] == wf_name] - def create_action_execution(self, request_body, extra_headers={}): + def create_action_execution(self, request_body, extra_headers=None): + if extra_headers is None: + extra_headers = {} resp, body = self.post_json('action_executions', request_body, extra_headers) diff --git a/mistral_tempest_tests/tests/api/v2/test_action_executions.py b/mistral_tempest_tests/tests/api/v2/test_action_executions.py index 271469d..a794d4f 100644 --- a/mistral_tempest_tests/tests/api/v2/test_action_executions.py +++ b/mistral_tempest_tests/tests/api/v2/test_action_executions.py @@ -244,9 +244,6 @@ class ActionExecutionTestsV2(base.TestCase): 'action_executions?include_output=true&task_execution_id=%s' % task_id) - self.assertEqual(200, resp.status) - action_execution = body['action_executions'][0] - self.assertEqual(200, resp.status) action_execution = body['action_executions'][0] self.assertEqual(wf_namespace, action_execution['workflow_namespace']) diff --git a/mistral_tempest_tests/tests/api/v2/test_actions.py b/mistral_tempest_tests/tests/api/v2/test_actions.py index 3f21d1f..e9295ae 100644 --- a/mistral_tempest_tests/tests/api/v2/test_actions.py +++ b/mistral_tempest_tests/tests/api/v2/test_actions.py @@ -24,7 +24,8 @@ class ActionTestsV2(base.TestCase): _service = 'workflowv2' - def get_field_value(self, body, act_name, field): + @staticmethod + def get_field_value(body, act_name, field): return [body['actions'][i][field] for i in range(len(body['actions'])) if body['actions'][i]['name'] == act_name][0] @@ -57,10 +58,10 @@ class ActionTestsV2(base.TestCase): self.assertIn('next', body) name_1 = body['actions'][0].get('name') - next = body.get('next') + next_ = body.get('next') param_dict = utils.get_dict_from_string( - next.split('?')[1], + next_.split('?')[1], delimiter='&' ) @@ -75,7 +76,7 @@ class ActionTestsV2(base.TestCase): self.assertDictContainsSubset(expected_sub_dict, param_dict) # Query again using 'next' hint - url_param = next.split('/')[-1] + url_param = next_.split('/')[-1] resp, body = self.client.get_list_obj(url_param) self.assertEqual(200, resp.status) diff --git a/mistral_tempest_tests/tests/api/v2/test_executions.py b/mistral_tempest_tests/tests/api/v2/test_executions.py index a4aa232..a166a2b 100644 --- a/mistral_tempest_tests/tests/api/v2/test_executions.py +++ b/mistral_tempest_tests/tests/api/v2/test_executions.py @@ -81,9 +81,9 @@ class ExecutionTestsV2(base.TestCase): self.assertIn('next', body) workflow_name_1 = body['executions'][0].get('workflow_name') - next = body.get('next') + next_ = body.get('next') param_dict = utils.get_dict_from_string( - next.split('?')[1], + next_.split('?')[1], delimiter='&' ) @@ -100,7 +100,7 @@ class ExecutionTestsV2(base.TestCase): ) # Query again using 'next' link - url_param = next.split('/')[-1] + url_param = next_.split('/')[-1] resp, body = self.client.get_list_obj(url_param) self.assertEqual(200, resp.status) diff --git a/mistral_tempest_tests/tests/api/v2/test_workflows.py b/mistral_tempest_tests/tests/api/v2/test_workflows.py index 9eebb4b..60641c6 100644 --- a/mistral_tempest_tests/tests/api/v2/test_workflows.py +++ b/mistral_tempest_tests/tests/api/v2/test_workflows.py @@ -129,10 +129,10 @@ class WorkflowTestsV2(base.TestCase): self.assertIn('next', body) name_1 = body['workflows'][0].get('name') - next = body.get('next') + next_ = body.get('next') param_dict = utils.get_dict_from_string( - next.split('?')[1], + next_.split('?')[1], delimiter='&' ) @@ -147,7 +147,7 @@ class WorkflowTestsV2(base.TestCase): self.assertDictContainsSubset(expected_sub_dict, param_dict) # Query again using 'next' hint - url_param = next.split('/')[-1] + url_param = next_.split('/')[-1] resp, body = self.client.get_list_obj(url_param) self.assertEqual(200, resp.status) @@ -256,13 +256,13 @@ class WorkflowTestsV2(base.TestCase): namespace=namespace ) name = body['workflows'][0]['name'] - id = body['workflows'][0]['id'] + wf_id = body['workflows'][0]['id'] self.assertEqual(201, resp.status) self.assertEqual(name, body['workflows'][0]['name']) resp, body = self.client.get_workflow( - id + wf_id ) self.assertEqual(namespace, body['namespace']) @@ -279,12 +279,12 @@ class WorkflowTestsV2(base.TestCase): namespace=namespace ) name = body['workflows'][0]['name'] - id = body['workflows'][0]['id'] + wf_id = body['workflows'][0]['id'] self.assertEqual(201, resp.status) self.assertEqual(name, body['workflows'][0]['name']) - resp, body = self.client.get_workflow(id) + resp, body = self.client.get_workflow(wf_id) self.assertEqual(namespace, body['namespace']) @@ -294,7 +294,7 @@ class WorkflowTestsV2(base.TestCase): 'single_wf.yaml' ) - resp, body = self.client.get_workflow(id) + resp, body = self.client.get_workflow(wf_id) self.assertEqual(200, resp.status) @decorators.attr(type='sanity') @@ -373,8 +373,7 @@ class WorkflowTestsV2(base.TestCase): tr_name = 'trigger' resp, body = self.client.create_workflow('wf_v2.yaml') name = body['workflows'][0]['name'] - resp, body = self.client.create_cron_trigger( - tr_name, name, None, '5 * * * *') + self.client.create_cron_trigger(tr_name, name, None, '5 * * * *') try: self.assertRaises( @@ -414,12 +413,7 @@ class WorkflowTestsV2(base.TestCase): tr_name = 'trigger' _, body = self.client.create_workflow('wf_v2.yaml', scope='public') name = body['workflows'][0]['name'] - resp, body = self.alt_client.create_cron_trigger( - tr_name, - name, - None, - '5 * * * *' - ) + self.alt_client.create_cron_trigger(tr_name, name, None, '5 * * * *') try: exception = self.assertRaises( diff --git a/mistral_tempest_tests/tests/scenario/engine/actions/v2/test_multi_vim_authentication.py b/mistral_tempest_tests/tests/scenario/engine/actions/v2/test_multi_vim_authentication.py index 641afab..cf5b4eb 100644 --- a/mistral_tempest_tests/tests/scenario/engine/actions/v2/test_multi_vim_authentication.py +++ b/mistral_tempest_tests/tests/scenario/engine/actions/v2/test_multi_vim_authentication.py @@ -113,7 +113,9 @@ def _extract_target_headers_from_client(client): } -def _execute_action(client, request, extra_headers={}): +def _execute_action(client, request, extra_headers=None): + if extra_headers is None: + extra_headers = {} _, result = client.create_action_execution( request, extra_headers=extra_headers diff --git a/mistral_tempest_tests/tests/scenario/engine/actions/v2/test_ssh_actions.py b/mistral_tempest_tests/tests/scenario/engine/actions/v2/test_ssh_actions.py index 3c3a84b..3bee506 100644 --- a/mistral_tempest_tests/tests/scenario/engine/actions/v2/test_ssh_actions.py +++ b/mistral_tempest_tests/tests/scenario/engine/actions/v2/test_ssh_actions.py @@ -94,7 +94,8 @@ class SSHActionsTestsV2(base.TestCaseAdvanced): return ip - def _wait_until_server_up(self, server_ip, timeout=120, delay=2): + @staticmethod + def _wait_until_server_up(server_ip, timeout=120, delay=2): seconds_remain = timeout LOG.info("Waiting server SSH [IP=%s]...", server_ip) diff --git a/requirements.txt b/requirements.txt index 8a6bab6..d3fa52e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,4 +12,5 @@ paramiko>=2.0.0 # LGPLv2.1+ six>=1.10.0 # MIT mock>=2.0.0 # BSD tempest>=17.1.0 # Apache-2.0 +testtools>=2.2.0 # MIT python-keystoneclient>=3.8.0 # Apache-2.0