Browse Source

Add raise unit test for search tuple in sqlalchemy

Change-Id: I60a2305b97f73b011496a8c02e115ab339d130f9
tags/7.1.0
gengchc2 1 year ago
parent
commit
edb258dbb6
2 changed files with 54 additions and 0 deletions
  1. +27
    -0
      freezer_api/tests/unit/sqlalchemy/v1/test_api_common.py
  2. +27
    -0
      freezer_api/tests/unit/sqlalchemy/v2/test_api_common.py

+ 27
- 0
freezer_api/tests/unit/sqlalchemy/v1/test_api_common.py View File

@@ -168,3 +168,30 @@ class ApiTestCase(base.DbTestCase):
self.assertRaises(freezer_api_exc.StorageEngineError,
api.replace_tuple, models.Job, self.fake_user_id,
self.fake_job_id, mock_tuple_values)

@patch('oslo_db.sqlalchemy.utils.model_query')
def test_raises_search_tuple(self, mock_model_query):
mock_tablename = mock.MagicMock()
mock_tablename = mock.MagicMock()
mock_search = mock.MagicMock()
mock_model_query.side_effect = Exception('regular test failure')
self.assertRaises(freezer_api_exc.StorageEngineError,
api.search_tuple, mock_tablename, self.fake_user_id,
offset=0, limit=100,
search=mock_search)

def test_valid_and_get_search_option(self):
search = {'error_key': 'search_info_error'}
result = api.valid_and_get_search_option(search)
self.assertEqual({}, result)

def test_get_recursively_list_include_dict(self):
dict1 = {'key1': [{'key11': {'key111': 111}},
{'key12': {'key121': 121}}],
'key2': 2
}
search_key = {'key111': 111,
'key121': 121,
'key2': 2}
search_keys_found = api.get_recursively(dict1, search_key)
self.assertEqual(search_key, search_keys_found)

+ 27
- 0
freezer_api/tests/unit/sqlalchemy/v2/test_api_common.py View File

@@ -179,3 +179,30 @@ class ApiTestCase(base.DbTestCase):
api.replace_tuple, models.Job, self.fake_user_id,
self.fake_job_id, mock_tuple_values,
project_id=self.fake_project_id)

@patch('oslo_db.sqlalchemy.utils.model_query')
def test_raises_search_tuple(self, mock_model_query):
mock_tablename = mock.MagicMock()
mock_tablename = mock.MagicMock()
mock_search = mock.MagicMock()
mock_model_query.side_effect = Exception('regular test failure')
self.assertRaises(freezer_api_exc.StorageEngineError,
api.search_tuple, mock_tablename, self.fake_user_id,
project_id=self.fake_project_id, offset=0, limit=100,
search=mock_search)

def test_valid_and_get_search_option(self):
search = {'error_key': 'search_info_error'}
result = api.valid_and_get_search_option(search)
self.assertEqual({}, result)

def test_get_recursively_list_include_dict(self):
dict1 = {'key1': [{'key11': {'key111': 111}},
{'key12': {'key121': 121}}],
'key2': 2
}
search_key = {'key111': 111,
'key121': 121,
'key2': 2}
search_keys_found = api.get_recursively(dict1, search_key)
self.assertEqual(search_key, search_keys_found)

Loading…
Cancel
Save