mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 10:21:14 -05:00
Changed db queries to use one, which throws NoResultFound exception, this exception is dealt with in our error handlers.
Now a lot of the if none checks can be removed.
This commit is contained in:
@@ -11,7 +11,7 @@ from app.dao.services_dao import (
|
||||
)
|
||||
from app.dao.users_dao import save_model_user
|
||||
from app.models import Service, User
|
||||
from sqlalchemy.orm.exc import FlushError
|
||||
from sqlalchemy.orm.exc import FlushError, NoResultFound
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
|
||||
@@ -145,7 +145,9 @@ def test_get_all_user_services_should_return_empty_list_if_no_services_for_user(
|
||||
|
||||
|
||||
def test_get_service_by_id_returns_none_if_no_service(notify_db):
|
||||
assert not dao_fetch_service_by_id(str(uuid.uuid4()))
|
||||
with pytest.raises(NoResultFound) as e:
|
||||
dao_fetch_service_by_id(str(uuid.uuid4()))
|
||||
assert 'No row was found for one()' in str(e)
|
||||
|
||||
|
||||
def test_get_service_by_id_returns_service(service_factory):
|
||||
|
||||
@@ -155,4 +155,6 @@ def test_get_template_by_id_and_service(notify_db, notify_db_session, sample_ser
|
||||
|
||||
|
||||
def test_get_template_by_id_and_service_returns_none_if_no_template(sample_service):
|
||||
assert not dao_get_template_by_id_and_service_id(template_id=999, service_id=sample_service.id)
|
||||
with pytest.raises(NoResultFound) as e:
|
||||
dao_get_template_by_id_and_service_id(template_id=999, service_id=sample_service.id)
|
||||
assert 'No row was found for one' in str(e.value)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from datetime import datetime, timedelta
|
||||
from sqlalchemy.exc import DataError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
from app import db
|
||||
import pytest
|
||||
|
||||
@@ -55,7 +57,7 @@ def test_get_user_not_exists(notify_api, notify_db, notify_db_session):
|
||||
try:
|
||||
get_model_users(user_id="12345")
|
||||
pytest.fail("NoResultFound exception not thrown.")
|
||||
except:
|
||||
except NoResultFound as e:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user