Return empty list when there are no users for the service.

Added a test for when there are no users for the service.
Added a test_url_for - do we want to add this test and use url_for in our tests?
Or explictly write the url in the test?
This commit is contained in:
Rebecca Law
2016-02-24 10:30:00 +00:00
parent 12a2d8db0a
commit f1fdfbb308
3 changed files with 64 additions and 2 deletions

View File

@@ -366,3 +366,25 @@ def test_get_users_by_service(notify_api, notify_db, notify_db_session, sample_u
assert result['data'][0]['name'] == sample_user.name
assert result['data'][0]['email_address'] == sample_user.email_address
assert result['data'][0]['mobile_number'] == sample_user.mobile_number
def test_get_users_for_service_returns_empty_list_if_no_users_associated_with_service(notify_api,
notify_db,
notify_db_session,
sample_service,
sample_user):
with notify_api.test_request_context():
with notify_api.test_client() as client:
sample_service.users.remove(sample_user)
auth_header = create_authorization_header(
path='/service/{}/users'.format(sample_service.id),
method='GET'
)
response = client.get(
'/service/{}/users'.format(sample_service.id),
headers=[('Content-Type', 'application/json'), auth_header]
)
assert response.status_code == 200
result = json.loads(response.get_data(as_text=True))
assert result['data'] == []

View File

@@ -0,0 +1,40 @@
import uuid
from flask import url_for
service_id = str(uuid.uuid4())
def test_url_for_get_services(notify_api):
with notify_api.test_request_context():
url = url_for('service.get_services')
assert str(url) == '/service'
url_with_user_id = url_for('service.get_services', user_id=1)
assert str(url_with_user_id) == '/service?user_id=1'
def test_url_for_get_service_by_id(notify_api):
with notify_api.test_request_context():
url = url_for('service.get_service_by_id', service_id=service_id)
assert str(url) == '/service/{}'.format(service_id)
url_with_user_id = url_for('service.get_service_by_id', service_id=service_id, user_id=1)
assert str(url_with_user_id) == '/service/{0}?user_id={1}'.format(service_id, 1)
def test_url_for_create_service(notify_api):
with notify_api.test_request_context():
url = url_for('service.create_service')
assert str(url) == '/service'.format(service_id)
def test_url_for_update_service(notify_api):
with notify_api.test_request_context():
url = url_for('service.update_service', service_id=service_id)
assert str(url) == '/service/{}'.format(service_id)
def test_url_for_renew_api_key(notify_api):
with notify_api.test_request_context():
url = url_for('service.renew_api_key', service_id=service_id)
assert str(url) == '/service/{}/api-key'.format(service_id)