From 858d824ea0638834e7faa9f08f755b04a51d7bb9 Mon Sep 17 00:00:00 2001 From: yuximiao Date: Sat, 30 May 2020 14:42:38 +0800 Subject: [PATCH] fix function too long --- mindinsight/profiler/common/validator/validate.py | 2 +- .../ut/backend/profiler/test_profiler_restful_api.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/mindinsight/profiler/common/validator/validate.py b/mindinsight/profiler/common/validator/validate.py index 68a3aef..1da0276 100644 --- a/mindinsight/profiler/common/validator/validate.py +++ b/mindinsight/profiler/common/validator/validate.py @@ -133,7 +133,7 @@ def validate_sort_condition(search_condition, search_scope): if "type" in sort_condition: sorted_type_param = ['ascending', 'descending'] sorted_type = sort_condition.get("type") - if sorted_type not in sorted_type_param: + if sorted_type and sorted_type not in sorted_type_param: err_msg = "The sorted type must be ascending or descending." log.error(err_msg) raise ProfilerSortConditionException(err_msg) diff --git a/tests/ut/backend/profiler/test_profiler_restful_api.py b/tests/ut/backend/profiler/test_profiler_restful_api.py index 2783940..3e96b68 100644 --- a/tests/ut/backend/profiler/test_profiler_restful_api.py +++ b/tests/ut/backend/profiler/test_profiler_restful_api.py @@ -50,17 +50,14 @@ class TestProfilerRestfulApi(TestCase): self.assertEqual(200, response.status_code) self.assertDictEqual(expect_result, response.get_json()) - @mock.patch('mindinsight.backend.lineagemgr.lineage_api.settings') @mock.patch('mindinsight.profiler.analyser.base_analyser.BaseAnalyser.query') def test_ops_search_failed(self, *args): """Test the failed of ops/search.""" - base_dir = '/path/to/test_profiler_base' expect_result = { 'object': ["test"], 'count': 1 } args[0].return_value = expect_result - args[1].SUMMARY_BASE_DIR = base_dir response = self.app_client.post(self.url, data=json.dumps(1)) self.assertEqual(400, response.status_code) expect_result = { @@ -89,6 +86,14 @@ class TestProfilerRestfulApi(TestCase): del result["error_msg"] self.assertDictEqual(expect_result, result) + @mock.patch('mindinsight.profiler.analyser.base_analyser.BaseAnalyser.query') + def test_ops_search_search_condition_failed(self, *args): + """Test search condition error.""" + expect_result = { + 'object': ["test"], + 'count': 1 + } + args[0].return_value = expect_result body_data = {"op_type": "aicore_type", "device_id": "1", "group_condition": 1} response = self.app_client.post(self.url, data=json.dumps(body_data)) self.assertEqual(400, response.status_code) -- GitLab