mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Added delete endpoint and tests.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
from app.dao.services_dao import (
|
||||
save_model_service, get_model_services, DAOException)
|
||||
save_model_service, get_model_services, DAOException, delete_model_service)
|
||||
from tests.app.conftest import sample_service as create_sample_service
|
||||
from app.models import Service
|
||||
|
||||
@@ -62,3 +62,9 @@ def test_missing_user_attribute(notify_api, notify_db, notify_db_session):
|
||||
pytest.fail("DAOException not thrown")
|
||||
except DAOException as e:
|
||||
assert "Missing data for required attribute" in str(e)
|
||||
|
||||
|
||||
def test_delete_service(notify_api, notify_db, notify_db_session, sample_service):
|
||||
assert Service.query.count() == 1
|
||||
delete_model_service(sample_service)
|
||||
assert Service.query.count() == 0
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from sqlalchemy.exc import DataError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from app.dao.users_dao import (save_model_user, get_model_users)
|
||||
from app.dao.users_dao import (
|
||||
save_model_user, get_model_users, delete_model_user)
|
||||
from tests.app.conftest import sample_user as create_sample_user
|
||||
from app.models import User
|
||||
|
||||
@@ -47,3 +48,9 @@ def test_get_user_invalid_id(notify_api, notify_db, notify_db_session):
|
||||
pytest.fail("DataError exception not thrown.")
|
||||
except DataError:
|
||||
pass
|
||||
|
||||
|
||||
def test_delete_users(notify_api, notify_db, notify_db_session, sample_user):
|
||||
assert User.query.count() == 1
|
||||
delete_model_user(sample_user)
|
||||
assert User.query.count() == 0
|
||||
|
||||
@@ -209,3 +209,15 @@ def test_put_service_remove_user(notify_api, notify_db, notify_db_session, sampl
|
||||
assert len(json_resp['data']['users']) == 1
|
||||
assert sample_user.id not in json_resp['data']['users']
|
||||
assert another_user.id in json_resp['data']['users']
|
||||
|
||||
|
||||
def test_delete_user(notify_api, notify_db, notify_db_session, sample_service):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
service = Service.query.first()
|
||||
resp = client.delete(
|
||||
url_for('service.update_service', service_id=service.id),
|
||||
headers=[('Content-Type', 'application/json')])
|
||||
assert resp.status_code == 202
|
||||
json_resp = json.loads(resp.get_data(as_text=True))
|
||||
assert Service.query.count() == 0
|
||||
|
||||
@@ -195,3 +195,15 @@ def test_get_user_service_service_not_exists(notify_api, notify_db, notify_db_se
|
||||
assert resp.status_code == 404
|
||||
json_resp = json.loads(resp.get_data(as_text=True))
|
||||
assert "Service not found" in json_resp['message']
|
||||
|
||||
|
||||
def test_delete_user(notify_api, notify_db, notify_db_session, sample_user):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
user = User.query.first()
|
||||
resp = client.delete(
|
||||
url_for('user.update_user', user_id=user.id),
|
||||
headers=[('Content-Type', 'application/json')])
|
||||
assert resp.status_code == 202
|
||||
json_resp = json.loads(resp.get_data(as_text=True))
|
||||
assert User.query.count() == 0
|
||||
|
||||
Reference in New Issue
Block a user