mirror of
https://github.com/GSA/notifications-api.git
synced 2026-04-18 16:19:36 -04:00
Change Organisation DAO update method
- Changed the organisation DAO update method to only make 1 query - Updated the update rest endpoint to not return an organisation when the update is successful
This commit is contained in:
@@ -19,7 +19,7 @@ def dao_create_organisation(organisation):
|
||||
|
||||
|
||||
@transactional
|
||||
def dao_update_organisation(organisation, **kwargs):
|
||||
for key, value in kwargs.items():
|
||||
setattr(organisation, key, value)
|
||||
db.session.add(organisation)
|
||||
def dao_update_organisation(organisation_id, **kwargs):
|
||||
return Organisation.query.filter_by(id=organisation_id).update(
|
||||
kwargs
|
||||
)
|
||||
|
||||
@@ -6,7 +6,7 @@ from app.dao.organisation_dao import (
|
||||
dao_get_organisation_by_id,
|
||||
dao_update_organisation,
|
||||
)
|
||||
from app.errors import register_errors
|
||||
from app.errors import register_errors, InvalidRequest
|
||||
from app.models import Organisation
|
||||
from app.organisation.organisation_schema import (
|
||||
post_create_organisation_schema,
|
||||
@@ -48,10 +48,10 @@ def create_organisation():
|
||||
@organisation_blueprint.route('/<uuid:organisation_id>', methods=['POST'])
|
||||
def update_organisation(organisation_id):
|
||||
data = request.get_json()
|
||||
|
||||
validate(data, post_update_organisation_schema)
|
||||
result = dao_update_organisation(organisation_id, **data)
|
||||
|
||||
fetched_organisation = dao_get_organisation_by_id(organisation_id)
|
||||
dao_update_organisation(fetched_organisation, **data)
|
||||
|
||||
return jsonify(fetched_organisation.serialize()), 200
|
||||
if result:
|
||||
return '', 204
|
||||
else:
|
||||
raise InvalidRequest("Organisation not found", 404)
|
||||
|
||||
@@ -45,7 +45,7 @@ def test_update_organisation(notify_db, notify_db_session):
|
||||
assert len(organisation) == 1
|
||||
assert organisation[0].name != updated_name
|
||||
|
||||
dao_update_organisation(organisation[0], name=updated_name)
|
||||
dao_update_organisation(organisation[0].id, **{'name': updated_name})
|
||||
|
||||
organisation = Organisation.query.all()
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ def test_post_update_organisation_updates_fields(admin_request, notify_db_sessio
|
||||
'organisation.update_organisation',
|
||||
_data=data,
|
||||
organisation_id=org.id,
|
||||
_expected_status=200
|
||||
_expected_status=204
|
||||
)
|
||||
|
||||
organisation = Organisation.query.all()
|
||||
@@ -88,3 +88,18 @@ def test_post_update_organisation_updates_fields(admin_request, notify_db_sessio
|
||||
assert organisation[0].id == org.id
|
||||
assert organisation[0].name == data['name']
|
||||
assert organisation[0].active == data['active']
|
||||
|
||||
|
||||
def test_post_update_organisation_gives_404_status_if_org_does_not_exist(admin_request, notify_db_session):
|
||||
data = {'name': 'new organisation name'}
|
||||
|
||||
admin_request.post(
|
||||
'organisation.update_organisation',
|
||||
_data=data,
|
||||
organisation_id='31d42ce6-3dac-45a7-95cb-94423d5ca03c',
|
||||
_expected_status=404
|
||||
)
|
||||
|
||||
organisation = Organisation.query.all()
|
||||
|
||||
assert not organisation
|
||||
|
||||
Reference in New Issue
Block a user