コード例 #1
0
def test_nested(app):
    item_without = Item('Without Children', 'without_children')
    assert isinstance(item_without.items, ItemCollection)
    assert len(item_without.items) == 0

    item_with = Item('With Children',
                     'with_children',
                     items=[Item('Nested item', 'nested')])
    assert isinstance(item_with.items, ItemCollection)
    assert len(item_with.items) == 1
コード例 #2
0
def items():
    items = {
        'biu':
        Item(u'Biu', endpoint='biu.biu'),
        'boom1':
        Item(u'Boom', endpoint='biu.boom', args={'num': 1}),
        'boom2':
        Item(u'Boom', endpoint='biu.boom', args=lambda: {'num': 2}),
        'example':
        Item(u'Example', endpoint='external.example', url='//example.com')
    }
    return items
コード例 #3
0
def test_alias_item():
    navbar = NavigationBar('mybar', [
        Item(u'Home', 'home'),
        Item(u'News', 'news', args={'page': 1}),
    ],
                           alias={
                               'foo': ItemReference('home'),
                               'bar': ItemReference('news', {'page': 1}),
                               'egg': ItemReference('news', {'page': 2}),
                           })

    assert navbar.alias_item('foo').label == u'Home'
    assert navbar.alias_item('bar').label == u'News'

    with raises(KeyError):
        navbar.alias_item('egg')
コード例 #4
0
def test_current_item():
    app = Flask(__name__)

    nav = Navigation()
    nav.init_app(app)
    news_item = Item(u'News', 'news')
    navbar = nav.Bar('test_current', [
        Item(u'Home', 'home'),
        news_item,
    ])

    @app.route('/')
    def home():
        pass

    @app.route('/news')
    def news():
        pass

    assert navbar.current_item is None

    with app.test_request_context('/news'):
        assert navbar.current_item == news_item
コード例 #5
0
def test_current_item_nested():
    app = Flask(__name__)

    nav = Navigation()
    nav.init_app(app)
    item = Item('Nested item', 'nested')
    navbar = nav.Bar('test_current', [
        Item(u'Home', 'home'),
        Item(u'News', 'news'),
        Item(u'With Children', 'with_children', items=[item])
    ])

    @app.route('/')
    def home():
        pass

    @app.route('/nested')
    def nested():
        pass

    assert navbar.current_item is None

    with app.test_request_context('/nested'):
        assert navbar.current_item == item
コード例 #6
0
def test_html_representation_with_class(app):
    biu_with_class = Item(u'Biu',
                          endpoint='biu.biu',
                          html_attrs={
                              'class': ['icon', 'icon-biu'],
                              'data-icon': 'biu'
                          })
    boom_with_class = Item(u'Boom',
                           endpoint='biu.boom',
                           args={'num': 1},
                           html_attrs={
                               'class': ['icon', 'icon-boom'],
                               'data-icon': 'boom'
                           })

    with app.test_client() as client:
        client.get('/biu/biu')

        assert str(Markup(biu_with_class)) == (
            '<a class="icon icon-biu active" data-icon="biu"'
            ' href="/biu/biu">Biu</a>')
        assert str(Markup(boom_with_class)) == (
            '<a class="icon icon-boom" data-icon="boom"'
            ' href="/biu/boom/1">Boom</a>')
コード例 #7
0
def navbar():
    navbar = NavigationBar('mybar', [
        Item(u'Home', 'home'),
        Item(u'News', 'news'),
    ])
    return navbar