summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgengchc2 <geng.changcai2@zte.com.cn>2018-12-11 00:23:44 -0800
committergengchc2 <geng.changcai2@zte.com.cn>2018-12-11 09:31:02 +0000
commit00dcbb03319802aad8c78982771d536d3cb1c0c9 (patch)
treef899a7dd028f3a4b4ab8d072713fd5aa7e744a4c
parent976347c84a47faa00b44f241d683cbbc54c91a08 (diff)
Add unit test for freezer-manageHEADmaster
Notes
Notes (review): Code-Review+2: gecong <ge.cong@zte.com.cn> Workflow+1: gecong <ge.cong@zte.com.cn> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 12 Dec 2018 03:01:15 +0000 Reviewed-on: https://review.openstack.org/624320 Project: openstack/freezer-api Branch: refs/heads/master
-rw-r--r--freezer_api/tests/unit/cmd/test_cmd.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/freezer_api/tests/unit/cmd/test_cmd.py b/freezer_api/tests/unit/cmd/test_cmd.py
new file mode 100644
index 0000000..1f193e3
--- /dev/null
+++ b/freezer_api/tests/unit/cmd/test_cmd.py
@@ -0,0 +1,71 @@
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13import mock
14from oslo_config import cfg
15import sys
16import unittest
17
18from freezer_api.cmd import manage as freezer_manage
19
20CONF = cfg.CONF
21
22
23class TestFreezerApiCmd(unittest.TestCase):
24 """Unit test cases for python modules under freezer/cmd."""
25 def setUp(self):
26 super(TestFreezerApiCmd, self).setUp()
27
28 def tearDown(self):
29 super(TestFreezerApiCmd, self).tearDown()
30 CONF.reset()
31 CONF.unregister_opt(cfg.StrOpt('db'))
32
33 @mock.patch("freezer_api.db.manager.get_db_driver")
34 def test_db_sync(self, mock_get_db_driver):
35 db_driver = mock_get_db_driver("elasticsearch", backend="")
36 db_driver.db_sync.return_value = mock.MagicMock()
37 sys.argv = ["freezer-manage", "db", "sync"]
38 freezer_manage.main()
39 self.assertTrue(db_driver.db_sync.called)
40
41 @mock.patch("freezer_api.db.manager.get_db_driver")
42 def test_db_update(self, mock_get_db_driver):
43 db_driver = mock_get_db_driver("elasticsearch", backend="")
44 db_driver.db_sync.return_value = mock.MagicMock()
45 sys.argv = ["freezer-manage", "db", "update"]
46 freezer_manage.main()
47 self.assertTrue(db_driver.db_sync.called)
48
49 @mock.patch("freezer_api.db.manager.get_db_driver")
50 def test_db_remove(self, mock_get_db_driver):
51 db_driver = mock_get_db_driver("elasticsearch", backend="")
52 db_driver.db_remove.return_value = mock.MagicMock()
53 sys.argv = ["freezer-manage", "db", "remove"]
54 freezer_manage.main()
55 self.assertTrue(db_driver.db_remove.called)
56
57 @mock.patch("freezer_api.db.manager.get_db_driver")
58 def test_db_show1(self, mock_get_db_driver):
59 db_driver = mock_get_db_driver("elasticsearch", backend="")
60 db_driver.db_show.return_value = {}
61 sys.argv = ["freezer-manage", "db", "show"]
62 freezer_manage.main()
63 self.assertTrue(db_driver.db_show.called)
64
65 @mock.patch("freezer_api.db.manager.get_db_driver")
66 def test_db_show2(self, mock_get_db_driver):
67 db_driver = mock_get_db_driver("elasticsearch", backend="")
68 db_driver.db_show.return_value = {"databaase": "freezer"}
69 sys.argv = ["freezer-manage", "db", "show"]
70 freezer_manage.main()
71 self.assertTrue(db_driver.db_show.called)