Added V0 Registry API
[multicloud/azure.git] / azure / multicloud_azure / tests / test_flavor_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
15 import mock
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
21
22 VIM_INFO = {'cloud_extra_info': 1, 'username': 'user1',
23             'password': '1234', 'default_tenant': 't1',
24             'cloud_region_id': 'r1'}
25
26
27 class FlavorViewTest(unittest.TestCase):
28
29     def setUp(self):
30         self.fsv = FlavorsView()
31
32     def tearDown(self):
33         pass
34
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
41
42         class Flavor:
43             def __init__(self, id, name):
44                 self.id = id
45                 self.name = name
46         f1 = Flavor(1, "f1")
47         f2 = Flavor(2, "f2")
48         flavors = [f1, f2]
49         mock_flavors.return_value = flavors
50         mock_formatter.return_value = flavors
51
52         class Request:
53             def __init__(self, query_params):
54                 self.query_params = query_params
55         req = Request({'k': 'v'})
56         self.assertEqual(
57             status.HTTP_500_INTERNAL_SERVER_ERROR,
58             self.fsv.get(req, "vimid").status_code)
59
60     def test_vmsize_aai(self):
61         expected = {
62             'name': "abc",
63             'vcpus': 1,
64             'ram': 123,
65             'disk': 1234
66         }
67
68         class VmSize:
69             def __init__(self, name, number_of_cores, memory_in_mb,
70                          os_disk_size_in_mb):
71                 self.name = name
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))