mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-11 18:38:14 -04:00
Remove endpoints for checking name uniqueness
The code which called these endpoints was removed: - for services in https://github.com/alphagov/notifications-admin/pull/4084/files - for organisations in https://github.com/alphagov/notifications-admin/pull/4128/files Therefore these endpoints are no longer needed.
This commit is contained in:
@@ -174,16 +174,6 @@ def get_organisation_users(organisation_id):
|
||||
return jsonify(data=[x.serialize() for x in org_users])
|
||||
|
||||
|
||||
@organisation_blueprint.route('/unique', methods=["GET"])
|
||||
def is_organisation_name_unique():
|
||||
organisation_id, name = check_request_args(request)
|
||||
|
||||
name_exists = Organisation.query.filter(Organisation.name.ilike(name)).first()
|
||||
|
||||
result = (not name_exists) or str(name_exists.id) == organisation_id
|
||||
return jsonify(result=result), 200
|
||||
|
||||
|
||||
def check_request_args(request):
|
||||
org_id = request.args.get('org_id')
|
||||
name = request.args.get('name', None)
|
||||
|
||||
@@ -940,21 +940,6 @@ def get_organisation_for_service(service_id):
|
||||
return jsonify(organisation.serialize() if organisation else {}), 200
|
||||
|
||||
|
||||
@service_blueprint.route('/unique', methods=["GET"])
|
||||
def is_service_name_unique():
|
||||
service_id, name, email_from = check_request_args(request)
|
||||
|
||||
name_exists = Service.query.filter_by(name=name).first()
|
||||
|
||||
email_from_exists = Service.query.filter(
|
||||
Service.email_from == email_from,
|
||||
Service.id != service_id
|
||||
).first()
|
||||
|
||||
result = not (name_exists or email_from_exists)
|
||||
return jsonify(result=result), 200
|
||||
|
||||
|
||||
@service_blueprint.route('/<uuid:service_id>/data-retention', methods=['GET'])
|
||||
def get_data_retention_for_service(service_id):
|
||||
data_retention_list = fetch_service_data_retention(service_id)
|
||||
|
||||
@@ -736,103 +736,6 @@ def test_get_organisation_users_returns_users_for_organisation(admin_request, sa
|
||||
assert response['data'][0]['id'] == str(first.id)
|
||||
|
||||
|
||||
def test_is_organisation_name_unique_returns_200_if_unique(admin_request, notify_db, notify_db_session):
|
||||
organisation = create_organisation(name='unique')
|
||||
|
||||
response = admin_request.get(
|
||||
'organisation.is_organisation_name_unique',
|
||||
_expected_status=200,
|
||||
org_id=organisation.id,
|
||||
name='something'
|
||||
)
|
||||
|
||||
assert response == {"result": True}
|
||||
|
||||
|
||||
@pytest.mark.parametrize('name', ["UNIQUE", "Unique.", "**uniQUE**"])
|
||||
def test_is_organisation_name_unique_returns_200_and_name_capitalized_or_punctuation_added(
|
||||
admin_request,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
name
|
||||
):
|
||||
organisation = create_organisation(name='unique')
|
||||
|
||||
response = admin_request.get(
|
||||
'organisation.is_organisation_name_unique',
|
||||
_expected_status=200,
|
||||
org_id=organisation.id,
|
||||
name=name
|
||||
)
|
||||
|
||||
assert response == {"result": True}
|
||||
|
||||
|
||||
@pytest.mark.parametrize('name', ["UNIQUE", "Unique"])
|
||||
def test_is_organisation_name_unique_returns_200_and_false_with_same_name_and_different_case_of_other_organisation(
|
||||
admin_request,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
name
|
||||
):
|
||||
create_organisation(name='unique')
|
||||
different_organisation_id = '111aa111-2222-bbbb-aaaa-111111111111'
|
||||
|
||||
response = admin_request.get(
|
||||
'organisation.is_organisation_name_unique',
|
||||
_expected_status=200,
|
||||
org_id=different_organisation_id,
|
||||
name=name
|
||||
)
|
||||
|
||||
assert response == {"result": False}
|
||||
|
||||
|
||||
def test_is_organisation_name_unique_returns_200_and_false_if_name_exists_for_a_different_organisation(
|
||||
admin_request,
|
||||
notify_db,
|
||||
notify_db_session
|
||||
):
|
||||
create_organisation(name='existing name')
|
||||
different_organisation_id = '111aa111-2222-bbbb-aaaa-111111111111'
|
||||
|
||||
response = admin_request.get(
|
||||
'organisation.is_organisation_name_unique',
|
||||
_expected_status=200,
|
||||
org_id=different_organisation_id,
|
||||
name='existing name'
|
||||
)
|
||||
|
||||
assert response == {"result": False}
|
||||
|
||||
|
||||
def test_is_organisation_name_unique_returns_200_and_true_if_name_exists_for_the_same_organisation(
|
||||
admin_request,
|
||||
notify_db,
|
||||
notify_db_session
|
||||
):
|
||||
organisation = create_organisation(name='unique')
|
||||
|
||||
response = admin_request.get(
|
||||
'organisation.is_organisation_name_unique',
|
||||
_expected_status=200,
|
||||
org_id=organisation.id,
|
||||
name='unique'
|
||||
)
|
||||
|
||||
assert response == {"result": True}
|
||||
|
||||
|
||||
def test_is_organisation_name_unique_returns_400_when_name_does_not_exist(admin_request):
|
||||
response = admin_request.get(
|
||||
'organisation.is_organisation_name_unique',
|
||||
_expected_status=400
|
||||
)
|
||||
|
||||
assert response["message"][0]["org_id"] == ["Can't be empty"]
|
||||
assert response["message"][1]["name"] == ["Can't be empty"]
|
||||
|
||||
|
||||
@freeze_time('2020-02-24 13:30')
|
||||
def test_get_organisation_services_usage(admin_request, notify_db_session):
|
||||
org = create_organisation(name='Organisation without live services')
|
||||
|
||||
@@ -2700,99 +2700,6 @@ def test_search_for_notification_by_to_field_returns_notifications_by_type(
|
||||
assert notifications[0]['id'] == str(sms_notification.id)
|
||||
|
||||
|
||||
def test_is_service_name_unique_returns_200_if_unique(admin_request, notify_db, notify_db_session):
|
||||
service = create_service(service_name='unique', email_from='unique')
|
||||
|
||||
response = admin_request.get(
|
||||
'service.is_service_name_unique',
|
||||
_expected_status=200,
|
||||
service_id=service.id,
|
||||
name='something',
|
||||
email_from='something'
|
||||
)
|
||||
|
||||
assert response == {"result": True}
|
||||
|
||||
|
||||
@pytest.mark.parametrize('name, email_from',
|
||||
[("UNIQUE", "unique"),
|
||||
("Unique.", "unique"),
|
||||
("**uniQUE**", "unique")
|
||||
])
|
||||
def test_is_service_name_unique_returns_200_with_name_capitalized_or_punctuation_added(
|
||||
admin_request,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
name,
|
||||
email_from
|
||||
):
|
||||
service = create_service(service_name='unique', email_from='unique')
|
||||
|
||||
response = admin_request.get(
|
||||
'service.is_service_name_unique',
|
||||
_expected_status=200,
|
||||
service_id=service.id,
|
||||
name=name,
|
||||
email_from=email_from
|
||||
)
|
||||
|
||||
assert response == {"result": True}
|
||||
|
||||
|
||||
@pytest.mark.parametrize('name, email_from', [
|
||||
("existing name", "email.from"),
|
||||
("name", "existing.name")
|
||||
])
|
||||
def test_is_service_name_unique_returns_200_and_false_if_name_or_email_from_exist_for_a_different_service(
|
||||
admin_request,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
name,
|
||||
email_from
|
||||
):
|
||||
create_service(service_name='existing name', email_from='existing.name')
|
||||
different_service_id = '111aa111-2222-bbbb-aaaa-111111111111'
|
||||
|
||||
response = admin_request.get(
|
||||
'service.is_service_name_unique',
|
||||
_expected_status=200,
|
||||
service_id=different_service_id,
|
||||
name=name,
|
||||
email_from=email_from
|
||||
)
|
||||
|
||||
assert response == {"result": False}
|
||||
|
||||
|
||||
def test_is_service_name_unique_returns_200_and_false_if_name_exists_for_the_same_service(
|
||||
admin_request,
|
||||
notify_db,
|
||||
notify_db_session
|
||||
):
|
||||
service = create_service(service_name='unique', email_from='unique')
|
||||
|
||||
response = admin_request.get(
|
||||
'service.is_service_name_unique',
|
||||
_expected_status=200,
|
||||
service_id=service.id,
|
||||
name='unique',
|
||||
email_from='unique2'
|
||||
)
|
||||
|
||||
assert response == {"result": False}
|
||||
|
||||
|
||||
def test_is_service_name_unique_returns_400_when_name_does_not_exist(admin_request):
|
||||
response = admin_request.get(
|
||||
'service.is_service_name_unique',
|
||||
_expected_status=400
|
||||
)
|
||||
|
||||
assert response["message"][0]["service_id"] == ["Can't be empty"]
|
||||
assert response["message"][1]["name"] == ["Can't be empty"]
|
||||
assert response["message"][2]["email_from"] == ["Can't be empty"]
|
||||
|
||||
|
||||
def test_get_email_reply_to_addresses_when_there_are_no_reply_to_email_addresses(client, sample_service):
|
||||
response = client.get('/service/{}/email-reply-to'.format(sample_service.id),
|
||||
headers=[create_admin_authorization_header()])
|
||||
|
||||
Reference in New Issue
Block a user