mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-23 09:29:43 -04:00
Organisation services API endpoints
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from app.models import Organisation
|
||||
from app.dao.organisation_dao import dao_add_service_to_organisation
|
||||
from tests.app.db import create_organisation
|
||||
|
||||
|
||||
@@ -103,3 +104,95 @@ def test_post_update_organisation_gives_404_status_if_org_does_not_exist(admin_r
|
||||
organisation = Organisation.query.all()
|
||||
|
||||
assert not organisation
|
||||
|
||||
|
||||
def test_post_link_service_to_organisation(admin_request, sample_service, sample_organisation):
|
||||
data = {
|
||||
'service_id': str(sample_service.id)
|
||||
}
|
||||
|
||||
admin_request.post(
|
||||
'organisation.link_service_to_organisation',
|
||||
_data=data,
|
||||
organisation_id=sample_organisation.id,
|
||||
_expected_status=204
|
||||
)
|
||||
|
||||
assert len(sample_organisation.services) == 1
|
||||
|
||||
|
||||
def test_post_link_service_to_another_org(
|
||||
admin_request, sample_service, sample_organisation):
|
||||
data = {
|
||||
'service_id': str(sample_service.id)
|
||||
}
|
||||
|
||||
admin_request.post(
|
||||
'organisation.link_service_to_organisation',
|
||||
_data=data,
|
||||
organisation_id=sample_organisation.id,
|
||||
_expected_status=204
|
||||
)
|
||||
|
||||
assert len(sample_organisation.services) == 1
|
||||
|
||||
new_org = create_organisation()
|
||||
admin_request.post(
|
||||
'organisation.link_service_to_organisation',
|
||||
_data=data,
|
||||
organisation_id=new_org.id,
|
||||
_expected_status=204
|
||||
)
|
||||
assert not sample_organisation.services
|
||||
assert len(new_org.services) == 1
|
||||
|
||||
|
||||
def test_post_link_service_to_organisation_nonexistent_organisation(
|
||||
admin_request, sample_service, fake_uuid):
|
||||
data = {
|
||||
'service_id': str(sample_service.id)
|
||||
}
|
||||
|
||||
admin_request.post(
|
||||
'organisation.link_service_to_organisation',
|
||||
_data=data,
|
||||
organisation_id=fake_uuid,
|
||||
_expected_status=404
|
||||
)
|
||||
|
||||
|
||||
def test_post_link_service_to_organisation_nonexistent_service(
|
||||
admin_request, sample_organisation, fake_uuid):
|
||||
data = {
|
||||
'service_id': fake_uuid
|
||||
}
|
||||
|
||||
admin_request.post(
|
||||
'organisation.link_service_to_organisation',
|
||||
_data=data,
|
||||
organisation_id=str(sample_organisation.id),
|
||||
_expected_status=404
|
||||
)
|
||||
|
||||
|
||||
def test_post_link_service_to_organisation_missing_payload(
|
||||
admin_request, sample_organisation, fake_uuid):
|
||||
admin_request.post(
|
||||
'organisation.link_service_to_organisation',
|
||||
organisation_id=str(sample_organisation.id),
|
||||
_expected_status=400
|
||||
)
|
||||
|
||||
|
||||
def test_rest_get_organisation_services(
|
||||
admin_request, sample_organisation, sample_service):
|
||||
dao_add_service_to_organisation(sample_service, sample_organisation.id)
|
||||
response = admin_request.get(
|
||||
'organisation.get_organisation_services',
|
||||
organisation_id=str(sample_organisation.id),
|
||||
_expected_status=200
|
||||
)
|
||||
|
||||
assert len(response) == 1
|
||||
assert response[0]['id'] == str(sample_service.id)
|
||||
assert response[0]['name'] == sample_service.name
|
||||
|
||||
@@ -9,6 +9,7 @@ from flask import url_for, current_app
|
||||
from freezegun import freeze_time
|
||||
|
||||
from app.celery.scheduled_tasks import daily_stats_template_usage_by_month
|
||||
from app.dao.organisation_dao import dao_add_service_to_organisation
|
||||
from app.dao.services_dao import dao_remove_user_from_service
|
||||
from app.dao.templates_dao import dao_redact_template
|
||||
from app.dao.users_dao import save_model_user
|
||||
@@ -2765,6 +2766,23 @@ def test_get_service_sms_senders_for_service_returns_empty_list_when_service_doe
|
||||
assert json.loads(response.get_data(as_text=True)) == []
|
||||
|
||||
|
||||
def test_get_organisation_for_service_id(admin_request, sample_service, sample_organisation):
|
||||
dao_add_service_to_organisation(sample_service, sample_organisation.id)
|
||||
response = admin_request.get(
|
||||
'service.get_organisation_for_service',
|
||||
service_id=sample_service.id
|
||||
)
|
||||
assert response == sample_organisation.serialize()
|
||||
|
||||
|
||||
def test_get_organisation_for_service_id_return_empty_dict_if_service_not_in_organisation(admin_request, fake_uuid):
|
||||
response = admin_request.get(
|
||||
'service.get_organisation_for_service',
|
||||
service_id=fake_uuid
|
||||
)
|
||||
assert response == {}
|
||||
|
||||
|
||||
def test_get_platform_stats(client, notify_db_session):
|
||||
service_1 = create_service(service_name='Service 1')
|
||||
service_2 = create_service(service_name='Service 2')
|
||||
|
||||
Reference in New Issue
Block a user