Skip to content

Commit

Permalink
Updated unit test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
sushanthakumar committed Jan 5, 2021
1 parent 7c0560f commit e94403a
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion delfin/tests/unit/api/v1/test_storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
from delfin.api.v1.storages import StorageController
from delfin.tests.unit.api import fakes

fake_schedular_config = {
"storages": [{"id": "fake_id",
"array_polling": {"perf_collection": True, "interval": 12,
"is_historic": True}}]}

invalid_schedular_config = '"storages": [{"id": "fake_id","array_polling": {' \
'"perf_collection": True, "interval": 12,' \
'"is_historic": True}}]} '


class TestStorageController(test.TestCase):

Expand All @@ -35,8 +44,24 @@ def setUp(self):

@mock.patch.object(db, 'storage_get',
mock.Mock(return_value={'id': 'fake_id'}))
def test_delete(self):
@mock.patch('delfin.common.config.load_json_file')
def test_delete(self, mock_load_json_file):
req = fakes.HTTPRequest.blank('/storages/fake_id')
mock_load_json_file.return_value = fake_schedular_config
self.controller.delete(req, 'fake_id')
ctxt = req.environ['delfin.context']
db.storage_get.assert_called_once_with(ctxt, 'fake_id')
self.task_rpcapi.remove_storage_resource.assert_called_with(
ctxt, 'fake_id', mock.ANY)
self.task_rpcapi.remove_storage_in_cache.assert_called_once_with(
ctxt, 'fake_id')

@mock.patch.object(db, 'storage_get',
mock.Mock(return_value={'id': 'fake_id'}))
@mock.patch('delfin.common.config.load_json_file')
def test_delete_invalid_schedular_conf(self, mock_load_json_file):
req = fakes.HTTPRequest.blank('/storages/fake_id')
mock_load_json_file.return_value = invalid_schedular_config
self.controller.delete(req, 'fake_id')
ctxt = req.environ['delfin.context']
db.storage_get.assert_called_once_with(ctxt, 'fake_id')
Expand Down

0 comments on commit e94403a

Please sign in to comment.