mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 08:51:30 -05:00
Adds provider onto the inbound sms table so we know where this came from.
This commit is contained in:
@@ -1166,6 +1166,7 @@ class InboundSms(db.Model):
|
|||||||
user_number = db.Column(db.String, nullable=False) # the end user's number, that the msg was sent from
|
user_number = db.Column(db.String, nullable=False) # the end user's number, that the msg was sent from
|
||||||
provider_date = db.Column(db.DateTime)
|
provider_date = db.Column(db.DateTime)
|
||||||
provider_reference = db.Column(db.String)
|
provider_reference = db.Column(db.String)
|
||||||
|
provider = db.Column(db.String, nullable=True)
|
||||||
_content = db.Column('content', db.String, nullable=False)
|
_content = db.Column('content', db.String, nullable=False)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import iso8601
|
|||||||
from flask import jsonify, Blueprint, current_app, request
|
from flask import jsonify, Blueprint, current_app, request
|
||||||
from notifications_utils.recipients import normalise_phone_number
|
from notifications_utils.recipients import normalise_phone_number
|
||||||
|
|
||||||
from app import statsd_client
|
from app import statsd_client, firetext_client, mmg_client
|
||||||
from app.dao.services_dao import dao_fetch_services_by_sms_sender
|
from app.dao.services_dao import dao_fetch_services_by_sms_sender
|
||||||
from app.dao.inbound_sms_dao import dao_create_inbound_sms
|
from app.dao.inbound_sms_dao import dao_create_inbound_sms
|
||||||
from app.models import InboundSms
|
from app.models import InboundSms
|
||||||
@@ -78,6 +78,7 @@ def create_inbound_mmg_sms_object(service, json):
|
|||||||
provider_date=provider_date,
|
provider_date=provider_date,
|
||||||
provider_reference=json.get('ID'),
|
provider_reference=json.get('ID'),
|
||||||
content=message,
|
content=message,
|
||||||
|
provider=mmg_client.name
|
||||||
)
|
)
|
||||||
dao_create_inbound_sms(inbound)
|
dao_create_inbound_sms(inbound)
|
||||||
return inbound
|
return inbound
|
||||||
@@ -90,7 +91,7 @@ def receive_firetext_sms():
|
|||||||
potential_services = dao_fetch_services_by_sms_sender(post_data['destination'])
|
potential_services = dao_fetch_services_by_sms_sender(post_data['destination'])
|
||||||
if len(potential_services) != 1:
|
if len(potential_services) != 1:
|
||||||
current_app.logger.error('Inbound number "{}" not associated with exactly one service'.format(
|
current_app.logger.error('Inbound number "{}" not associated with exactly one service'.format(
|
||||||
post_data['source']
|
post_data['destination']
|
||||||
))
|
))
|
||||||
statsd_client.incr('inbound.firetext.failed')
|
statsd_client.incr('inbound.firetext.failed')
|
||||||
return jsonify({
|
return jsonify({
|
||||||
@@ -109,7 +110,8 @@ def receive_firetext_sms():
|
|||||||
notify_number=service.sms_sender,
|
notify_number=service.sms_sender,
|
||||||
user_number=user_number,
|
user_number=user_number,
|
||||||
provider_date=timestamp,
|
provider_date=timestamp,
|
||||||
content=message
|
content=message,
|
||||||
|
provider=firetext_client.name
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
22
migrations/versions/0090_add_inbound_provider.py
Normal file
22
migrations/versions/0090_add_inbound_provider.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 0090_add_inbound_provider
|
||||||
|
Revises: 0090_inbound_sms
|
||||||
|
Create Date: 2017-06-02 16:07:35.445423
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '0090_add_inbound_provider'
|
||||||
|
down_revision = '0090_inbound_sms'
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.add_column('inbound_sms', sa.Column('provider', sa.String(), nullable=True))
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_column('inbound_sms', 'provider')
|
||||||
@@ -70,6 +70,7 @@ def test_create_inbound_mmg_sms_object(sample_service):
|
|||||||
assert inbound_sms.provider_reference == 'bar'
|
assert inbound_sms.provider_reference == 'bar'
|
||||||
assert inbound_sms._content != 'hello there 📩'
|
assert inbound_sms._content != 'hello there 📩'
|
||||||
assert inbound_sms.content == 'hello there 📩'
|
assert inbound_sms.content == 'hello there 📩'
|
||||||
|
assert inbound_sms.provider == 'mmg'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('notify_number', ['foo', 'baz'], ids=['two_matching_services', 'no_matching_services'])
|
@pytest.mark.parametrize('notify_number', ['foo', 'baz'], ids=['two_matching_services', 'no_matching_services'])
|
||||||
@@ -136,6 +137,7 @@ def test_receive_notification_from_firetext_persists_message(notify_db_session,
|
|||||||
assert persisted.user_number == '7999999999'
|
assert persisted.user_number == '7999999999'
|
||||||
assert persisted.service == service
|
assert persisted.service == service
|
||||||
assert persisted.content == 'this is a message'
|
assert persisted.content == 'this is a message'
|
||||||
|
assert persisted.provider == 'firetext'
|
||||||
assert persisted.provider_date == datetime(2017, 1, 1, 12, 0, 0, 0)
|
assert persisted.provider_date == datetime(2017, 1, 1, 12, 0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user