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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 from tests import mock, storage
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'
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
31 def test_get_resource_and_render_provided_variables(ctx):
33 content = ctx.get_resource_and_render(_VARIABLES_TEMPLATE_PATH,
34 variables={'variable': variable})
35 assert content == variable
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
45 def test_download_resource_and_render_provided_variables(tmpdir, ctx):
46 destination = tmpdir.join('destination')
48 ctx.download_resource_and_render(destination=str(destination),
49 path=_VARIABLES_TEMPLATE_PATH,
50 variables={'variable': variable})
51 assert destination.read() == variable
56 context = mock.context.simple(str(tmpdir))
58 storage.release_sqlite_storage(context.model)
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)