view MoinMoin/themes/_tests/test_navi_bar.py @ 608:27dc049120b1 pytest2

test for shorten_item_name() added in themes/test_navi_bar
author pkumar <contactprashantat@gmail.com>
date Fri, 01 Jul 2011 23:24:54 +0530
parents e9c80fcc5ae5
children ed593361022e
line wrap: on
line source
# Copyright: 2010 MoinMoin:DiogenesAugusto
# Copyright: 2010 MoinMoin:ThomasWaldmann
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
    MoinMoin - Navibar Tests
"""


from flask import current_app as app

from MoinMoin._tests import wikiconfig
from MoinMoin.themes import ThemeSupport
from MoinMoin import themes

class TestNaviBar(object):
    class Config(wikiconfig.Config):
        interwiki_map = dict(MoinMoin='http://moinmo.in/', )

    def setup_method(self, method):
        self.theme = ThemeSupport(app.cfg)

    def test_split_navilink(self):
        tests = [
            #(navilink, (href, text, interwiki)),
            ('ItemName', ('/ItemName', 'ItemName', '')),
            ('[[ItemName|LinkText]]', ('/ItemName', 'LinkText', '')),
            ('MoinMoin:ItemName', ('http://moinmo.in/ItemName', 'ItemName', 'MoinMoin')),
            ('[[MoinMoin:ItemName|LinkText]]', ('http://moinmo.in/ItemName', 'LinkText', 'MoinMoin')),
            ('[[wiki:MoinMoin:ItemName|LinkText]]', ('http://moinmo.in/ItemName', 'LinkText', 'MoinMoin')),
            ('http://example.org/', ('http://example.org/', 'http://example.org/', '')),
            ('[[http://example.org/|LinkText]]', ('http://example.org/', 'LinkText', '')),
        ]
        for navilink, expected in tests:
            result = self.theme.split_navilink(navilink)
            assert result == expected

    def test_location_breadcrumbs(self):
        test_result = ThemeSupport.location_breadcrumbs(self.theme, 'some/place/test_item')
        test_segment_name_1, test_item_name_1, test_item_exists_1 = test_result[0]
        test_segment_name_2, test_item_name_2, test_item_exists_2 = test_result[1]
        test_segment_name_3, test_item_name_3, test_item_exists_3 = test_result[2]
         
        assert test_segment_name_1 == 'some'
        assert test_item_name_1 == 'some'
        assert test_segment_name_2 == 'place'
        assert test_item_name_2 == 'some/place'
        assert test_segment_name_3 == 'test_item'
        assert test_item_name_3 == 'some/place/test_item'

def test_shorten_item_name():
    test_result1 = themes.shorten_item_name(u'MoinMoin/some/value', 0) 
    assert test_result1 == u'valu...lue'    
    test_result2 = themes.shorten_item_name(u'MoinMoin/some/value', 5) 
    assert test_result2 == 'value'    
    test_result3 = themes.shorten_item_name(u'MoinMoin/some/value') 
    assert test_result3 == u'MoinMoin/some/value'