mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Updated service DAO and API end points
This commit is contained in:
@@ -11,6 +11,7 @@ from app.dao.services_dao import (
|
||||
dao_create_service,
|
||||
dao_add_user_to_service,
|
||||
dao_remove_user_from_service,
|
||||
dao_remove_service_permission as dao_services_remove_service_permission,
|
||||
dao_fetch_all_services,
|
||||
dao_fetch_service_by_id,
|
||||
dao_fetch_all_services_by_user,
|
||||
@@ -45,7 +46,10 @@ from app.models import (
|
||||
InvitedUser,
|
||||
Service,
|
||||
ServicePermission,
|
||||
<<<<<<< HEAD
|
||||
ServicePermissionTypes,
|
||||
=======
|
||||
>>>>>>> Updated service DAO and API end points
|
||||
BRANDING_GOVUK,
|
||||
DVLA_ORG_HM_GOVERNMENT,
|
||||
KEY_TYPE_NORMAL,
|
||||
@@ -372,6 +376,40 @@ def test_update_service_creates_a_history_record_with_current_data(sample_user):
|
||||
assert Service.get_history_model().query.filter_by(name='updated_service_name').one().version == 2
|
||||
|
||||
|
||||
def test_update_service_permission_creates_a_history_record_with_current_data(sample_user):
|
||||
assert Service.query.count() == 0
|
||||
assert Service.get_history_model().query.count() == 0
|
||||
service = Service(name="service_name",
|
||||
email_from="email_from",
|
||||
message_limit=1000,
|
||||
restricted=False,
|
||||
created_by=sample_user)
|
||||
dao_create_service(service, sample_user)
|
||||
|
||||
service.permissions.append(ServicePermission(service_id=service.id, permission='letter'))
|
||||
dao_update_service(service)
|
||||
|
||||
assert Service.query.count() == 1
|
||||
assert Service.get_history_model().query.count() == 2
|
||||
|
||||
service_from_db = Service.query.first()
|
||||
|
||||
assert service_from_db.version == 2
|
||||
assert LETTER_TYPE in [p.permission for p in service_from_db.permissions]
|
||||
|
||||
dao_services_remove_service_permission(service, permission='sms')
|
||||
|
||||
assert Service.query.count() == 1
|
||||
assert Service.get_history_model().query.count() == 3
|
||||
|
||||
service_from_db = Service.query.first()
|
||||
assert service_from_db.version == 3
|
||||
assert SMS_TYPE not in [p.permission for p in service_from_db.permissions]
|
||||
|
||||
assert len(Service.get_history_model().query.filter_by(name='service_name').all()) == 3
|
||||
assert Service.get_history_model().query.filter_by(name='service_name').all()[2].version == 3
|
||||
|
||||
|
||||
def test_create_service_and_history_is_transactional(sample_user):
|
||||
assert Service.query.count() == 0
|
||||
assert Service.get_history_model().query.count() == 0
|
||||
|
||||
Reference in New Issue
Block a user