mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
All four http methods working now for user and service restful apis.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from app.models import (User, Service)
|
||||
from app.dao.users_dao import (create_model_user, get_model_users)
|
||||
from app.dao.services_dao import create_model_service
|
||||
from app.dao.users_dao import (save_model_user, get_model_users)
|
||||
from app.dao.services_dao import save_model_service
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@@ -9,7 +9,7 @@ def sample_user(notify_db,
|
||||
notify_db_session,
|
||||
email="notify@digital.cabinet-office.gov.uk"):
|
||||
user = User(**{'email_address': email})
|
||||
create_model_user(user)
|
||||
save_model_user(user)
|
||||
return user
|
||||
|
||||
|
||||
@@ -27,5 +27,5 @@ def sample_service(notify_db,
|
||||
'active': False,
|
||||
'restricted': False}
|
||||
service = Service(**data)
|
||||
create_model_service(service)
|
||||
save_model_service(service)
|
||||
return service
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
from app.dao.services_dao import (
|
||||
create_model_service, get_model_services, DAOException)
|
||||
save_model_service, get_model_services, DAOException)
|
||||
from tests.app.conftest import sample_service as create_sample_service
|
||||
from app.models import Service
|
||||
|
||||
@@ -15,7 +15,7 @@ def test_create_service(notify_api, notify_db, notify_db_session, sample_user):
|
||||
'active': False,
|
||||
'restricted': False}
|
||||
service = Service(**data)
|
||||
create_model_service(service)
|
||||
save_model_service(service)
|
||||
assert Service.query.count() == 1
|
||||
assert Service.query.first().name == service_name
|
||||
assert Service.query.first().id == service.id
|
||||
@@ -58,7 +58,7 @@ def test_missing_user_attribute(notify_api, notify_db, notify_db_session):
|
||||
'restricted': False}
|
||||
|
||||
service = Service(**data)
|
||||
create_model_service(service)
|
||||
save_model_service(service)
|
||||
pytest.fail("DAOException not thrown")
|
||||
except DAOException as e:
|
||||
assert "Missing data for required attribute" in str(e)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from sqlalchemy.exc import DataError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from app.dao.users_dao import (create_model_user, get_model_users)
|
||||
from app.dao.users_dao import (save_model_user, get_model_users)
|
||||
from tests.app.conftest import sample_user as create_sample_user
|
||||
from app.models import User
|
||||
|
||||
@@ -8,7 +8,7 @@ from app.models import User
|
||||
def test_create_user(notify_api, notify_db, notify_db_session):
|
||||
email = 'notify@digital.cabinet-office.gov.uk'
|
||||
user = User(**{'email_address': email})
|
||||
create_model_user(user)
|
||||
save_model_user(user)
|
||||
assert User.query.count() == 1
|
||||
assert User.query.first().email_address == email
|
||||
assert User.query.first().id == user.id
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import json
|
||||
from app.models import Service
|
||||
from app.models import (Service, User)
|
||||
from flask import url_for
|
||||
|
||||
|
||||
@@ -58,4 +58,30 @@ def test_post_service(notify_api, notify_db, notify_db_session, sample_user):
|
||||
|
||||
|
||||
def test_put_service(notify_api, notify_db, notify_db_session, sample_service):
|
||||
pass
|
||||
"""
|
||||
Tests Put endpoint '/<service_id' to edit a service.
|
||||
"""
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
assert Service.query.count() == 1
|
||||
sample_user = User.query.first()
|
||||
old_service = Service.query.first()
|
||||
new_name = 'updated service'
|
||||
data = {
|
||||
'name': new_name,
|
||||
'users': [sample_user.id],
|
||||
'limit': 1000,
|
||||
'restricted': False,
|
||||
'active': False}
|
||||
headers = [('Content-Type', 'application/json')]
|
||||
resp = client.put(
|
||||
url_for('service.update_service', service_id=old_service.id),
|
||||
data=json.dumps(data),
|
||||
headers=headers)
|
||||
assert Service.query.count() == 1
|
||||
assert resp.status_code == 200
|
||||
updated_service = Service.query.first()
|
||||
json_resp = json.loads(resp.get_data(as_text=True))
|
||||
assert json_resp['data']['name'] == updated_service.name
|
||||
assert json_resp['data']['limit'] == updated_service.limit
|
||||
assert updated_service.name == new_name
|
||||
|
||||
@@ -54,4 +54,20 @@ def test_post_user(notify_api, notify_db, notify_db_session):
|
||||
|
||||
|
||||
def test_put_user(notify_api, notify_db, notify_db_session, sample_user):
|
||||
pass
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
assert User.query.count() == 1
|
||||
new_email = 'new@digital.cabinet-office.gov.uk'
|
||||
data = {
|
||||
'email_address': new_email}
|
||||
headers = [('Content-Type', 'application/json')]
|
||||
resp = client.put(
|
||||
url_for('user.update_user', user_id=sample_user.id),
|
||||
data=json.dumps(data),
|
||||
headers=headers)
|
||||
assert resp.status_code == 200
|
||||
assert User.query.count() == 1
|
||||
user = User.query.first()
|
||||
json_resp = json.loads(resp.get_data(as_text=True))
|
||||
assert json_resp['data']['email_address'] == new_email
|
||||
assert json_resp['data']['id'] == user.id
|
||||
|
||||
Reference in New Issue
Block a user