f0ab6d6b4ba01ee69d093227b37254dff9809bbb
[it/dep.git] / smo-install / test / pythonsdk / src / oransdk / utils / jinja.py
1 ###
2 # ============LICENSE_START=======================================================
3 # ORAN SMO PACKAGE - PYTHONSDK TESTS
4 # ================================================================================
5 # Copyright (C) 2021-2022 AT&T Intellectual Property. All rights
6 #                             reserved.
7 # ================================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 # ============LICENSE_END============================================
20 # ===================================================================
21 #
22 ###
23 """Jinja module."""
24
25 from jinja2 import Environment, PackageLoader, select_autoescape, ChoiceLoader
26
27
28 def jinja_env() -> Environment:
29     """Create Jinja environment.
30
31     jinja_env allow to fetch simply jinja templates where they are.
32     by default jinja engine will look for templates in `templates` directory of
33     the package. So to load a template, you just have to do:
34
35     Example:
36     >>> template = jinja_env().get_template('vendor_create.json.j2')
37     >>> data = template.render(name="vendor")
38
39     See also:
40         SdcElement.create() for real use
41
42     Returns:
43         Environment: the Jinja environment to use
44
45     """
46     return Environment(autoescape=select_autoescape(['html', 'htm', 'xml']),
47                        loader=ChoiceLoader([
48                            PackageLoader("oransdk.a1sim"),
49                            PackageLoader("oransdk.dmaap"),
50                            PackageLoader("oransdk.enrichmentservice"),
51                            PackageLoader("oransdk.policy")
52                        ]))