vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / tests / orchestrator / context / test_resource_render.py
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements.  See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License.  You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import pytest
17
18 from tests import mock, storage
19
20 _IMPLICIT_CTX_TEMPLATE = '{{ctx.service.name}}'
21 _IMPLICIT_CTX_TEMPLATE_PATH = 'implicit-ctx.template'
22 _VARIABLES_TEMPLATE = '{{variable}}'
23 _VARIABLES_TEMPLATE_PATH = 'variables.template'
24
25
26 def test_get_resource_and_render_implicit_ctx_no_variables(ctx):
27     content = ctx.get_resource_and_render(_IMPLICIT_CTX_TEMPLATE_PATH)
28     assert content == mock.models.SERVICE_NAME
29
30
31 def test_get_resource_and_render_provided_variables(ctx):
32     variable = 'VARIABLE'
33     content = ctx.get_resource_and_render(_VARIABLES_TEMPLATE_PATH,
34                                           variables={'variable': variable})
35     assert content == variable
36
37
38 def test_download_resource_and_render_implicit_ctx_no_variables(tmpdir, ctx):
39     destination = tmpdir.join('destination')
40     ctx.download_resource_and_render(destination=str(destination),
41                                      path=_IMPLICIT_CTX_TEMPLATE_PATH)
42     assert destination.read() == mock.models.SERVICE_NAME
43
44
45 def test_download_resource_and_render_provided_variables(tmpdir, ctx):
46     destination = tmpdir.join('destination')
47     variable = 'VARIABLE'
48     ctx.download_resource_and_render(destination=str(destination),
49                                      path=_VARIABLES_TEMPLATE_PATH,
50                                      variables={'variable': variable})
51     assert destination.read() == variable
52
53
54 @pytest.fixture
55 def ctx(tmpdir):
56     context = mock.context.simple(str(tmpdir))
57     yield context
58     storage.release_sqlite_storage(context.model)
59
60
61 @pytest.fixture(autouse=True)
62 def resources(tmpdir, ctx):
63     implicit_ctx_template_path = tmpdir.join(_IMPLICIT_CTX_TEMPLATE_PATH)
64     implicit_ctx_template_path.write(_IMPLICIT_CTX_TEMPLATE)
65     variables_template_path = tmpdir.join(_VARIABLES_TEMPLATE_PATH)
66     variables_template_path.write(_VARIABLES_TEMPLATE)
67     ctx.resource.service.upload(entry_id='1',
68                                 source=str(implicit_ctx_template_path),
69                                 path=_IMPLICIT_CTX_TEMPLATE_PATH)
70     ctx.resource.service.upload(entry_id='1',
71                                 source=str(variables_template_path),
72                                 path=_VARIABLES_TEMPLATE_PATH)