<s> from test_ella . cases import RedisTestCase as TestCase <EOL> from nose import tools <EOL> from django import template <EOL> from django . template import Context <EOL> from test_ella . test_core import create_basic_categories <EOL> from ella . core . models import Category <EOL> from ella . positions . models import Position <EOL> from ella . positions . templatetags . positions import ( <EOL> _get_category_from_pars_var , <EOL> _parse_position_tag , <EOL> PositionNode , <EOL> ) <EOL> class TestPositionParsing ( TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestPositionParsing , self ) . setUp ( ) <EOL> create_basic_categories ( self ) <EOL> self . context = Context ( { '<STR_LIT>' : self . category } ) <EOL> self . context_for_category_nested = Context ( { '<STR_LIT>' : self . category_nested } ) <EOL> self . position = Position ( <EOL> category = self . category_nested , <EOL> name = '<STR_LIT>' , <EOL> text = '<STR_LIT>' <EOL> ) <EOL> self . position . save ( ) <EOL> def test_getting_category_for_templatag_from_category_variable ( self ) : <EOL> tools . assert_equals ( _get_category_from_pars_var ( template . Variable ( '<STR_LIT>' ) , self . context ) , self . category ) <EOL> def test_raising_exception_for_templatag_if_category_is_not_in_context ( self ) : <EOL> tools . assert_raises ( template . VariableDoesNotExist , _get_category_from_pars_var , template . Variable ( '<STR_LIT>' ) , Context ( { } ) ) <EOL> def test_getting_category_for_templatag_from_category_tree_path_in_variable ( self ) : <EOL> context = Context ( { '<STR_LIT>' : '<STR_LIT:%s>' % ( self . category . tree_path ) } ) <EOL> tools . assert_equals ( _get_category_from_pars_var ( template . Variable ( '<STR_LIT>' ) , context ) , self . category ) <EOL> def test_raising_exception_for_templatag_if_no_category_for_tree_path_in_variable ( self ) : <EOL> context = Context ( { '<STR_LIT>' : '<STR_LIT:%s>' % ( "<STR_LIT>" ) } ) <EOL> tools . assert_raises ( Category . DoesNotExist , _get_category_from_pars_var , template . Variable ( '<STR_LIT>' ) , context ) <EOL> def test_getting_category_for_templatag_from_category_tree_path ( self ) : <EOL> tools . assert_equals ( _get_category_from_pars_var ( template . Variable ( '<STR_LIT>' % ( self . category . tree_path ) ) , self . context ) , self . category ) <EOL> tools . assert_equals ( _get_category_from_pars_var ( template . Variable ( '<STR_LIT>' % ( self . category_nested . tree_path ) ) , self . context ) , self . category_nested ) <EOL> def test_raising_exception_for_templatag_if_no_category_for_tree_path ( self ) : <EOL> tools . assert_raises ( Category . DoesNotExist , _get_category_from_pars_var , template . Variable ( '<STR_LIT>' ) , self . context ) <EOL> def test_parsing_position_tag ( self ) : <EOL> position_node = _parse_position_tag ( '<STR_LIT>' . split ( ) , '<STR_LIT>' ) <EOL> tools . assert_true ( isinstance ( position_node , PositionNode ) ) <EOL> tools . assert_true ( isinstance ( position_node . category , template . Variable ) ) <EOL> position_node = _parse_position_tag ( '<STR_LIT>' . split ( ) , '<STR_LIT>' ) <EOL> tools . assert_true ( isinstance ( position_node , PositionNode ) ) <EOL> tools . assert_true ( isinstance ( position_node . category , template . Variable ) ) <EOL> position_node = _parse_position_tag ( '<STR_LIT>' . split ( ) , '<STR_LIT>' ) <EOL> tools . assert_true ( isinstance ( position_node , PositionNode ) ) <EOL> tools . assert_true ( isinstance ( position_node . category , template . Variable ) ) <EOL> position_node = _parse_position_tag ( '<STR_LIT>' . split ( ) , '<STR_LIT>' ) <EOL> tools . assert_true ( isinstance ( position_node , PositionNode ) ) <EOL> tools . assert_true ( isinstance ( position_node . category , template . Variable ) ) <EOL> position_node = _parse_position_tag ( '<STR_LIT>' . split ( ) , '<STR_LIT>' ) <EOL> tools . assert_true ( isinstance ( position_node , PositionNode ) ) <EOL> tools . assert_true ( isinstance ( position_node . category , template . Variable ) ) <EOL> def test_position_templatetag_render_with_category_var ( self ) : <EOL> t = template . Template ( '<STR_LIT>' ) <EOL> tools . assert_equals ( '<STR_LIT>' , t . render ( self . context_for_category_nested ) ) <EOL> def test_position_templatetag_render_with_category_tree_path ( self ) : <EOL> t = template . Template ( '<STR_LIT>' ) <EOL> tools . assert_equals ( '<STR_LIT>' , t . render ( self . context_for_category_nested ) ) <EOL> def test_empty_position_templatetag_render_with_category_var ( self ) : <EOL> t = template . Template ( '<STR_LIT>' ) <EOL> tools . assert_equals ( '<STR_LIT>' , t . render ( self . context ) ) <EOL> def test_empty_position_templatetag_render_with_category_tree_path_if_position_does_not_exist ( self ) : <EOL> t = template . Template ( '<STR_LIT>' ) <EOL> tools . assert_equals ( '<STR_LIT>' , t . render ( self . context ) ) <EOL> def test_raising_exception_position_templatetag_render_with_bad_category_tree_path ( self ) : <EOL> t = template . Template ( '<STR_LIT>' ) <EOL> tools . assert_raises ( Category . DoesNotExist , t . render , self . context_for_category_nested ) <EOL> def test_raising_exception_position_templatetag_render_with_category_not_defined ( self ) : <EOL> t = template . Template ( '<STR_LIT>' ) <EOL> tools . assert_raises ( template . VariableDoesNotExist , t . render , Context ( { } ) ) <EOL> def test_ifposition_templatetag_render_with_category_var ( self ) : <EOL> t = template . Template ( '<STR_LIT>' ) <EOL> tools . assert_equals ( '<STR_LIT>' , t . render ( self . context_for_category_nested ) ) <EOL> def test_ifposition_templatetag_render_with_category_tree_path ( self ) : <EOL> t = template . Template ( '<STR_LIT>' ) <EOL> tools . assert_equals ( '<STR_LIT>' , t . render ( self . context_for_category_nested ) ) <EOL> def test_not_position_for_ifposition_templatetag_render_with_category_var ( self ) : <EOL> t = template . Template ( '<STR_LIT>' ) <EOL> tools . assert_equals ( '<STR_LIT>' , t . render ( self . context ) ) <EOL> def test_raising_exception_for_ifposition_templatetag_render_with_category_var_not_in_context ( self ) : <EOL> t = template . Template ( '<STR_LIT>' ) <EOL> tools . assert_raises ( template . VariableDoesNotExist , t . render , Context ( { } ) ) <EOL> def test_raising_exception_ifposition_templatetag_render_with_bad_category_tree_path ( self ) : <EOL> t = template . Template ( '<STR_LIT>' ) <EOL> tools . assert_raises ( Category . DoesNotExist , t . render , self . context ) </s>
