mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Fixed up the get_notitication endpoint
- returns a notification
This commit is contained in:
@@ -3,7 +3,8 @@ from app.models import Notification
|
||||
from app.dao.notifications_dao import (
|
||||
save_notification,
|
||||
get_notification,
|
||||
get_notifications
|
||||
get_notification_for_job,
|
||||
get_notifications_for_job
|
||||
)
|
||||
|
||||
|
||||
@@ -31,6 +32,13 @@ def test_save_notification(notify_db, notify_db_session, sample_template, sample
|
||||
assert 'sent' == notification_from_db.status
|
||||
|
||||
|
||||
def test_get_notification(notify_db, notify_db_session, sample_notification):
|
||||
notifcation_from_db = get_notification(
|
||||
sample_notification.service.id,
|
||||
sample_notification.id)
|
||||
assert sample_notification == notifcation_from_db
|
||||
|
||||
|
||||
def test_save_notification_no_job_id(notify_db, notify_db_session, sample_template):
|
||||
|
||||
assert Notification.query.count() == 0
|
||||
@@ -54,9 +62,10 @@ def test_save_notification_no_job_id(notify_db, notify_db_session, sample_templa
|
||||
|
||||
|
||||
def test_get_notification_for_job(notify_db, notify_db_session, sample_notification):
|
||||
notifcation_from_db = get_notification(sample_notification.service.id,
|
||||
sample_notification.job_id,
|
||||
sample_notification.id)
|
||||
notifcation_from_db = get_notification_for_job(
|
||||
sample_notification.service.id,
|
||||
sample_notification.job_id,
|
||||
sample_notification.id)
|
||||
assert sample_notification == notifcation_from_db
|
||||
|
||||
|
||||
@@ -70,7 +79,7 @@ def test_get_all_notifications_for_job(notify_db, notify_db_session, sample_job)
|
||||
template=sample_job.template,
|
||||
job=sample_job)
|
||||
|
||||
notifcations_from_db = get_notifications(sample_job.service.id, sample_job.id)
|
||||
notifcations_from_db = get_notifications_for_job(sample_job.service.id, sample_job.id)
|
||||
assert len(notifcations_from_db) == 5
|
||||
|
||||
|
||||
|
||||
@@ -4,46 +4,49 @@ import uuid
|
||||
from tests import create_authorization_header
|
||||
from flask import url_for, json
|
||||
from app.models import Service
|
||||
from tests.app.conftest import sample_service as create_sample_service
|
||||
from tests.app.conftest import sample_template as create_sample_template
|
||||
|
||||
|
||||
def test_get_notifications(
|
||||
notify_api, notify_db, notify_db_session, sample_api_key, mocker):
|
||||
notify_api, notify_db, notify_db_session, sample_api_key, sample_notification):
|
||||
"""
|
||||
Tests GET endpoint '/' to retrieve entire service list.
|
||||
"""
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_api_key.service_id,
|
||||
path=url_for('notifications.get_notifications', notification_id=123),
|
||||
service_id=sample_notification.service_id,
|
||||
path='/notifications/{}'.format(sample_notification.id),
|
||||
method='GET')
|
||||
|
||||
response = client.get(
|
||||
url_for('notifications.get_notifications', notification_id=123),
|
||||
'/notifications/{}'.format(sample_notification.id),
|
||||
headers=[auth_header])
|
||||
|
||||
notification = json.loads(response.get_data(as_text=True))['notification']
|
||||
assert notification['status'] == 'sent'
|
||||
assert notification['template'] == sample_notification.template.id
|
||||
assert notification['to'] == '+44709123456'
|
||||
assert notification['service'] == str(sample_notification.service_id)
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_get_notifications_empty_result(
|
||||
notify_api, notify_db, notify_db_session, sample_api_key, mocker):
|
||||
"""
|
||||
Tests GET endpoint '/' to retrieve entire service list.
|
||||
"""
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
id = uuid.uuid4()
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
service_id=sample_api_key.service_id,
|
||||
path=url_for('notifications.get_notifications', notification_id=123),
|
||||
path=url_for('notifications.get_notifications', notification_id=id),
|
||||
method='GET')
|
||||
|
||||
response = client.get(
|
||||
url_for('notifications.get_notifications', notification_id=123),
|
||||
url_for('notifications.get_notifications', notification_id=id),
|
||||
headers=[auth_header])
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
def test_create_sms_should_reject_if_no_phone_numbers(
|
||||
|
||||
Reference in New Issue
Block a user