1# Licensed under the Apache License, Version 2.0 (the "License"); you may 2# not use this file except in compliance with the License. You may obtain 3# a copy of the License at 4# 5# http://www.apache.org/licenses/LICENSE-2.0 6# 7# Unless required by applicable law or agreed to in writing, software 8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10# License for the specific language governing permissions and limitations 11# under the License. 12 13import copy 14from openstack.tests.unit import base 15 16from openstack.orchestration.v1 import stack_template 17 18 19FAKE = { 20 'description': 'template description', 21 'heat_template_version': '2014-10-16', 22 'parameters': { 23 'key_name': { 24 'type': 'string' 25 } 26 }, 27 'resources': { 28 'resource1': { 29 'type': 'ResourceType' 30 } 31 }, 32 'conditions': {'cd1': True}, 33 'outputs': { 34 'key1': 'value1' 35 } 36} 37 38 39class TestStackTemplate(base.TestCase): 40 41 def test_basic(self): 42 sot = stack_template.StackTemplate() 43 self.assertFalse(sot.allow_create) 44 self.assertTrue(sot.allow_fetch) 45 self.assertFalse(sot.allow_commit) 46 self.assertFalse(sot.allow_delete) 47 self.assertFalse(sot.allow_list) 48 49 def test_make_it(self): 50 sot = stack_template.StackTemplate(**FAKE) 51 self.assertEqual(FAKE['description'], sot.description) 52 self.assertEqual(FAKE['heat_template_version'], 53 sot.heat_template_version) 54 self.assertEqual(FAKE['outputs'], sot.outputs) 55 self.assertEqual(FAKE['parameters'], sot.parameters) 56 self.assertEqual(FAKE['resources'], sot.resources) 57 self.assertEqual(FAKE['conditions'], sot.conditions) 58 59 def test_to_dict(self): 60 fake_sot = copy.deepcopy(FAKE) 61 fake_sot['parameter_groups'] = [{ 62 "description": "server parameters", 63 "parameters": ["key_name", "image_id"], 64 "label": "server_parameters"}] 65 fake_sot['location'] = None 66 fake_sot['id'] = None 67 fake_sot['name'] = None 68 69 for temp_version in ['2016-10-14', '2017-02-24', '2017-02-24', 70 '2017-09-01', '2018-03-02', 'newton', 71 'ocata', 'pike', 'queens']: 72 fake_sot['heat_template_version'] = temp_version 73 sot = stack_template.StackTemplate(**fake_sot) 74 self.assertEqual(fake_sot, sot.to_dict()) 75