Azure-plugin not sending REST calls to Azure cloud
[multicloud/azure.git] / azure / multicloud_azure / tests / test_aria_view.py
1 # Copyright (c) 2018 Amdocs
2 #
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:
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
12
13 import unittest
14 import mock
15 import json
16 from rest_framework import status
17 from aria.cli.core import aria
18
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
22
23
24 class InfraViewTest(unittest.TestCase):
25
26     def setUp(self):
27         self.fsv = InfraWorkload()
28
29     def tearDown(self):
30         pass
31
32     def test_service_get_fail(self):
33         req = mock.Mock()
34         dict = {'infra-template': 'aria', 'infra-payload': json.dumps(
35             {'name': 'abc', 'template_data': {'stack_name': 'stack'}})}
36         req.data = dict
37         resp = self.fsv.post(req, "abc", "def")
38         self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR,
39                          resp.status_code)
40
41
42 class StackViewTest(unittest.TestCase):
43
44     def setUp(self):
45         self.fsv = GetStackView()
46
47     def tearDown(self):
48         pass
49
50     def test_service_get_fail(self):
51
52         class Request:
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))
58
59
60 class WorkoadViewTest(unittest.TestCase):
61
62     def setUp(self):
63         self.fsv = AriaServiceImpl()
64
65     def tearDown(self):
66         pass
67
68     @mock.patch.object(AriaServiceImpl, 'deploy_service')
69     def test_deploy_service(self, mock_service_info):
70
71         class Service:
72             def __init__(self, name, body, input, logger):
73                 self.name = name
74                 self.body = body
75                 self.input = input
76                 self.logger = 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",
81                                                            "OK"))
82
83     @mock.patch.object(AriaServiceImpl, 'install_template_private')
84     @aria.pass_model_storage
85     @aria.pass_resource_storage
86     @aria.pass_plugin_manager
87     @aria.pass_logger
88     def test_install_template(self, mock_template_info, model_storage,
89                               resource_storage, plugin_manager, logger):
90
91         class Workload:
92             def __init__(self, name, body):
93                 self.name = name
94                 self.body = body
95         service = Workload("a", "w1")
96         mock_template_info.return_value = service
97
98         class Request:
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",
104                                                               model_storage,
105                                                               resource_storage,
106                                                               plugin_manager,
107                                                               logger))
108
109     @mock.patch.object(AriaServiceImpl, 'create_service')
110     @aria.pass_model_storage
111     @aria.pass_resource_storage
112     @aria.pass_plugin_manager
113     @aria.pass_logger
114     def test_create_service(self, mock_template_info, model_storage,
115                             resource_storage, plugin_manager, logger):
116         class Workload:
117             def __init__(self, id, name, input):
118                 self.id = id
119                 self.name = name
120                 self.input = input
121
122         f1 = Workload(1, "a", "w1")
123         f2 = Workload(2, "b", "w2")
124         service = [f1, f2]
125         mock_template_info.return_value = service
126
127         class Request:
128             def __init__(self, query_params):
129                 self.query_params = query_params
130
131         req = Request({'k': 'v'})
132         self.assertNotEqual(200,
133                             self.fsv.create_service(req, 123, "a1", "b1",
134                                                     model_storage,
135                                                     resource_storage,
136                                                     plugin_manager,
137                                                     logger))
138
139     def test_show_execution(self):
140         service_op = AriaServiceImpl()
141         self.assertNotEqual(200,
142                             service_op.show_execution(123))