def test_blocked(): blocklist = [re_compile(r"^.+example\.com$", IGNORECASE)] assert Short.query.count() == 0 Short.generate(target="http://www.example.org") Short.generate(target="https://example.org") one = Short.generate(target="http://www.example.com") two = Short.generate(target="https://example.com") assert Short.query.count() == 4 assert Short.blocked([]).all() == [] assert Short.blocked(blocklist).all() == [one, two] assert Short.blocked(blocklist, rev=True).all() == [two, one]
def block(page=None, field=None, sort=None): query = Short.blocked(BLOCKLIST, field=field, rev=sort == "desc") if not query: abort(404) return render_template( "plus/show.html", title="Blocked", elements=query.paginate( page=page, per_page=current_app.config["PAGINATION"] ), )