예제 #1
0
def client_without_env_app_id(app, mocker):
    with app.test_request_context(), app.test_client() as client:
        mocker.patch.dict(os.environ, {'VCAP_APPLICATION': '{}'})

        metrics = GDSMetrics()
        metrics.init_app(app)

        yield client
def test_teardown_requests_doesnt_record_duration_metric_if_gds_metrics_start_time_not_set(mocker):
    app = Flask(__name__)
    with app.test_request_context():
        assert not hasattr(g, "_gds_metrics_start_time")
        duration_metric = mocker.patch('gds_metrics.HTTP_SERVER_REQUEST_DURATION_SECONDS.labels')
        count_metric = mocker.patch('gds_metrics.HTTP_SERVER_REQUESTS_TOTAL.labels')
        gds_metrics = GDSMetrics()

        gds_metrics.teardown_request(sender=Mock(), response=Mock())

        assert not duration_metric.called
        assert count_metric.called
예제 #3
0
def client_without_basic_auth(app, mocker):
    with app.test_request_context(), app.test_client() as client:
        mocker.patch.dict(
            os.environ, {
                'VCAP_APPLICATION':
                '{"application_id": "' + FAKE_APP_ID + '"}',
                'METRICS_BASIC_AUTH': 'false'
            })

        metrics = GDSMetrics()
        metrics.init_app(app)

        yield client
예제 #4
0
def create_app(scriptinfo):
    app = Flask(__name__,
                static_url_path="/assets",
                instance_relative_config=True)
    app.config.from_envvar("FLASK_CONFIG_FILE")
    verify_config(app)
    metrics = GDSMetrics()
    metrics.init_app(app)
    app.jinja_loader = ChoiceLoader([
        PackageLoader("vulnerable_people_form"),
        PrefixLoader(
            {"govuk_frontend_jinja": PackageLoader("govuk_frontend_jinja")}),
    ])

    sentry_sdk.init(
        dsn=app.config["SENTRY_DSN"],
        integrations=[FlaskIntegration()],
        with_locals=False,
        request_bodies='never',
    )

    app.register_blueprint(form_pages.default.app_default)
    app.register_blueprint(form_pages.blueprint.form)

    _init_security(app)

    app.nhs_oidc_client = nhs_openconnect_id.NHSOIDCDetails()
    app.nhs_oidc_client.init_app(app)

    persistence.init_app(app)

    app.is_tiering_logic_enabled = "TIERING_LOGIC" in app.config and app.config[
        "TIERING_LOGIC"] == "True"

    app.register_error_handler(HTTPStatus.NOT_FOUND.value, _handle_error)
    app.register_error_handler(HTTPStatus.INTERNAL_SERVER_ERROR.value,
                               _handle_error)
    app.context_processor(utility_processor)

    app.add_template_filter(postcode_with_spaces)

    return app
예제 #5
0
db = SQLAlchemy()
migrate = Migrate()
ma = Marshmallow()
notify_celery = NotifyCelery()
firetext_client = FiretextClient()
mmg_client = MMGClient()
aws_ses_client = AwsSesClient()
aws_ses_stub_client = AwsSesStubClient()
encryption = Encryption()
zendesk_client = ZendeskClient()
statsd_client = StatsdClient()
redis_store = RedisClient()
performance_platform_client = PerformancePlatformClient()
cbc_proxy_client = CBCProxyClient()
document_download_client = DocumentDownloadClient()
metrics = GDSMetrics()

notification_provider_clients = NotificationProviderClients()

api_user = LocalProxy(lambda: _request_ctx_stack.top.api_user)
authenticated_service = LocalProxy(
    lambda: _request_ctx_stack.top.authenticated_service)

CONCURRENT_REQUESTS = Gauge(
    'concurrent_web_request_count',
    'How many concurrent requests are currently being served',
)


def create_app(application):
    from app.config import configs
예제 #6
0
import os
from datetime import datetime
from flask import Flask, request
from gds_metrics import GDSMetrics

app = Flask(__name__)

metrics = GDSMetrics()
metrics.init_app(app)

app_name = os.getenv("APP_NAME", "test-flask")
port = int(os.getenv("PORT", 5000))


@app.route('/')
def index():
    return '{}, I am running on port {}'.format(app_name, port)


@app.before_request
def before_request():
    print(datetime.now(), request.endpoint)


if __name__ == '__main__':
    print('running on port: {}'.format(port))
    app.run(host='0.0.0.0', port=port)
예제 #7
0
def client(app):
    with app.test_request_context(), app.test_client() as client:
        metrics = GDSMetrics()
        metrics.init_app(app)

        yield client
예제 #8
0
from flask import Flask
from notifications_utils import logging, request_helper
from gds_metrics import GDSMetrics

from app.config import configs
from app.utils.store import DocumentStore
from app.utils.antivirus import AntivirusClient

document_store = DocumentStore() # noqa, has to be imported before views
antivirus_client = AntivirusClient() # noqa
metrics = GDSMetrics() # noqa

from .download.views import download_blueprint
from .upload.views import upload_blueprint


def create_app():
    application = Flask('app')
    application.config.from_object(configs[application.env])

    request_helper.init_app(application)
    logging.init_app(application)

    document_store.init_app(application)
    antivirus_client.init_app(application)
    metrics.init_app(application)

    application.register_blueprint(download_blueprint)
    application.register_blueprint(upload_blueprint)

    return application