mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:15:19 -05:00
Merge branch 'master' into add-template-version
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
import uuid
|
import uuid
|
||||||
import os
|
import os
|
||||||
from flask import request, url_for
|
from flask import request, url_for, g
|
||||||
from flask import Flask, _request_ctx_stack
|
from flask import Flask, _request_ctx_stack
|
||||||
from flask.ext.sqlalchemy import SQLAlchemy
|
from flask.ext.sqlalchemy import SQLAlchemy
|
||||||
from flask_marshmallow import Marshmallow
|
from flask_marshmallow import Marshmallow
|
||||||
|
from monotonic import monotonic
|
||||||
from werkzeug.local import LocalProxy
|
from werkzeug.local import LocalProxy
|
||||||
from notifications_utils import logging
|
from notifications_utils import logging
|
||||||
from app.celery.celery import NotifyCelery
|
from app.celery.celery import NotifyCelery
|
||||||
@@ -11,6 +12,7 @@ from app.clients import Clients
|
|||||||
from app.clients.sms.mmg import MMGClient
|
from app.clients.sms.mmg import MMGClient
|
||||||
from app.clients.sms.twilio import TwilioClient
|
from app.clients.sms.twilio import TwilioClient
|
||||||
from app.clients.sms.firetext import FiretextClient
|
from app.clients.sms.firetext import FiretextClient
|
||||||
|
from app.clients.sms.loadtesting import LoadtestingClient
|
||||||
from app.clients.email.aws_ses import AwsSesClient
|
from app.clients.email.aws_ses import AwsSesClient
|
||||||
from app.encryption import Encryption
|
from app.encryption import Encryption
|
||||||
|
|
||||||
@@ -22,6 +24,7 @@ ma = Marshmallow()
|
|||||||
notify_celery = NotifyCelery()
|
notify_celery = NotifyCelery()
|
||||||
twilio_client = TwilioClient()
|
twilio_client = TwilioClient()
|
||||||
firetext_client = FiretextClient()
|
firetext_client = FiretextClient()
|
||||||
|
loadtest_client = LoadtestingClient()
|
||||||
mmg_client = MMGClient()
|
mmg_client = MMGClient()
|
||||||
aws_ses_client = AwsSesClient()
|
aws_ses_client = AwsSesClient()
|
||||||
encryption = Encryption()
|
encryption = Encryption()
|
||||||
@@ -46,11 +49,12 @@ def create_app(app_name=None):
|
|||||||
logging.init_app(application)
|
logging.init_app(application)
|
||||||
twilio_client.init_app(application)
|
twilio_client.init_app(application)
|
||||||
firetext_client.init_app(application)
|
firetext_client.init_app(application)
|
||||||
|
loadtest_client.init_app(application)
|
||||||
mmg_client.init_app(application.config)
|
mmg_client.init_app(application.config)
|
||||||
aws_ses_client.init_app(application.config['AWS_REGION'])
|
aws_ses_client.init_app(application.config['AWS_REGION'])
|
||||||
notify_celery.init_app(application)
|
notify_celery.init_app(application)
|
||||||
encryption.init_app(application)
|
encryption.init_app(application)
|
||||||
clients.init_app(sms_clients=[firetext_client, mmg_client], email_clients=[aws_ses_client])
|
clients.init_app(sms_clients=[firetext_client, mmg_client, loadtest_client], email_clients=[aws_ses_client])
|
||||||
|
|
||||||
from app.service.rest import service as service_blueprint
|
from app.service.rest import service as service_blueprint
|
||||||
from app.user.rest import user as user_blueprint
|
from app.user.rest import user as user_blueprint
|
||||||
@@ -99,6 +103,10 @@ def init_app(app):
|
|||||||
if error:
|
if error:
|
||||||
return error
|
return error
|
||||||
|
|
||||||
|
@app.before_request
|
||||||
|
def record_start_time():
|
||||||
|
g.start = monotonic()
|
||||||
|
|
||||||
@app.after_request
|
@app.after_request
|
||||||
def after_request(response):
|
def after_request(response):
|
||||||
response.headers.add('Access-Control-Allow-Origin', '*')
|
response.headers.add('Access-Control-Allow-Origin', '*')
|
||||||
|
|||||||
18
app/clients/sms/loadtesting.py
Normal file
18
app/clients/sms/loadtesting.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import logging
|
||||||
|
from app.clients.sms.firetext import (
|
||||||
|
FiretextClient
|
||||||
|
)
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class LoadtestingClient(FiretextClient):
|
||||||
|
'''
|
||||||
|
Loadtest sms client.
|
||||||
|
'''
|
||||||
|
|
||||||
|
def init_app(self, config, *args, **kwargs):
|
||||||
|
super(FiretextClient, self).__init__(*args, **kwargs)
|
||||||
|
self.api_key = config.config.get('LOADTESTING_API_KEY')
|
||||||
|
self.from_number = config.config.get('LOADTESTING_NUMBER')
|
||||||
|
self.name = 'loadtesting'
|
||||||
@@ -82,6 +82,8 @@ class Config(object):
|
|||||||
TWILIO_NUMBER = os.getenv('TWILIO_NUMBER')
|
TWILIO_NUMBER = os.getenv('TWILIO_NUMBER')
|
||||||
FIRETEXT_NUMBER = os.getenv('FIRETEXT_NUMBER')
|
FIRETEXT_NUMBER = os.getenv('FIRETEXT_NUMBER')
|
||||||
FIRETEXT_API_KEY = os.getenv("FIRETEXT_API_KEY")
|
FIRETEXT_API_KEY = os.getenv("FIRETEXT_API_KEY")
|
||||||
|
LOADTESTING_NUMBER = os.getenv('LOADTESTING_NUMBER')
|
||||||
|
LOADTESTING_API_KEY = os.getenv("LOADTESTING_API_KEY")
|
||||||
CSV_UPLOAD_BUCKET_NAME = 'local-notifications-csv-upload'
|
CSV_UPLOAD_BUCKET_NAME = 'local-notifications-csv-upload'
|
||||||
NOTIFICATIONS_ALERT = 5 # five mins
|
NOTIFICATIONS_ALERT = 5 # five mins
|
||||||
|
|
||||||
|
|||||||
@@ -19,4 +19,6 @@ export FIRETEXT_API_KEY="Firetext"
|
|||||||
export FIRETEXT_NUMBER="Firetext"
|
export FIRETEXT_NUMBER="Firetext"
|
||||||
export NOTIFY_EMAIL_DOMAIN="test.notify.com"
|
export NOTIFY_EMAIL_DOMAIN="test.notify.com"
|
||||||
export MMG_API_KEY='mmg-secret-key'
|
export MMG_API_KEY='mmg-secret-key'
|
||||||
export MMG_FROM_NUMBER='test'
|
export MMG_FROM_NUMBER='test'
|
||||||
|
export LOADTESTING_API_KEY="loadtesting"
|
||||||
|
export LOADTESTING_NUMBER="loadtesting"
|
||||||
|
|||||||
27
migrations/versions/0013_add_loadtest_client.py
Normal file
27
migrations/versions/0013_add_loadtest_client.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 0013_add_loadtest_client
|
||||||
|
Revises: 0012_complete_provider_details
|
||||||
|
Create Date: 2016-05-05 09:14:29.328841
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '0013_add_loadtest_client'
|
||||||
|
down_revision = '0012_complete_provider_details'
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
|
||||||
|
op.execute(
|
||||||
|
"INSERT INTO provider_details (id, display_name, identifier, priority, notification_type, active) values ('{}', 'Loadtesting', 'loadtesting', 30, 'sms', true)".format(str(uuid.uuid4()))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_table('provider_details')
|
||||||
@@ -22,4 +22,4 @@ monotonic==0.3
|
|||||||
git+https://github.com/alphagov/notifications-python-client.git@1.0.0#egg=notifications-python-client==1.0.0
|
git+https://github.com/alphagov/notifications-python-client.git@1.0.0#egg=notifications-python-client==1.0.0
|
||||||
|
|
||||||
|
|
||||||
git+https://github.com/alphagov/notifications-utils.git@5.2.0#egg=notifications-utils==5.2.0
|
git+https://github.com/alphagov/notifications-utils.git@5.2.3#egg=notifications-utils==5.2.3
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ from app.dao.provider_details_dao import (
|
|||||||
|
|
||||||
|
|
||||||
def test_can_get_all_providers(notify_db, notify_db_session):
|
def test_can_get_all_providers(notify_db, notify_db_session):
|
||||||
assert len(get_provider_details()) == 3
|
assert len(get_provider_details()) == 4
|
||||||
|
|
||||||
|
|
||||||
def test_can_get_sms_providers(notify_db, notify_db_session):
|
def test_can_get_sms_providers(notify_db, notify_db_session):
|
||||||
assert len(get_provider_details_by_notification_type('sms')) == 2
|
assert len(get_provider_details_by_notification_type('sms')) == 3
|
||||||
types = [provider.notification_type for provider in get_provider_details_by_notification_type('sms')]
|
types = [provider.notification_type for provider in get_provider_details_by_notification_type('sms')]
|
||||||
assert all('sms' == notification_type for notification_type in types)
|
assert all('sms' == notification_type for notification_type in types)
|
||||||
|
|
||||||
@@ -21,6 +21,7 @@ def test_can_get_sms_providers_in_order(notify_db, notify_db_session):
|
|||||||
|
|
||||||
assert providers[0].identifier == "mmg"
|
assert providers[0].identifier == "mmg"
|
||||||
assert providers[1].identifier == "firetext"
|
assert providers[1].identifier == "firetext"
|
||||||
|
assert providers[2].identifier == "loadtesting"
|
||||||
|
|
||||||
|
|
||||||
def test_can_get_email_providers_in_order(notify_db, notify_db_session):
|
def test_can_get_email_providers_in_order(notify_db, notify_db_session):
|
||||||
|
|||||||
@@ -12,11 +12,12 @@ def test_get_provider_details_in_type_and_identifier_order(notify_db, notify_db_
|
|||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
json_resp = json.loads(response.get_data(as_text=True))['provider_details']
|
json_resp = json.loads(response.get_data(as_text=True))['provider_details']
|
||||||
assert len(json_resp) == 3
|
assert len(json_resp) == 4
|
||||||
|
|
||||||
assert json_resp[0]['identifier'] == 'ses'
|
assert json_resp[0]['identifier'] == 'ses'
|
||||||
assert json_resp[1]['identifier'] == 'mmg'
|
assert json_resp[1]['identifier'] == 'mmg'
|
||||||
assert json_resp[2]['identifier'] == 'firetext'
|
assert json_resp[2]['identifier'] == 'firetext'
|
||||||
|
assert json_resp[3]['identifier'] == 'loadtesting'
|
||||||
|
|
||||||
|
|
||||||
def test_get_provider_details_by_id(notify_db, notify_db_session, notify_api):
|
def test_get_provider_details_by_id(notify_db, notify_db_session, notify_api):
|
||||||
|
|||||||
Reference in New Issue
Block a user