Coverage for webapp/app.py: 97%
66 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-14 22:07 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-14 22:07 +0000
1"""
2A Flask application for snapcraft.io.
4The web frontend for the snap store.
5"""
7# We import the config module before anything else to make sure env vars are
8# loaded properly and the FLASK_* prefix is stripped before they are parsed
9import webapp.config # noqa: F401
11import sentry_sdk
13from canonicalwebteam.flask_base.app import FlaskBase
14from webapp.blog.views import init_blog
15from webapp.docs.views import init_docs
16from webapp.extensions import csrf
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
37from webapp.feeds.feeds import feeds
38from webapp.config import SENTRY_DSN
41def create_app(testing=False):
42 sentry_sdk.init(dsn=SENTRY_DSN)
44 app = FlaskBase(
45 __name__,
46 "snapcraft.io",
47 favicon_url="https://assets.ubuntu.com/v1/d4ca039f-favicon_16px.png",
48 template_404="404.html",
49 template_folder="../templates",
50 static_folder="../static",
51 )
52 app.config.from_object("webapp.config")
53 app.name = "snapcraft"
54 app.testing = testing
56 if not testing:
57 init_extensions(app)
59 if testing:
61 @app.context_processor
62 def inject_csrf_token():
63 return dict(csrf_token=lambda: "mocked_csrf_token")
65 set_handlers(app)
67 app.register_blueprint(snapcraft_blueprint())
68 app.register_blueprint(store_packages)
69 app.register_blueprint(login)
70 app.register_blueprint(oauth)
71 app.register_blueprint(store_blueprint())
72 app.register_blueprint(account, url_prefix="/account")
73 app.register_blueprint(publisher_snaps)
74 app.register_blueprint(publisher_github)
75 app.register_blueprint(admin)
76 app.register_blueprint(endpoints)
77 app.register_blueprint(signing_keys)
78 app.register_blueprint(models)
79 app.register_blueprint(members)
80 app.register_blueprint(snaps)
81 app.register_blueprint(snap_search)
82 app.register_blueprint(validation_sets)
83 app.register_blueprint(invites)
84 app.register_blueprint(settings)
85 app.register_blueprint(feeds)
86 init_docs(app, "/docs")
87 init_blog(app, "/blog")
88 init_tutorials(app, "/tutorials")
90 return app
93def init_extensions(app):
94 csrf.init_app(app)