mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-07 08:18:24 -04:00
Find services by name or partial name
This commit is contained in:
@@ -12,6 +12,7 @@ from app.main.views import ( # noqa isort:skip
|
|||||||
dashboard,
|
dashboard,
|
||||||
email_branding,
|
email_branding,
|
||||||
feedback,
|
feedback,
|
||||||
|
find_services,
|
||||||
find_users,
|
find_users,
|
||||||
forgot_password,
|
forgot_password,
|
||||||
inbound_number,
|
inbound_number,
|
||||||
|
|||||||
23
app/main/views/find_services.py
Normal file
23
app/main/views/find_services.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
from flask import render_template, request
|
||||||
|
|
||||||
|
from app import service_api_client
|
||||||
|
from app.main import main
|
||||||
|
from app.main.forms import SearchByNameForm
|
||||||
|
from app.utils import user_is_platform_admin
|
||||||
|
|
||||||
|
|
||||||
|
@main.route("/find-services-by-name", methods=['GET', 'POST'])
|
||||||
|
@user_is_platform_admin
|
||||||
|
def find_services_by_name():
|
||||||
|
form = SearchByNameForm()
|
||||||
|
services_found = None
|
||||||
|
status = 200
|
||||||
|
if form.validate_on_submit():
|
||||||
|
services_found = service_api_client.find_services_by_name(service_name=form.search.data)['data']
|
||||||
|
elif request.method == 'POST':
|
||||||
|
status = 400
|
||||||
|
return render_template(
|
||||||
|
'views/find-services/find-services-by-name.html',
|
||||||
|
form=form,
|
||||||
|
services_found=services_found
|
||||||
|
), status
|
||||||
@@ -23,7 +23,6 @@ from app.main.forms import (
|
|||||||
PDFUploadForm,
|
PDFUploadForm,
|
||||||
RequiredDateFilterForm,
|
RequiredDateFilterForm,
|
||||||
ReturnedLettersForm,
|
ReturnedLettersForm,
|
||||||
SearchByNameForm,
|
|
||||||
)
|
)
|
||||||
from app.statistics_utils import (
|
from app.statistics_utils import (
|
||||||
get_formatted_percentage,
|
get_formatted_percentage,
|
||||||
@@ -190,23 +189,6 @@ def platform_admin_services():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@main.route("/find-services-by-name", methods=['GET', 'POST'])
|
|
||||||
@user_is_platform_admin
|
|
||||||
def find_services_by_name():
|
|
||||||
form = SearchByNameForm()
|
|
||||||
services_found = None
|
|
||||||
status = 200
|
|
||||||
if form.validate_on_submit():
|
|
||||||
services_found = service_api_client.get_service({"name": form.search.data})['data']
|
|
||||||
elif request.method == 'POST':
|
|
||||||
status = 400
|
|
||||||
return render_template(
|
|
||||||
'views/find-services/find-services-by-name.html',
|
|
||||||
form=form,
|
|
||||||
services_found=services_found
|
|
||||||
), status
|
|
||||||
|
|
||||||
|
|
||||||
@main.route("/platform-admin/reports")
|
@main.route("/platform-admin/reports")
|
||||||
@user_is_platform_admin
|
@user_is_platform_admin
|
||||||
def platform_admin_reports():
|
def platform_admin_reports():
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ class HeaderNavigation(Navigation):
|
|||||||
'create_email_branding',
|
'create_email_branding',
|
||||||
'create_letter_branding',
|
'create_letter_branding',
|
||||||
'email_branding',
|
'email_branding',
|
||||||
|
'find_services_by_name',
|
||||||
'find_users_by_email',
|
'find_users_by_email',
|
||||||
'letter_branding',
|
'letter_branding',
|
||||||
'live_services',
|
'live_services',
|
||||||
@@ -483,6 +484,7 @@ class MainNavigation(Navigation):
|
|||||||
'features_letters',
|
'features_letters',
|
||||||
'features_sms',
|
'features_sms',
|
||||||
'feedback',
|
'feedback',
|
||||||
|
'find_services_by_name',
|
||||||
'find_users_by_email',
|
'find_users_by_email',
|
||||||
'forgot_password',
|
'forgot_password',
|
||||||
'get_example_csv',
|
'get_example_csv',
|
||||||
@@ -701,6 +703,7 @@ class CaseworkNavigation(Navigation):
|
|||||||
'features_letters',
|
'features_letters',
|
||||||
'features_sms',
|
'features_sms',
|
||||||
'feedback',
|
'feedback',
|
||||||
|
'find_services_by_name',
|
||||||
'find_users_by_email',
|
'find_users_by_email',
|
||||||
'forgot_password',
|
'forgot_password',
|
||||||
'get_example_csv',
|
'get_example_csv',
|
||||||
@@ -979,6 +982,7 @@ class OrgNavigation(Navigation):
|
|||||||
'features_letters',
|
'features_letters',
|
||||||
'features_sms',
|
'features_sms',
|
||||||
'feedback',
|
'feedback',
|
||||||
|
'find_services_by_name',
|
||||||
'find_users_by_email',
|
'find_users_by_email',
|
||||||
'forgot_password',
|
'forgot_password',
|
||||||
'get_example_csv',
|
'get_example_csv',
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ class ServiceAPIClient(NotifyAdminAPIClient):
|
|||||||
"""
|
"""
|
||||||
return self.get('/service', params=params_dict)
|
return self.get('/service', params=params_dict)
|
||||||
|
|
||||||
|
def find_services_by_name(self, service_name):
|
||||||
|
return self.get('/service/find-services-by-name', params={"service_name": service_name})
|
||||||
|
|
||||||
def get_live_services_data(self, params_dict=None):
|
def get_live_services_data(self, params_dict=None):
|
||||||
"""
|
"""
|
||||||
Retrieve a list of live services data with contact names and notification counts.
|
Retrieve a list of live services data with contact names and notification counts.
|
||||||
|
|||||||
51
app/templates/views/find-services/find-services-by-name.html
Normal file
51
app/templates/views/find-services/find-services-by-name.html
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
{% extends "views/platform-admin/_base_template.html" %}
|
||||||
|
{% from "components/page-footer.html" import page_footer %}
|
||||||
|
{% from "components/form.html" import form_wrapper %}
|
||||||
|
|
||||||
|
{% block per_page_title %}
|
||||||
|
Find services by name
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block platform_admin_content %}
|
||||||
|
|
||||||
|
<h1 class="heading-large">
|
||||||
|
Find services by name
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
|
||||||
|
{% call form_wrapper(
|
||||||
|
action=url_for('.find_services_by_name'),
|
||||||
|
class='grid-row'
|
||||||
|
) %}
|
||||||
|
<div class="column-three-quarters">
|
||||||
|
{{ textbox(
|
||||||
|
form.search,
|
||||||
|
width='1-1',
|
||||||
|
label='Find services by name, or by partial name'
|
||||||
|
) }}
|
||||||
|
</div>
|
||||||
|
<div class="column-one-quarter align-button-with-textbox">
|
||||||
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||||
|
<button type="submit" class="button">Search</button>
|
||||||
|
</div>
|
||||||
|
{% endcall %}
|
||||||
|
|
||||||
|
{% call form_wrapper(id='search-form' ) %}
|
||||||
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||||
|
{% endcall %}
|
||||||
|
|
||||||
|
{% if services_found %}
|
||||||
|
<nav class="browse-list">
|
||||||
|
<ul>
|
||||||
|
{% for service in services_found %}
|
||||||
|
<li class="browse-list-item">
|
||||||
|
<a href="{{url_for('.service_dashboard', service_id=service.id)}}" class="browse-list-link">{{ service.name }}</a>
|
||||||
|
</li>
|
||||||
|
<hr>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
{% elif services_found == [] %}
|
||||||
|
<p class="browse-list-hint">No services found.</p>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
('Email branding', url_for('main.email_branding')),
|
('Email branding', url_for('main.email_branding')),
|
||||||
('Letter branding', url_for('main.letter_branding')),
|
('Letter branding', url_for('main.letter_branding')),
|
||||||
('Inbound SMS numbers', url_for('main.inbound_sms_admin')),
|
('Inbound SMS numbers', url_for('main.inbound_sms_admin')),
|
||||||
|
('Find services by name', url_for('main.find_services_by_name')),
|
||||||
('Find users by email', url_for('main.find_users_by_email')),
|
('Find users by email', url_for('main.find_users_by_email')),
|
||||||
('Email Complaints', url_for('main.platform_admin_list_complaints')),
|
('Email Complaints', url_for('main.platform_admin_list_complaints')),
|
||||||
('Returned letters', url_for('main.platform_admin_returned_letters')),
|
('Returned letters', url_for('main.platform_admin_returned_letters')),
|
||||||
|
|||||||
73
tests/app/main/views/test_find_services.py
Normal file
73
tests/app/main/views/test_find_services.py
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
from tests import service_json
|
||||||
|
|
||||||
|
|
||||||
|
def test_find_services_by_name_page_loads_correctly(client_request, platform_admin_user):
|
||||||
|
client_request.login(platform_admin_user)
|
||||||
|
document = client_request.get('main.find_services_by_name')
|
||||||
|
|
||||||
|
assert document.h1.text.strip() == 'Find services by name'
|
||||||
|
assert len(document.find_all('input', {'type': 'search'})) > 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_find_services_by_name_displays_services_found(
|
||||||
|
client_request,
|
||||||
|
platform_admin_user,
|
||||||
|
mocker
|
||||||
|
):
|
||||||
|
client_request.login(platform_admin_user)
|
||||||
|
get_services = mocker.patch(
|
||||||
|
'app.service_api_client.find_services_by_name',
|
||||||
|
return_value={"data": [service_json()]}
|
||||||
|
)
|
||||||
|
document = client_request.post(
|
||||||
|
'main.find_services_by_name',
|
||||||
|
_data={"search": "Test Service"},
|
||||||
|
_expected_status=200
|
||||||
|
)
|
||||||
|
get_services.assert_called_once_with(service_name="Test Service")
|
||||||
|
result = document.find('a', {'class': 'browse-list-link'})
|
||||||
|
assert result.text.strip() == 'Test Service'
|
||||||
|
assert result.attrs["href"] == "/services/1234"
|
||||||
|
|
||||||
|
|
||||||
|
def test_find_services_by_name_displays_multiple_services(
|
||||||
|
client_request,
|
||||||
|
platform_admin_user,
|
||||||
|
mocker
|
||||||
|
):
|
||||||
|
client_request.login(platform_admin_user)
|
||||||
|
mocker.patch(
|
||||||
|
'app.service_api_client.find_services_by_name',
|
||||||
|
return_value={"data": [service_json(name="Tadfield Police"), service_json(name="Tadfield Air Base")]}
|
||||||
|
)
|
||||||
|
document = client_request.post('main.find_services_by_name', _data={"search": "Tadfield"}, _expected_status=200)
|
||||||
|
|
||||||
|
results = document.findAll('a', {'class': 'browse-list-link'})
|
||||||
|
assert len(results) == 2
|
||||||
|
assert sorted([result.text.strip() for result in results]) == ["Tadfield Air Base", "Tadfield Police"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_find_services_by_name_displays_message_if_no_services_found(
|
||||||
|
client_request,
|
||||||
|
platform_admin_user,
|
||||||
|
mocker
|
||||||
|
):
|
||||||
|
client_request.login(platform_admin_user)
|
||||||
|
mocker.patch('app.service_api_client.find_services_by_name', return_value={"data": []})
|
||||||
|
document = client_request.post(
|
||||||
|
'main.find_services_by_name', _data={"search": "Nabuchodonosorian Empire"}, _expected_status=200
|
||||||
|
)
|
||||||
|
|
||||||
|
assert document.find('p', {'class': 'browse-list-hint'}).text.strip() == 'No services found.'
|
||||||
|
|
||||||
|
|
||||||
|
# def test_find_users_by_email_validates_against_empty_search_submission(
|
||||||
|
# client_request,
|
||||||
|
# platform_admin_user,
|
||||||
|
# mocker
|
||||||
|
# ):
|
||||||
|
# client_request.login(platform_admin_user)
|
||||||
|
# document = client_request.post('main.find_users_by_email', _data={"search": ""}, _expected_status=400)
|
||||||
|
#
|
||||||
|
# expected_message = "You need to enter full or partial email address to search by."
|
||||||
|
# assert document.find('span', {'class': 'error-message'}).text.strip() == expected_message
|
||||||
Reference in New Issue
Block a user