File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed
Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ __author__ = 'rande'
2+
3+ class JinjaHelper (object ):
4+ def __init__ (self , container ):
5+ self .container = container
6+
7+ def get_parameter (self , name , default = None ):
8+ if self .container .parameters .has (name ):
9+ return self .container .parameters .get (name )
10+
11+ return default
Original file line number Diff line number Diff line change 1+ #
2+ # Copyright 2014 Thomas Rabaix <[email protected] > 3+ #
4+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
5+ # not use this file except in compliance with the License. You may obtain
6+ # 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, WITHOUT
12+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+ # License for the specific language governing permissions and limitations
14+ # under the License.
Original file line number Diff line number Diff line change 1+ #
2+ # Copyright 2014 Thomas Rabaix <[email protected] > 3+ #
4+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
5+ # not use this file except in compliance with the License. You may obtain
6+ # 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, WITHOUT
12+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+ # License for the specific language governing permissions and limitations
14+ # under the License.
15+
16+ import unittest
17+
18+ from ioc .extra .jinja2 .helper import JinjaHelper
19+ from ioc .component import Container , ParameterHolder
20+ class JinjaHelperTest (unittest .TestCase ):
21+ def test_get_parameter (self ):
22+
23+ container = Container ()
24+ container .parameters .set ('hello' , 'world' )
25+
26+ helper = JinjaHelper (container )
27+
28+ self .assertEquals ('world' , helper .get_parameter ('hello' ))
29+ self .assertEquals (None , helper .get_parameter ('fake' ))
30+ self .assertEquals ('for real' , helper .get_parameter ('fake' , 'for real' ))
You can’t perform that action at this time.
0 commit comments