mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-23 15:56:45 -04:00
New endpoint to set ServiceInboundApi data.
This commit is contained in:
@@ -20,6 +20,7 @@ from app.dao.api_key_dao import (
|
|||||||
expire_api_key)
|
expire_api_key)
|
||||||
from app.dao.date_util import get_financial_year
|
from app.dao.date_util import get_financial_year
|
||||||
from app.dao.notification_usage_dao import get_total_billable_units_for_sent_sms_notifications_in_date_range
|
from app.dao.notification_usage_dao import get_total_billable_units_for_sent_sms_notifications_in_date_range
|
||||||
|
from app.dao.service_inbound_api_dao import save_service_inbound_api
|
||||||
from app.dao.services_dao import (
|
from app.dao.services_dao import (
|
||||||
dao_fetch_service_by_id,
|
dao_fetch_service_by_id,
|
||||||
dao_fetch_all_services,
|
dao_fetch_all_services,
|
||||||
@@ -49,7 +50,7 @@ from app.errors import (
|
|||||||
InvalidRequest,
|
InvalidRequest,
|
||||||
register_errors
|
register_errors
|
||||||
)
|
)
|
||||||
from app.models import Service
|
from app.models import Service, ServiceInboundApi
|
||||||
from app.service import statistics
|
from app.service import statistics
|
||||||
from app.service.utils import get_whitelist_objects
|
from app.service.utils import get_whitelist_objects
|
||||||
from app.service.sender import send_notification_to_service_users
|
from app.service.sender import send_notification_to_service_users
|
||||||
@@ -531,3 +532,12 @@ def get_yearly_monthly_usage(service_id):
|
|||||||
return json.dumps(json_results)
|
return json.dumps(json_results)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return jsonify(result='error', message='No valid year provided'), 400
|
return jsonify(result='error', message='No valid year provided'), 400
|
||||||
|
|
||||||
|
|
||||||
|
@service_blueprint.route('/<uuid:service_id>/inbound-api', methods=['POST'])
|
||||||
|
def set_service_inbound_api(service_id):
|
||||||
|
data = request.get_json()
|
||||||
|
data["service_id"] = service_id
|
||||||
|
save_service_inbound_api(ServiceInboundApi(**data))
|
||||||
|
|
||||||
|
return jsonify(data="Service inbound api data saved"), 201
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
|
|
||||||
from app.dao.service_inbound_api_dao import save_service_inbound_api
|
from app.dao.service_inbound_api_dao import save_service_inbound_api
|
||||||
from app.models import ServiceInboundApi
|
from app.models import ServiceInboundApi
|
||||||
|
|
||||||
@@ -18,3 +23,14 @@ def test_save_service_inbound_api(sample_service):
|
|||||||
assert results[0].url == "https::/some_service/inbound_messages"
|
assert results[0].url == "https::/some_service/inbound_messages"
|
||||||
assert results[0].unsigned_bearer_token == "some_unique_string"
|
assert results[0].unsigned_bearer_token == "some_unique_string"
|
||||||
assert results[0].bearer_token != "some_unique_string"
|
assert results[0].bearer_token != "some_unique_string"
|
||||||
|
|
||||||
|
|
||||||
|
def test_save_service_inbound_api_fails_if_service_doesnot_exist(notify_db, notify_db_session):
|
||||||
|
service_inbound_api = ServiceInboundApi(
|
||||||
|
service_id=uuid.uuid4(),
|
||||||
|
url="https::/some_service/inbound_messages",
|
||||||
|
bearer_token="some_unique_string"
|
||||||
|
)
|
||||||
|
|
||||||
|
with pytest.raises(SQLAlchemyError):
|
||||||
|
save_service_inbound_api(service_inbound_api)
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ from app.models import (
|
|||||||
Organisation, Rate, Service, ServicePermission, User,
|
Organisation, Rate, Service, ServicePermission, User,
|
||||||
KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST,
|
KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST,
|
||||||
EMAIL_TYPE, SMS_TYPE, LETTER_TYPE, INTERNATIONAL_SMS_TYPE, INBOUND_SMS_TYPE,
|
EMAIL_TYPE, SMS_TYPE, LETTER_TYPE, INTERNATIONAL_SMS_TYPE, INBOUND_SMS_TYPE,
|
||||||
DVLA_ORG_LAND_REGISTRY
|
DVLA_ORG_LAND_REGISTRY,
|
||||||
)
|
ServiceInboundApi)
|
||||||
from tests import create_authorization_header
|
from tests import create_authorization_header
|
||||||
from tests.app.db import create_template
|
from tests.app.db import create_template
|
||||||
from tests.app.conftest import (
|
from tests.app.conftest import (
|
||||||
@@ -27,7 +27,6 @@ from tests.app.conftest import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from tests.app.db import create_user
|
from tests.app.db import create_user
|
||||||
from tests.conftest import set_config_values
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_service_list(client, service_factory):
|
def test_get_service_list(client, service_factory):
|
||||||
@@ -2149,3 +2148,23 @@ def test_search_for_notification_by_to_field_returns_content(
|
|||||||
assert notifications[0]['id'] == str(notification.id)
|
assert notifications[0]['id'] == str(notification.id)
|
||||||
assert notifications[0]['to'] == '+447700900855'
|
assert notifications[0]['to'] == '+447700900855'
|
||||||
assert notifications[0]['body'] == 'Hello Foo\nYour thing is due soon'
|
assert notifications[0]['body'] == 'Hello Foo\nYour thing is due soon'
|
||||||
|
|
||||||
|
|
||||||
|
def test_set_service_inbound_api(client, sample_service):
|
||||||
|
data = {
|
||||||
|
"url": "https://some_service/inbound-sms",
|
||||||
|
"bearer_token": "some-unique-string"
|
||||||
|
}
|
||||||
|
response = client.post(
|
||||||
|
'/service/{}/inbound-api'.format(sample_service.id),
|
||||||
|
data=json.dumps(data),
|
||||||
|
headers=[('Content-Type', 'application/json'), create_authorization_header()]
|
||||||
|
)
|
||||||
|
assert response.status_code == 201
|
||||||
|
|
||||||
|
api_data = ServiceInboundApi.query.all()
|
||||||
|
assert len(api_data) == 1
|
||||||
|
assert api_data[0].service_id == sample_service.id
|
||||||
|
assert api_data[0].url == "https://some_service/inbound-sms"
|
||||||
|
assert api_data[0].unsigned_bearer_token == "some-unique-string"
|
||||||
|
assert api_data[0].bearer_token != "some-unique-string"
|
||||||
|
|||||||
Reference in New Issue
Block a user