summaryrefslogtreecommitdiffstats
path: root/vio
diff options
context:
space:
mode:
authorLiang Ke <lokyse@163.com>2018-07-04 03:07:33 +0000
committerGerrit Code Review <gerrit@onap.org>2018-07-04 03:07:33 +0000
commit65ab9ae82daf0e0522a7fbf1fbd556dc5abea9fe (patch)
treeb25668610b502432a477a47fb61840006c4a9270 /vio
parent9a503f6d0c341df9f595a44fbcdd0715cc8338cd (diff)
parent7332806d416bfac209fdda72854533f3e5489de8 (diff)
Merge changes from topic 'ut3'
* changes: Add test_operate_server_resume Add test_operate_server_start Add test_operate_server_stop Add test_list_servers_unauth
Diffstat (limited to 'vio')
-rw-r--r--vio/vio/tests/test_fake_nova_view.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/vio/vio/tests/test_fake_nova_view.py b/vio/vio/tests/test_fake_nova_view.py
index 5e56f0f..3d322cd 100644
--- a/vio/vio/tests/test_fake_nova_view.py
+++ b/vio/vio/tests/test_fake_nova_view.py
@@ -10,6 +10,7 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+import json
import mock
import unittest
@@ -29,6 +30,9 @@ class TestFakeNovaServer(unittest.TestCase):
def setUp(self):
self.view = views.FakeNovaServer()
+ def tearDown(self):
+ fakeResponse.serverMapps[Server]['status'] = "ACTIVE"
+
@mock.patch.object(fakeResponse, "show_serverDetail")
def test_get_server(self, mock_show_serverDetail):
req = mock.Mock()
@@ -59,6 +63,55 @@ class TestFakeNovaServer(unittest.TestCase):
resp = self.view.get(req, "abcd")
self.assertEqual(200, resp.status_code)
+ def test_list_servers_unauth(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": "invalid"
+ }
+ resp = self.view.get(req, "abcd")
+ self.assertEqual(401, resp.status_code)
+
+ def test_operate_server_stop(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": Token
+ }
+ req.body = json.dumps({
+ "os-stop": {}
+ })
+ resp = self.view.post(req, "abcd", Server)
+ self.assertEqual(202, resp.status_code)
+ self.assertEqual(
+ "POWERING_OFF", fakeResponse.serverMapps[Server]['status'])
+
+ def test_operate_server_start(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": Token
+ }
+ req.body = json.dumps({
+ "os-start": {}
+ })
+ fakeResponse.serverMapps[Server]['status'] = "SHUTDOWN"
+ resp = self.view.post(req, "abcd", Server)
+ self.assertEqual(202, resp.status_code)
+ self.assertEqual(
+ "POWERING_ON", fakeResponse.serverMapps[Server]['status'])
+
+ def test_operate_server_resume(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": Token
+ }
+ req.body = json.dumps({
+ "resume": {}
+ })
+ fakeResponse.serverMapps[Server]['status'] = "SUSPENDED"
+ resp = self.view.post(req, "abcd", Server)
+ self.assertEqual(202, resp.status_code)
+ self.assertEqual(
+ "ACTIVE", fakeResponse.serverMapps[Server]['status'])
+
class TestFakeNovaHypervisors(unittest.TestCase):