From c587bbee7190f4816cc8384122184661493bedd0 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 7 Mar 2024 09:29:51 -0800 Subject: [PATCH 1/6] dashboard bug --- app/main/views/jobs.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index ed8f051a30..0ef267f61b 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -269,19 +269,23 @@ def get_notifications(service_id, message_type, status_override=None): # noqa def get_status_filters(service, message_type, statistics): + print(f"incoming statistics {statistics} and message_type {message_type}") if message_type is None: stats = { key: sum(statistics[message_type][key] for message_type in {"email", "sms"}) - for key in {"requested", "delivered", "failed"} + for key in {"requested", "delivered", "failure"} } else: stats = statistics[message_type] - stats["sending"] = stats["requested"] - stats["delivered"] - stats["failed"] + + print(f"STATS = {stats}") + stats["failed"] = stats["failure"] + stats filters = [ # key, label, option ("requested", "total", "sending,delivered,failed"), - ("sending", "pending", "pending"), + ("pending", "pending", "pending"), ("delivered", "delivered", "delivered"), ("failed", "failed", "failed"), ] @@ -296,7 +300,7 @@ def get_status_filters(service, message_type, statistics): message_type=message_type, status=option, ), - stats[key], + stats.get(key), ) for key, label, option in filters ] From 111c6fd93a72677b79f9a83ff0e8f3b607d786fb Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 7 Mar 2024 09:42:06 -0800 Subject: [PATCH 2/6] more fixing --- app/main/views/jobs.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index 0ef267f61b..6e22a82e21 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -269,23 +269,26 @@ def get_notifications(service_id, message_type, status_override=None): # noqa def get_status_filters(service, message_type, statistics): - print(f"incoming statistics {statistics} and message_type {message_type}") if message_type is None: stats = { key: sum(statistics[message_type][key] for message_type in {"email", "sms"}) - for key in {"requested", "delivered", "failure"} + for key in {"requested", "delivered", "failed"} } else: stats = statistics[message_type] - print(f"STATS = {stats}") - stats["failed"] = stats["failure"] - stats + if stats.get("failure") is not None: + stats["failed"] = stats["failure"] + + if stats.get("pending") is None: + stats["pending"] = 0 + if stats.get("sending") is None: + stats["sending"] = 0 filters = [ # key, label, option ("requested", "total", "sending,delivered,failed"), - ("pending", "pending", "pending"), + ("sending", "pending", "pending"), ("delivered", "delivered", "delivered"), ("failed", "failed", "failed"), ] From de38f38892edcfa21d9da0e7f875302921d8f64c Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 7 Mar 2024 09:45:21 -0800 Subject: [PATCH 3/6] fix test --- app/main/views/jobs.py | 2 +- tests/app/main/views/test_activity.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index 6e22a82e21..3f48cb9ecc 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -288,7 +288,7 @@ def get_status_filters(service, message_type, statistics): filters = [ # key, label, option ("requested", "total", "sending,delivered,failed"), - ("sending", "pending", "pending"), + ("pending", "pending", "pending"), ("delivered", "delivered", "delivered"), ("failed", "failed", "failed"), ] diff --git a/tests/app/main/views/test_activity.py b/tests/app/main/views/test_activity.py index e224c2e7d5..936bfac803 100644 --- a/tests/app/main/views/test_activity.py +++ b/tests/app/main/views/test_activity.py @@ -531,7 +531,7 @@ def test_time_left(job_created_at, expected_message): assert get_time_left(job_created_at) == expected_message -STATISTICS = {"sms": {"requested": 6, "failed": 2, "delivered": 1}} +STATISTICS = {"sms": {"requested": 6, "failed": 2, "delivered": 1, "pending": 3}} def test_get_status_filters_calculates_stats(client_request): From f42cf3bd22e9cb23722e7e5306e501a69fb3b4df Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 7 Mar 2024 09:59:58 -0800 Subject: [PATCH 4/6] rebreak the tests to reflect reality --- app/main/views/jobs.py | 2 +- tests/app/main/views/test_activity.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index 3f48cb9ecc..99506fa511 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -272,7 +272,7 @@ def get_status_filters(service, message_type, statistics): if message_type is None: stats = { key: sum(statistics[message_type][key] for message_type in {"email", "sms"}) - for key in {"requested", "delivered", "failed"} + for key in {"requested", "delivered", "failure"} } else: stats = statistics[message_type] diff --git a/tests/app/main/views/test_activity.py b/tests/app/main/views/test_activity.py index 936bfac803..29a0341de6 100644 --- a/tests/app/main/views/test_activity.py +++ b/tests/app/main/views/test_activity.py @@ -531,12 +531,13 @@ def test_time_left(job_created_at, expected_message): assert get_time_left(job_created_at) == expected_message -STATISTICS = {"sms": {"requested": 6, "failed": 2, "delivered": 1, "pending": 3}} +STATISTICS = {"sms": {"requested": 6, "failed": 2, "delivered": 1}} def test_get_status_filters_calculates_stats(client_request): ret = get_status_filters(Service({"id": "foo"}), "sms", STATISTICS) + # TODO WHY DO WE THINK THE PENDING COUNT SHOULD BE 3? HOW DID THIS WORK BEFORE? assert {label: count for label, _option, _link, count in ret} == { "total": 6, "pending": 3, From b3966ae8007d886866181ee7508dd73e2cdcd804 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 7 Mar 2024 10:17:37 -0800 Subject: [PATCH 5/6] revert previous commit --- app/main/views/jobs.py | 2 +- tests/app/main/views/test_activity.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index 99506fa511..3f48cb9ecc 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -272,7 +272,7 @@ def get_status_filters(service, message_type, statistics): if message_type is None: stats = { key: sum(statistics[message_type][key] for message_type in {"email", "sms"}) - for key in {"requested", "delivered", "failure"} + for key in {"requested", "delivered", "failed"} } else: stats = statistics[message_type] diff --git a/tests/app/main/views/test_activity.py b/tests/app/main/views/test_activity.py index 29a0341de6..936bfac803 100644 --- a/tests/app/main/views/test_activity.py +++ b/tests/app/main/views/test_activity.py @@ -531,13 +531,12 @@ def test_time_left(job_created_at, expected_message): assert get_time_left(job_created_at) == expected_message -STATISTICS = {"sms": {"requested": 6, "failed": 2, "delivered": 1}} +STATISTICS = {"sms": {"requested": 6, "failed": 2, "delivered": 1, "pending": 3}} def test_get_status_filters_calculates_stats(client_request): ret = get_status_filters(Service({"id": "foo"}), "sms", STATISTICS) - # TODO WHY DO WE THINK THE PENDING COUNT SHOULD BE 3? HOW DID THIS WORK BEFORE? assert {label: count for label, _option, _link, count in ret} == { "total": 6, "pending": 3, From 2be3db10d98780f9dbc059854e1bf18fbaa47fbc Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 7 Mar 2024 10:25:11 -0800 Subject: [PATCH 6/6] fix the right way --- app/main/views/jobs.py | 5 +---- tests/app/main/views/test_activity.py | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index 3f48cb9ecc..774f2a9163 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -280,10 +280,7 @@ def get_status_filters(service, message_type, statistics): if stats.get("failure") is not None: stats["failed"] = stats["failure"] - if stats.get("pending") is None: - stats["pending"] = 0 - if stats.get("sending") is None: - stats["sending"] = 0 + stats["pending"] = stats["requested"] - stats["delivered"] - stats["failed"] filters = [ # key, label, option diff --git a/tests/app/main/views/test_activity.py b/tests/app/main/views/test_activity.py index 936bfac803..e224c2e7d5 100644 --- a/tests/app/main/views/test_activity.py +++ b/tests/app/main/views/test_activity.py @@ -531,7 +531,7 @@ def test_time_left(job_created_at, expected_message): assert get_time_left(job_created_at) == expected_message -STATISTICS = {"sms": {"requested": 6, "failed": 2, "delivered": 1, "pending": 3}} +STATISTICS = {"sms": {"requested": 6, "failed": 2, "delivered": 1}} def test_get_status_filters_calculates_stats(client_request):