mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
add GET /organisation and GET /organisation/id endpoints
This commit is contained in:
@@ -71,6 +71,7 @@ def create_app(app_name=None):
|
|||||||
from app.events.rest import events as events_blueprint
|
from app.events.rest import events as events_blueprint
|
||||||
from app.provider_details.rest import provider_details as provider_details_blueprint
|
from app.provider_details.rest import provider_details as provider_details_blueprint
|
||||||
from app.spec.rest import spec as spec_blueprint
|
from app.spec.rest import spec as spec_blueprint
|
||||||
|
from app.organisation.rest import organisation_blueprint
|
||||||
|
|
||||||
application.register_blueprint(service_blueprint, url_prefix='/service')
|
application.register_blueprint(service_blueprint, url_prefix='/service')
|
||||||
application.register_blueprint(user_blueprint, url_prefix='/user')
|
application.register_blueprint(user_blueprint, url_prefix='/user')
|
||||||
@@ -85,6 +86,7 @@ def create_app(app_name=None):
|
|||||||
application.register_blueprint(events_blueprint)
|
application.register_blueprint(events_blueprint)
|
||||||
application.register_blueprint(provider_details_blueprint, url_prefix='/provider-details')
|
application.register_blueprint(provider_details_blueprint, url_prefix='/provider-details')
|
||||||
application.register_blueprint(spec_blueprint, url_prefix='/spec')
|
application.register_blueprint(spec_blueprint, url_prefix='/spec')
|
||||||
|
application.register_blueprint(organisation_blueprint, url_prefix='/organisation')
|
||||||
|
|
||||||
return application
|
return application
|
||||||
|
|
||||||
|
|||||||
9
app/dao/organisation_dao.py
Normal file
9
app/dao/organisation_dao.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
from app.models import Organisation
|
||||||
|
|
||||||
|
|
||||||
|
def dao_get_organisations():
|
||||||
|
return Organisation.query.all()
|
||||||
|
|
||||||
|
|
||||||
|
def dao_get_organisation_by_id(org_id):
|
||||||
|
return Organisation.query.filter_by(id=org_id).one()
|
||||||
0
app/organisation/__init__.py
Normal file
0
app/organisation/__init__.py
Normal file
20
app/organisation/rest.py
Normal file
20
app/organisation/rest.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
from flask import Blueprint, jsonify
|
||||||
|
|
||||||
|
from app.dao.organisation_dao import dao_get_organisations, dao_get_organisation_by_id
|
||||||
|
from app.schemas import organisation_schema
|
||||||
|
from app.errors import register_errors
|
||||||
|
|
||||||
|
organisation_blueprint = Blueprint('organisation', __name__)
|
||||||
|
register_errors(organisation_blueprint)
|
||||||
|
|
||||||
|
|
||||||
|
@organisation_blueprint.route('', methods=['GET'])
|
||||||
|
def get_organisations():
|
||||||
|
data = organisation_schema.dump(dao_get_organisations(), many=True).data
|
||||||
|
return jsonify(organisations=data)
|
||||||
|
|
||||||
|
|
||||||
|
@organisation_blueprint.route('/<uuid:org_id>', methods=['GET'])
|
||||||
|
def get_organisation_by_id(org_id):
|
||||||
|
data = organisation_schema.dump(dao_get_organisation_by_id(org_id)).data
|
||||||
|
return jsonify(organisation=data)
|
||||||
@@ -440,6 +440,12 @@ class EventSchema(BaseSchema):
|
|||||||
strict = True
|
strict = True
|
||||||
|
|
||||||
|
|
||||||
|
class OrganisationSchema(BaseSchema):
|
||||||
|
class Meta:
|
||||||
|
model = models.Organisation
|
||||||
|
strict = True
|
||||||
|
|
||||||
|
|
||||||
class FromToDateSchema(ma.Schema):
|
class FromToDateSchema(ma.Schema):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@@ -533,6 +539,7 @@ service_history_schema = ServiceHistorySchema()
|
|||||||
api_key_history_schema = ApiKeyHistorySchema()
|
api_key_history_schema = ApiKeyHistorySchema()
|
||||||
template_history_schema = TemplateHistorySchema()
|
template_history_schema = TemplateHistorySchema()
|
||||||
event_schema = EventSchema()
|
event_schema = EventSchema()
|
||||||
|
organisation_schema = OrganisationSchema()
|
||||||
from_to_date_schema = FromToDateSchema()
|
from_to_date_schema = FromToDateSchema()
|
||||||
provider_details_schema = ProviderDetailsSchema()
|
provider_details_schema = ProviderDetailsSchema()
|
||||||
week_aggregate_notification_statistics_schema = WeekAggregateNotificationStatisticsSchema()
|
week_aggregate_notification_statistics_schema = WeekAggregateNotificationStatisticsSchema()
|
||||||
|
|||||||
0
tests/app/organisation/__init__.py
Normal file
0
tests/app/organisation/__init__.py
Normal file
39
tests/app/organisation/test_rest.py
Normal file
39
tests/app/organisation/test_rest.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
from flask import json
|
||||||
|
|
||||||
|
from app.models import Organisation
|
||||||
|
|
||||||
|
from tests import create_authorization_header
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_organisations(notify_api, notify_db, notify_db_session):
|
||||||
|
org1 = Organisation(colour='#FFFFFF', logo='/path/image.png', name='Org1')
|
||||||
|
org2 = Organisation(colour='#000000', logo='/path/other.png', name='Org2')
|
||||||
|
notify_db.session.add_all([org1, org2])
|
||||||
|
notify_db.session.commit()
|
||||||
|
|
||||||
|
with notify_api.test_request_context(), notify_api.test_client() as client:
|
||||||
|
auth_header = create_authorization_header()
|
||||||
|
response = client.get('/organisation', headers=[auth_header])
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
organisations = json.loads(response.get_data(as_text=True))['organisations']
|
||||||
|
assert len(organisations) == 2
|
||||||
|
assert {org['id'] for org in organisations} == {str(org1.id), str(org2.id)}
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_organisation_by_id(notify_api, notify_db, notify_db_session):
|
||||||
|
org = Organisation(colour='#FFFFFF', logo='/path/image.png', name='My Org')
|
||||||
|
notify_db.session.add(org)
|
||||||
|
notify_db.session.commit()
|
||||||
|
|
||||||
|
with notify_api.test_request_context(), notify_api.test_client() as client:
|
||||||
|
auth_header = create_authorization_header()
|
||||||
|
response = client.get('/organisation/{}'.format(org.id), headers=[auth_header])
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
organisation = json.loads(response.get_data(as_text=True))['organisation']
|
||||||
|
assert set(organisation.keys()) == {'colour', 'logo', 'name', 'id'}
|
||||||
|
assert organisation['colour'] == '#FFFFFF'
|
||||||
|
assert organisation['logo'] == '/path/image.png'
|
||||||
|
assert organisation['name'] == 'My Org'
|
||||||
|
assert organisation['id'] == str(org.id)
|
||||||
Reference in New Issue
Block a user