Coverage for webapp/app.py: 93%
69 statements
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-05 22:06 +0000
« prev ^ index » next coverage.py v7.10.2, created at 2025-08-05 22:06 +0000
1"""
2A Flask application for snapcraft.io.
4The web frontend for the snap store.
5"""
7import talisker.requests
8import webapp.api
10from talisker import logging
12from canonicalwebteam.flask_base.app import FlaskBase
13from webapp.blog.views import init_blog
14from webapp.docs.views import init_docs
15from webapp.extensions import csrf
16from webapp.first_snap.views import first_snap
17from webapp.handlers import set_handlers
18from webapp.login.views import login
19from webapp.login.oauth_views import oauth
20from webapp.publisher.snaps.views import publisher_snaps
21from webapp.publisher.github.views import publisher_github
22from webapp.admin.views import admin
23from webapp.publisher.views import account
24from webapp.snapcraft.views import snapcraft_blueprint
25from webapp.store.views import store_blueprint
26from webapp.tutorials.views import init_tutorials
27from webapp.packages.store_packages import store_packages
28from webapp.endpoints.views import endpoints
29from webapp.endpoints.signing_keys import signing_keys
30from webapp.endpoints.models import models
31from webapp.endpoints.members import members
32from webapp.endpoints.snaps import snaps
33from webapp.endpoints.snap_search import snap_search
34from webapp.endpoints.validation_sets import validation_sets
35from webapp.endpoints.invites import invites
36from webapp.endpoints.settings import settings
39TALISKER_WSGI_LOGGER = logging.getLogger("talisker.wsgi")
42def create_app(testing=False):
43 app = FlaskBase(
44 __name__,
45 "snapcraft.io",
46 favicon_url="https://assets.ubuntu.com/v1/d4ca039f-favicon_16px.png",
47 template_404="404.html",
48 template_folder="../templates",
49 static_folder="../static",
50 )
51 app.config.from_object("webapp.config")
52 app.name = "snapcraft"
53 app.testing = testing
55 if not testing:
56 init_extensions(app)
57 talisker.requests.configure(webapp.api.sso.api_session)
58 talisker.requests.configure(webapp.helpers.api_session)
59 talisker.requests.configure(webapp.helpers.api_publisher_session)
61 if testing:
63 @app.context_processor
64 def inject_csrf_token():
65 return dict(csrf_token=lambda: "mocked_csrf_token")
67 set_handlers(app)
69 app.register_blueprint(snapcraft_blueprint())
70 app.register_blueprint(store_packages)
71 app.register_blueprint(first_snap, url_prefix="/first-snap")
72 app.register_blueprint(login)
73 app.register_blueprint(oauth)
74 app.register_blueprint(store_blueprint())
75 app.register_blueprint(account, url_prefix="/account")
76 app.register_blueprint(publisher_snaps)
77 app.register_blueprint(publisher_github)
78 app.register_blueprint(admin)
79 app.register_blueprint(endpoints)
80 app.register_blueprint(signing_keys)
81 app.register_blueprint(models)
82 app.register_blueprint(members)
83 app.register_blueprint(snaps)
84 app.register_blueprint(snap_search)
85 app.register_blueprint(validation_sets)
86 app.register_blueprint(invites)
87 app.register_blueprint(settings)
88 init_docs(app, "/docs")
89 init_blog(app, "/blog")
90 init_tutorials(app, "/tutorials")
92 return app
95def init_extensions(app):
96 csrf.init_app(app)