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 multicloud_azure.pub.msapi import extsys
17 from multicloud_azure.pub.vim.vimapi.compute import OperateFlavors
18 from multicloud_azure.swagger import compute_utils
19 from multicloud_azure.swagger.views.flavor.views import FlavorsView
20 from rest_framework import status
22 VIM_INFO = {'cloud_extra_info': 1, 'username': 'user1',
23 'password': '1234', 'default_tenant': 't1',
24 'cloud_region_id': 'r1'}
27 class FlavorViewTest(unittest.TestCase):
30 self.fsv = FlavorsView()
35 @mock.patch.object(compute_utils, 'convert_vmsize_aai')
36 @mock.patch.object(OperateFlavors.OperateFlavors, 'list_flavors')
37 @mock.patch.object(extsys, 'get_vim_by_id')
38 def test_flavors_get_fail(self, mock_vim_info,
39 mock_flavors, mock_formatter):
40 mock_vim_info.return_value = VIM_INFO
43 def __init__(self, id, name):
49 mock_flavors.return_value = flavors
50 mock_formatter.return_value = flavors
53 def __init__(self, query_params):
54 self.query_params = query_params
55 req = Request({'k': 'v'})
57 status.HTTP_500_INTERNAL_SERVER_ERROR,
58 self.fsv.get(req, "vimid").status_code)
60 def test_vmsize_aai(self):
69 def __init__(self, name, number_of_cores, memory_in_mb,
72 self.number_of_cores = number_of_cores
73 self.memory_in_mb = memory_in_mb
74 self.os_disk_size_in_mb = os_disk_size_in_mb
75 v1 = VmSize("abc", 1, 123, 1234)
76 self.assertEquals(expected, compute_utils.convert_vmsize_aai(v1))