Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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')
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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>')
Ejemplo n.º 7
0
def navbar():
    navbar = NavigationBar('mybar', [
        Item(u'Home', 'home'),
        Item(u'News', 'news'),
    ])
    return navbar