Skip to content

Commit

Permalink
Add filter heartbeats for live service data
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbahrai committed Feb 9, 2024
1 parent 3b371b4 commit 7ab86e7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
11 changes: 10 additions & 1 deletion app/dao/services_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,17 @@ def dao_fetch_live_services_data(filter_heartbeats=None):
AnnualBilling.free_sms_fragment_limit,
)
.order_by(asc(Service.go_live_at))
.all()
)
if filter_heartbeats:
data = data.join(Template, Service.id == Template.service_id).filter(
Template.id != current_app.config["HEARTBEAT_TEMPLATE_EMAIL_LOW"],
Template.id != current_app.config["HEARTBEAT_TEMPLATE_EMAIL_MEDIUM"],
Template.id != current_app.config["HEARTBEAT_TEMPLATE_EMAIL_HIGH"],
Template.id != current_app.config["HEARTBEAT_TEMPLATE_SMS_LOW"],
Template.id != current_app.config["HEARTBEAT_TEMPLATE_SMS_MEDIUM"],
Template.id != current_app.config["HEARTBEAT_TEMPLATE_SMS_HIGH"],
)
data = data.all()
results = []
for row in data:
existing_service = next((x for x in results if x["service_id"] == row.service_id), None)
Expand Down
2 changes: 1 addition & 1 deletion app/service/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def find_services_by_name():

@service_blueprint.route("/live-services-data", methods=["GET"])
def get_live_services_data():
filter_heartbeats = request.args.get("filter_heartbeats", None)
filter_heartbeats = request.args.get("filter_heartbeats", None) == "True"
data = dao_fetch_live_services_data(filter_heartbeats=filter_heartbeats)
return jsonify(data=data)

Expand Down
12 changes: 9 additions & 3 deletions tests/app/dao/test_services_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
create_user,
save_notification,
)
from tests.conftest import set_config

# from unittest import mock

Expand Down Expand Up @@ -493,7 +494,8 @@ def test_get_all_user_services_should_return_empty_list_if_no_services_for_user(


@freeze_time("2019-04-23T10:00:00")
def test_dao_fetch_live_services_data(sample_user):
@pytest.mark.parametrize("filter_heartbeats", [True, False])
def test_dao_fetch_live_services_data_filter_heartbeats(notify_api, sample_user, filter_heartbeats):
org = create_organisation(organisation_type="nhs_central")
service = create_service(go_live_user=sample_user, go_live_at="2014-04-20T10:00:00")
template = create_template(service=service)
Expand Down Expand Up @@ -561,8 +563,12 @@ def test_dao_fetch_live_services_data(sample_user):
# 3rd service: billing from 2019
create_annual_billing(service_3.id, 200, 2019)

results = dao_fetch_live_services_data()
assert len(results) == 3
with set_config(notify_api, "HEARTBEAT_TEMPLATE_EMAIL_LOW", template.id):
results = dao_fetch_live_services_data(filter_heartbeats=filter_heartbeats)
if not filter_heartbeats:
assert len(results) == 3
else:
assert len(results) == 2
# checks the results and that they are ordered by date:
# @todo: this test is temporarily forced to pass until we can add the fiscal year back into
# the query and create a new endpoint for the homepage stats
Expand Down

0 comments on commit 7ab86e7

Please sign in to comment.