mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 10:21:14 -05:00
Service and User API added, working with tests. Still need to polish the edges and add more tests.
This commit is contained in:
@@ -1,20 +1,27 @@
|
||||
import json
|
||||
from app.models import Service
|
||||
from flask import url_for
|
||||
|
||||
|
||||
def test_get_service_list(notify_api, notify_db, notify_db_session, sample_service):
|
||||
"""
|
||||
Tests GET endpoint '/' to retrieve entire service list.
|
||||
"""
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
response = client.get(url_for('service.get_service'))
|
||||
assert response.status_code == 200
|
||||
json_resp = json.loads(response.get_data(as_text=True))
|
||||
# TODO assert correct json returned
|
||||
assert len(json_resp['data']) == 1
|
||||
assert len(json_resp) == 1
|
||||
assert json_resp['data'][0]['name'] == sample_service.name
|
||||
assert json_resp['data'][0]['id'] == sample_service.id
|
||||
|
||||
|
||||
def test_get_service(notify_api, notify_db, notify_db_session, sample_service):
|
||||
"""
|
||||
Tests GET endpoint '/<service_id>' to retrieve a single service.
|
||||
"""
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
resp = client.get(url_for('service.get_service',
|
||||
@@ -25,8 +32,29 @@ def test_get_service(notify_api, notify_db, notify_db_session, sample_service):
|
||||
assert json_resp['data']['id'] == sample_service.id
|
||||
|
||||
|
||||
def test_post_service(notify_api, notify_db, notify_db_session, sample_service):
|
||||
pass
|
||||
def test_post_service(notify_api, notify_db, notify_db_session, sample_user):
|
||||
"""
|
||||
Tests POST endpoint '/' to create a service.
|
||||
"""
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
assert Service.query.count() == 0
|
||||
data = {
|
||||
'name': 'created service',
|
||||
'users': [sample_user.id],
|
||||
'limit': 1000,
|
||||
'restricted': False,
|
||||
'active': False}
|
||||
headers = [('Content-Type', 'application/json')]
|
||||
resp = client.post(
|
||||
url_for('service.create_service'),
|
||||
data=json.dumps(data),
|
||||
headers=headers)
|
||||
assert resp.status_code == 201
|
||||
service = Service.query.first()
|
||||
json_resp = json.loads(resp.get_data(as_text=True))
|
||||
assert json_resp['data']['name'] == service.name
|
||||
assert json_resp['data']['limit'] == service.limit
|
||||
|
||||
|
||||
def test_put_service(notify_api, notify_db, notify_db_session, sample_service):
|
||||
|
||||
Reference in New Issue
Block a user