summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgengchc2 <geng.changcai2@zte.com.cn>2018-12-26 16:53:57 -0800
committergengchc2 <geng.changcai2@zte.com.cn>2018-12-26 16:53:57 -0800
commitedb258dbb6bcdb3bdf414ecd26cefa2d9fe55dbc (patch)
treeae1be518b9635302619655f5b9d112321e44c23b
parent0f7c37c7765a2905bfad834f82d9ec982a2c0763 (diff)
Add raise unit test for search tuple in sqlalchemy
Notes
Notes (review): Code-Review+2: Carl Caihui <cai.hui@zte.com.cn> Workflow+1: Carl Caihui <cai.hui@zte.com.cn> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Thu, 27 Dec 2018 10:32:43 +0000 Reviewed-on: https://review.openstack.org/627429 Project: openstack/freezer-api Branch: refs/heads/master
-rw-r--r--freezer_api/tests/unit/sqlalchemy/v1/test_api_common.py27
-rw-r--r--freezer_api/tests/unit/sqlalchemy/v2/test_api_common.py27
2 files changed, 54 insertions, 0 deletions
diff --git a/freezer_api/tests/unit/sqlalchemy/v1/test_api_common.py b/freezer_api/tests/unit/sqlalchemy/v1/test_api_common.py
index 29fb419..4b37556 100644
--- a/freezer_api/tests/unit/sqlalchemy/v1/test_api_common.py
+++ b/freezer_api/tests/unit/sqlalchemy/v1/test_api_common.py
@@ -168,3 +168,30 @@ class ApiTestCase(base.DbTestCase):
168 self.assertRaises(freezer_api_exc.StorageEngineError, 168 self.assertRaises(freezer_api_exc.StorageEngineError,
169 api.replace_tuple, models.Job, self.fake_user_id, 169 api.replace_tuple, models.Job, self.fake_user_id,
170 self.fake_job_id, mock_tuple_values) 170 self.fake_job_id, mock_tuple_values)
171
172 @patch('oslo_db.sqlalchemy.utils.model_query')
173 def test_raises_search_tuple(self, mock_model_query):
174 mock_tablename = mock.MagicMock()
175 mock_tablename = mock.MagicMock()
176 mock_search = mock.MagicMock()
177 mock_model_query.side_effect = Exception('regular test failure')
178 self.assertRaises(freezer_api_exc.StorageEngineError,
179 api.search_tuple, mock_tablename, self.fake_user_id,
180 offset=0, limit=100,
181 search=mock_search)
182
183 def test_valid_and_get_search_option(self):
184 search = {'error_key': 'search_info_error'}
185 result = api.valid_and_get_search_option(search)
186 self.assertEqual({}, result)
187
188 def test_get_recursively_list_include_dict(self):
189 dict1 = {'key1': [{'key11': {'key111': 111}},
190 {'key12': {'key121': 121}}],
191 'key2': 2
192 }
193 search_key = {'key111': 111,
194 'key121': 121,
195 'key2': 2}
196 search_keys_found = api.get_recursively(dict1, search_key)
197 self.assertEqual(search_key, search_keys_found)
diff --git a/freezer_api/tests/unit/sqlalchemy/v2/test_api_common.py b/freezer_api/tests/unit/sqlalchemy/v2/test_api_common.py
index 29bbcf9..42a0bfd 100644
--- a/freezer_api/tests/unit/sqlalchemy/v2/test_api_common.py
+++ b/freezer_api/tests/unit/sqlalchemy/v2/test_api_common.py
@@ -179,3 +179,30 @@ class ApiTestCase(base.DbTestCase):
179 api.replace_tuple, models.Job, self.fake_user_id, 179 api.replace_tuple, models.Job, self.fake_user_id,
180 self.fake_job_id, mock_tuple_values, 180 self.fake_job_id, mock_tuple_values,
181 project_id=self.fake_project_id) 181 project_id=self.fake_project_id)
182
183 @patch('oslo_db.sqlalchemy.utils.model_query')
184 def test_raises_search_tuple(self, mock_model_query):
185 mock_tablename = mock.MagicMock()
186 mock_tablename = mock.MagicMock()
187 mock_search = mock.MagicMock()
188 mock_model_query.side_effect = Exception('regular test failure')
189 self.assertRaises(freezer_api_exc.StorageEngineError,
190 api.search_tuple, mock_tablename, self.fake_user_id,
191 project_id=self.fake_project_id, offset=0, limit=100,
192 search=mock_search)
193
194 def test_valid_and_get_search_option(self):
195 search = {'error_key': 'search_info_error'}
196 result = api.valid_and_get_search_option(search)
197 self.assertEqual({}, result)
198
199 def test_get_recursively_list_include_dict(self):
200 dict1 = {'key1': [{'key11': {'key111': 111}},
201 {'key12': {'key121': 121}}],
202 'key2': 2
203 }
204 search_key = {'key111': 111,
205 'key121': 121,
206 'key2': 2}
207 search_keys_found = api.get_recursively(dict1, search_key)
208 self.assertEqual(search_key, search_keys_found)