mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-05 08:40:29 -04:00
Replaced first queries with one queries, which throws a NoResultFound.
Able to remove many of the None checks as a result of this. Fixed the tests were needed.
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
from datetime import datetime, timedelta
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from app import db
|
||||
|
||||
from app.models import InvitedUser
|
||||
@@ -50,8 +54,9 @@ def test_get_invited_user_by_id(notify_db, notify_db_session, sample_invited_use
|
||||
def test_get_unknown_invited_user_returns_none(notify_db, notify_db_session, sample_service):
|
||||
unknown_id = uuid.uuid4()
|
||||
|
||||
unknown = get_invited_user(sample_service.id, unknown_id)
|
||||
assert unknown is None
|
||||
with pytest.raises(NoResultFound) as e:
|
||||
get_invited_user(sample_service.id, unknown_id)
|
||||
assert 'No row was found for one()' in str(e.value)
|
||||
|
||||
|
||||
def test_get_invited_users_for_service(notify_db, notify_db_session, sample_service):
|
||||
|
||||
@@ -171,4 +171,6 @@ def test_cannot_get_service_by_id_and_owned_by_different_user(service_factory, s
|
||||
save_model_user(new_user)
|
||||
service2 = service_factory.get('service 2', new_user)
|
||||
assert dao_fetch_service_by_id_and_user(service1.id, sample_user.id).name == 'service 1'
|
||||
assert not dao_fetch_service_by_id_and_user(service2.id, sample_user.id)
|
||||
with pytest.raises(NoResultFound) as e:
|
||||
dao_fetch_service_by_id_and_user(service2.id, sample_user.id)
|
||||
assert 'No row was found for one()' in str(e)
|
||||
|
||||
@@ -233,8 +233,7 @@ def test_update_invited_user_for_wrong_service_returns_404(notify_api, sample_in
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert response.status_code == 404
|
||||
json_response = json.loads(response.get_data(as_text=True))['message']
|
||||
assert json_response == 'Invited user not found for service id: {} and invited user id: {}'\
|
||||
.format(bad_service_id, sample_invited_user.id)
|
||||
assert json_response == 'No result found'
|
||||
|
||||
|
||||
def test_update_invited_user_for_invalid_data_returns_400(notify_api, sample_invited_user):
|
||||
|
||||
@@ -166,8 +166,7 @@ def test_get_service_by_id_should_404_if_no_service_for_user(notify_api, sample_
|
||||
assert resp.status_code == 404
|
||||
json_resp = json.loads(resp.get_data(as_text=True))
|
||||
assert json_resp['result'] == 'error'
|
||||
assert json_resp['message'] == \
|
||||
'Service not found for service id: {0} and for user id: {1}'.format(service_id, sample_user.id)
|
||||
assert json_resp['message'] == 'No result found'
|
||||
|
||||
|
||||
def test_create_service(notify_api, sample_user):
|
||||
@@ -257,9 +256,9 @@ def test_should_not_create_service_with_missing_if_user_id_is_not_in_database(no
|
||||
data=json.dumps(data),
|
||||
headers=headers)
|
||||
json_resp = json.loads(resp.get_data(as_text=True))
|
||||
assert resp.status_code == 400
|
||||
assert resp.status_code == 404
|
||||
assert json_resp['result'] == 'error'
|
||||
assert 'not found' in json_resp['message']['user_id']
|
||||
assert 'No result found' == json_resp['message']
|
||||
|
||||
|
||||
def test_should_not_create_service_if_missing_data(notify_api, sample_user):
|
||||
|
||||
Reference in New Issue
Block a user