mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-24 00:06:16 -04:00
Updated tests for fetch notifications by id, not simply fetch all
This commit is contained in:
@@ -24,7 +24,6 @@ def requires_auth():
|
|||||||
try:
|
try:
|
||||||
auth_token = auth_header[7:]
|
auth_token = auth_header[7:]
|
||||||
api_client = fetch_client(get_token_issuer(auth_token))
|
api_client = fetch_client(get_token_issuer(auth_token))
|
||||||
|
|
||||||
if api_client is None:
|
if api_client is None:
|
||||||
authentication_response("Invalid credentials", 403)
|
authentication_response("Invalid credentials", 403)
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ mobile_regex = re.compile("^\\+44[\\d]{10}$")
|
|||||||
notifications = Blueprint('notifications', __name__)
|
notifications = Blueprint('notifications', __name__)
|
||||||
|
|
||||||
|
|
||||||
@notifications.route('/', methods=['GET'])
|
@notifications.route('/<notification_id>', methods=['GET'])
|
||||||
def get_notifications():
|
def get_notifications(notification_id):
|
||||||
return jsonify(notify_alpha_client.fetch_notifications()), 200
|
return jsonify(notify_alpha_client.fetch_notification_by_id(notification_id)), 200
|
||||||
|
|
||||||
|
|
||||||
@notifications.route('/sms', methods=['POST'])
|
@notifications.route('/sms', methods=['POST'])
|
||||||
|
|||||||
@@ -15,4 +15,4 @@ git+https://github.com/alphagov/notifications-python-client.git@0.1.5#egg=notifi
|
|||||||
|
|
||||||
git+https://github.com/alphagov/notifications-utils.git@0.0.3#egg=notifications-utils==0.0.3
|
git+https://github.com/alphagov/notifications-utils.git@0.0.3#egg=notifications-utils==0.0.3
|
||||||
|
|
||||||
git+https://github.com/alphagov/notify-api-client.git@0.1.5#egg=notify-api-client==0.1.5
|
git+https://github.com/alphagov/notify-api-client.git@0.1.6#egg=notify-api-client==0.1.6
|
||||||
|
|||||||
@@ -30,5 +30,5 @@ display_result $? 1 "Code style check"
|
|||||||
#display_result $? 2 "Code coverage"
|
#display_result $? 2 "Code coverage"
|
||||||
|
|
||||||
|
|
||||||
py.test -v
|
py.test -v tests/
|
||||||
display_result $? 3 "Unit tests"
|
display_result $? 3 "Unit tests"
|
||||||
@@ -11,7 +11,7 @@ def test_get_notifications(
|
|||||||
with notify_api.test_request_context():
|
with notify_api.test_request_context():
|
||||||
with notify_api.test_client() as client:
|
with notify_api.test_client() as client:
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'app.notify_alpha_client.fetch_notifications',
|
'app.notify_alpha_client.fetch_notification_by_id',
|
||||||
return_value={
|
return_value={
|
||||||
'notifications': [
|
'notifications': [
|
||||||
{
|
{
|
||||||
@@ -24,11 +24,11 @@ def test_get_notifications(
|
|||||||
|
|
||||||
auth_header = create_authorization_header(
|
auth_header = create_authorization_header(
|
||||||
service_id=sample_admin_service_id,
|
service_id=sample_admin_service_id,
|
||||||
path=url_for('notifications.get_notifications'),
|
path=url_for('notifications.get_notifications', notification_id=123),
|
||||||
method='GET')
|
method='GET')
|
||||||
|
|
||||||
response = client.get(
|
response = client.get(
|
||||||
url_for('notifications.get_notifications'),
|
url_for('notifications.get_notifications', notification_id=123),
|
||||||
headers=[auth_header])
|
headers=[auth_header])
|
||||||
|
|
||||||
json_resp = json.loads(response.get_data(as_text=True))
|
json_resp = json.loads(response.get_data(as_text=True))
|
||||||
@@ -36,7 +36,7 @@ def test_get_notifications(
|
|||||||
assert len(json_resp['notifications']) == 1
|
assert len(json_resp['notifications']) == 1
|
||||||
assert json_resp['notifications'][0]['id'] == 'my_id'
|
assert json_resp['notifications'][0]['id'] == 'my_id'
|
||||||
assert json_resp['notifications'][0]['notification'] == 'some notify'
|
assert json_resp['notifications'][0]['notification'] == 'some notify'
|
||||||
assert notify_alpha_client.fetch_notifications.called
|
notify_alpha_client.fetch_notification_by_id.assert_called_with("123")
|
||||||
|
|
||||||
|
|
||||||
def test_get_notifications_empty_result(
|
def test_get_notifications_empty_result(
|
||||||
@@ -47,7 +47,7 @@ def test_get_notifications_empty_result(
|
|||||||
with notify_api.test_request_context():
|
with notify_api.test_request_context():
|
||||||
with notify_api.test_client() as client:
|
with notify_api.test_client() as client:
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'app.notify_alpha_client.fetch_notifications',
|
'app.notify_alpha_client.fetch_notification_by_id',
|
||||||
return_value={
|
return_value={
|
||||||
'notifications': [
|
'notifications': [
|
||||||
]
|
]
|
||||||
@@ -56,17 +56,17 @@ def test_get_notifications_empty_result(
|
|||||||
|
|
||||||
auth_header = create_authorization_header(
|
auth_header = create_authorization_header(
|
||||||
service_id=sample_admin_service_id,
|
service_id=sample_admin_service_id,
|
||||||
path=url_for('notifications.get_notifications'),
|
path=url_for('notifications.get_notifications', notification_id=123),
|
||||||
method='GET')
|
method='GET')
|
||||||
|
|
||||||
response = client.get(
|
response = client.get(
|
||||||
url_for('notifications.get_notifications'),
|
url_for('notifications.get_notifications', notification_id=123),
|
||||||
headers=[auth_header])
|
headers=[auth_header])
|
||||||
|
|
||||||
json_resp = json.loads(response.get_data(as_text=True))
|
json_resp = json.loads(response.get_data(as_text=True))
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert len(json_resp['notifications']) == 0
|
assert len(json_resp['notifications']) == 0
|
||||||
assert notify_alpha_client.fetch_notifications.called
|
notify_alpha_client.fetch_notification_by_id.assert_called_with("123")
|
||||||
|
|
||||||
|
|
||||||
def test_should_reject_if_no_phone_numbers(
|
def test_should_reject_if_no_phone_numbers(
|
||||||
|
|||||||
Reference in New Issue
Block a user