first commit
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17
hypenv/lib/python3.11/site-packages/tests/integration/app.py
Normal file
17
hypenv/lib/python3.11/site-packages/tests/integration/app.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from flask import Flask
|
||||
|
||||
from .ext import nav
|
||||
from .views import bp
|
||||
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config)
|
||||
nav.init_app(app)
|
||||
app.register_blueprint(bp)
|
||||
return app
|
||||
|
||||
|
||||
class Config(object):
|
||||
DEBUG = True
|
||||
NEWS_SPECIAL_PAGE = 42
|
||||
@@ -0,0 +1,4 @@
|
||||
from flask.ext.navigation import Navigation
|
||||
|
||||
|
||||
nav = Navigation()
|
||||
@@ -0,0 +1,60 @@
|
||||
from pytest import fixture
|
||||
from webtest import TestApp
|
||||
|
||||
from .app import create_app
|
||||
|
||||
|
||||
@fixture
|
||||
def app():
|
||||
app = create_app()
|
||||
return TestApp(app)
|
||||
|
||||
|
||||
def test_app(app):
|
||||
r = app.get('/')
|
||||
assert r.status == '200 OK'
|
||||
assert 'Welcome' in r
|
||||
assert_navbar_exists(r)
|
||||
assert_active(r, 'Home')
|
||||
|
||||
r = r.click('Latest News')
|
||||
assert r.status == '200 OK'
|
||||
assert 'News :: Page - 1' in r
|
||||
assert_navbar_exists(r)
|
||||
assert_active(r, 'Latest News')
|
||||
|
||||
r = r.click('Special News')
|
||||
assert r.status == '200 OK'
|
||||
assert 'News :: Page - 42' in r
|
||||
assert_navbar_exists(r)
|
||||
assert_active(r, 'Special News')
|
||||
|
||||
r = r.click('Home')
|
||||
assert r.status == '200 OK'
|
||||
assert 'Welcome' in r
|
||||
assert_navbar_exists(r)
|
||||
assert_active(r, 'Home')
|
||||
|
||||
|
||||
def test_alias(app):
|
||||
r = app.get('/news/1024')
|
||||
assert r.status == '200 OK'
|
||||
assert 'News :: Page - 1024' in r
|
||||
assert_navbar_exists(r)
|
||||
assert_active(r, '')
|
||||
|
||||
r = r.click('Back')
|
||||
assert r.status == '200 OK'
|
||||
assert 'Welcome' in r
|
||||
assert_navbar_exists(r)
|
||||
assert_active(r, 'Home')
|
||||
|
||||
|
||||
def assert_navbar_exists(r):
|
||||
assert 'Home' in r
|
||||
assert 'Latest News' in r
|
||||
assert 'Special News' in r
|
||||
|
||||
|
||||
def assert_active(r, text):
|
||||
assert r.pyquery('li.active > a').text().strip() == text
|
||||
@@ -0,0 +1,31 @@
|
||||
from flask import Blueprint, current_app, render_template
|
||||
|
||||
from .ext import nav
|
||||
|
||||
|
||||
bp = Blueprint('main', __name__)
|
||||
|
||||
navbar_top = nav.Bar('top', [
|
||||
nav.Item('Home', 'main.index'),
|
||||
nav.Item('Latest News', 'main.news', {'page': 1}),
|
||||
], alias={'index': nav.ItemReference('main.index')})
|
||||
|
||||
|
||||
@navbar_top.initializer
|
||||
def initialize_navbar_top(nav):
|
||||
top = nav['top']
|
||||
if len(top.items) > 2:
|
||||
return
|
||||
args = {'page': current_app.config['NEWS_SPECIAL_PAGE']}
|
||||
item = nav.Item('Special News', 'main.news', args)
|
||||
top.items.append(item)
|
||||
|
||||
|
||||
@bp.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
@bp.route('/news/<int:page>')
|
||||
def news(page):
|
||||
return render_template('news.html', page=page)
|
||||
Reference in New Issue
Block a user