1 # Copyright (c) 2018 Amdocs
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 from rest_framework import status
17 from aria.cli.core import aria
19 from multicloud_azure.swagger.views.infra_workload.views import InfraWorkload
20 from multicloud_azure.swagger.views.infra_workload.views import GetStackView
21 from multicloud_azure.pub.aria.service import AriaServiceImpl
24 class InfraViewTest(unittest.TestCase):
27 self.fsv = InfraWorkload()
32 def test_service_get_fail(self):
34 dict = {'infra-template': 'aria', 'infra-payload': json.dumps(
35 {'name': 'abc', 'template_data': {'stack_name': 'stack'}})}
37 resp = self.fsv.post(req, "abc", "def")
38 self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR,
42 class StackViewTest(unittest.TestCase):
45 self.fsv = GetStackView()
50 def test_service_get_fail(self):
53 def __init__(self, query_params):
54 self.query_params = query_params
55 req = Request({'k': 'v'})
56 self.assertNotEqual(status.HTTP_500_INTERNAL_SERVER_ERROR,
57 self.fsv.get(req, "abc", "def", 123))
60 class WorkoadViewTest(unittest.TestCase):
63 self.fsv = AriaServiceImpl()
68 @mock.patch.object(AriaServiceImpl, 'deploy_service')
69 def test_deploy_service(self, mock_service_info):
72 def __init__(self, name, body, input, logger):
77 s = Service("abc", "def", "ghi", "OK")
78 mock_service_info.return_value = s
79 service_op = AriaServiceImpl()
80 self.assertNotEqual(200, service_op.deploy_service("a1", "b1", "c1",
83 @mock.patch.object(AriaServiceImpl, 'install_template_private')
84 @aria.pass_model_storage
85 @aria.pass_resource_storage
86 @aria.pass_plugin_manager
88 def test_install_template(self, mock_template_info, model_storage,
89 resource_storage, plugin_manager, logger):
92 def __init__(self, name, body):
95 service = Workload("a", "w1")
96 mock_template_info.return_value = service
99 def __init__(self, query_params):
100 self.query_params = query_params
101 req = Request({'k': 'v'})
102 self.assertNotEqual(200,
103 self.fsv.install_template_private(req, "a1", "b1",
109 @mock.patch.object(AriaServiceImpl, 'create_service')
110 @aria.pass_model_storage
111 @aria.pass_resource_storage
112 @aria.pass_plugin_manager
114 def test_create_service(self, mock_template_info, model_storage,
115 resource_storage, plugin_manager, logger):
117 def __init__(self, id, name, input):
122 f1 = Workload(1, "a", "w1")
123 f2 = Workload(2, "b", "w2")
125 mock_template_info.return_value = service
128 def __init__(self, query_params):
129 self.query_params = query_params
131 req = Request({'k': 'v'})
132 self.assertNotEqual(200,
133 self.fsv.create_service(req, 123, "a1", "b1",
139 @mock.patch.object(AriaServiceImpl, 'start_execution')
140 @aria.pass_model_storage
141 @aria.pass_resource_storage
142 @aria.pass_plugin_manager
144 def test_start_execution(self, mock_template_info, model_storage,
145 resource_storage, plugin_manager, logger):
147 def __init__(self, status_id, execution_id, name, input):
148 self.status_id = status_id
149 self.execution_id = execution_id
153 service = Workload(1, 2, "a", "w")
154 mock_template_info.return_value = service
157 def __init__(self, query_params):
158 self.query_params = query_params
160 req = Request({'k': 'v'})
161 self.assertNotEqual(200,
162 self.fsv.start_execution(req, 123, 456, "a1", "b1",
168 def test_show_execution(self):
169 service_op = AriaServiceImpl()
170 self.assertNotEqual(200,
171 service_op.show_execution(123))