From 06a15c5afccbce843f1277d20d9b327b526335ac Mon Sep 17 00:00:00 2001 From: Jonathan Bobel Date: Thu, 16 Nov 2023 12:02:59 -0500 Subject: [PATCH 1/7] 927 - Updates to math in Dashboard area --- app/__init__.py | 5 ++++- app/assets/javascripts/date.js | 9 +++++++++ app/templates/views/dashboard/_usage.html | 2 +- app/templates/views/dashboard/dashboard.html | 4 ++-- app/templates/views/usage.html | 2 +- gulpfile.js | 1 + 6 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 app/assets/javascripts/date.js diff --git a/app/__init__.py b/app/__init__.py index 1694fe018..3c71904df 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -301,7 +301,10 @@ def init_app(application): remaining_global_messages = global_limit - global_messages_count.get( "count" ) - return {"daily_global_messages_remaining": remaining_global_messages} + return { + "daily_global_messages_remaining": remaining_global_messages, + "global_message_limit": global_limit + } @application.before_request def record_start_time(): diff --git a/app/assets/javascripts/date.js b/app/assets/javascripts/date.js new file mode 100644 index 000000000..1d6a0d353 --- /dev/null +++ b/app/assets/javascripts/date.js @@ -0,0 +1,9 @@ +(function (window) { + + "use strict"; + + // Show the current year + document.getElementById("current-year").innerHTML = new Date().getFullYear(); + + +})(window); diff --git a/app/templates/views/dashboard/_usage.html b/app/templates/views/dashboard/_usage.html index e7f9e5f07..a2e46d007 100644 --- a/app/templates/views/dashboard/_usage.html +++ b/app/templates/views/dashboard/_usage.html @@ -15,7 +15,7 @@ - {{ big_number(40000 - sms_allowance_remaining, smaller=True) }} + {{ big_number(sms_sent, smaller=True) }} {% if sms_cost %} {{ big_number( diff --git a/app/templates/views/dashboard/dashboard.html b/app/templates/views/dashboard/dashboard.html index 851629621..828c83101 100644 --- a/app/templates/views/dashboard/dashboard.html +++ b/app/templates/views/dashboard/dashboard.html @@ -45,7 +45,7 @@ - {{ 5000 - daily_global_messages_remaining }} + {{ global_message_limit - daily_global_messages_remaining }} {{ daily_global_messages_remaining }} @@ -54,7 +54,7 @@ {% if current_user.has_permissions('manage_service') %} -

2023

+

{{ ajax_block(partials, updates_url, 'usage') }} {{ show_more( url_for(".usage", service_id=current_service['id']), diff --git a/app/templates/views/usage.html b/app/templates/views/usage.html index a9801aabd..87ce5ade8 100644 --- a/app/templates/views/usage.html +++ b/app/templates/views/usage.html @@ -22,7 +22,7 @@

Daily messages across all services

-

You have sent {{ 5000 - daily_global_messages_remaining }} of your 5000 daily messages allowance.

+

You have sent {{ global_message_limit - daily_global_messages_remaining }} of your {{ global_message_limit }} daily messages allowance.

You have {{ daily_global_messages_remaining }} messages remaining.

Text messages

diff --git a/gulpfile.js b/gulpfile.js index f26ef6f39..541c39cf4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -126,6 +126,7 @@ const javascripts = () => { paths.src + 'javascripts/errorBanner.js', paths.src + 'javascripts/homepage.js', paths.src + 'javascripts/timeoutPopup.js', + paths.src + 'javascripts/date.js', paths.src + 'javascripts/main.js', ]) .pipe(plugins.prettyerror()) From 6cee00929ecc2a4cffda9267500d760ebb616cf7 Mon Sep 17 00:00:00 2001 From: Jonathan Bobel Date: Thu, 16 Nov 2023 12:26:35 -0500 Subject: [PATCH 2/7] Fixed tests --- app/__init__.py | 3 ++- tests/app/main/views/test_dashboard.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 3c71904df..ab3e924a2 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -284,6 +284,7 @@ def init_app(application): @application.context_processor def _attach_current_global_daily_messages(): + global global_limit remaining_global_messages = 0 if current_app: if request.view_args: @@ -302,8 +303,8 @@ def init_app(application): "count" ) return { + "global_message_limit": global_limit, "daily_global_messages_remaining": remaining_global_messages, - "global_message_limit": global_limit } @application.before_request diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index f0e07f105..f2c9af263 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -1531,7 +1531,7 @@ def test_service_dashboard_shows_usage( assert normalize_spaces(page.select_one("[data-key=usage]").text) == ( "Daily Usage Remaining " - "40,000 " + "251,800 " "$29.85 " "spent on text messages" # Disabled for pilot @@ -1566,4 +1566,4 @@ def test_service_dashboard_shows_free_allowance( usage_text = normalize_spaces(page.select_one("[data-key=usage]").text) assert "spent on text messages" not in usage_text - assert "Daily Usage Remaining -209,000 249,000" in usage_text + assert "Daily Usage Remaining 1,000 249,000" in usage_text From 077b1b8ed9bed004c9071848a4cbdf4c12741fb0 Mon Sep 17 00:00:00 2001 From: Jonathan Bobel Date: Mon, 20 Nov 2023 13:45:35 -0500 Subject: [PATCH 3/7] Updated utils --- app/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/__init__.py b/app/__init__.py index ab3e924a2..21f0c8e03 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -284,7 +284,7 @@ def init_app(application): @application.context_processor def _attach_current_global_daily_messages(): - global global_limit + global_limit = 0 remaining_global_messages = 0 if current_app: if request.view_args: From e4c97e925f2be33d9aa373ac7be22fbb869bcd2f Mon Sep 17 00:00:00 2001 From: Jonathan Bobel Date: Tue, 21 Nov 2023 15:38:41 -0500 Subject: [PATCH 4/7] Adding a test for the dashboard usage area --- tests/app/main/views/test_dashboard.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index f2c9af263..031bc0316 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -1517,6 +1517,7 @@ def test_breadcrumb_shows_if_service_is_suspended( ], ) def test_service_dashboard_shows_usage( + mocker, client_request, service_one, mock_get_service_templates, @@ -1526,18 +1527,22 @@ def test_service_dashboard_shows_usage( mock_get_free_sms_fragment_limit, permissions, ): + mocker.patch( + "app.service_api_client.get_global_notification_count", + return_value={ + "count": 500, + }, + ) + service_one["permissions"] = permissions page = client_request.get("main.service_dashboard", service_id=SERVICE_ONE_ID) - assert normalize_spaces(page.select_one("[data-key=usage]").text) == ( - "Daily Usage Remaining " - "251,800 " - "$29.85 " - "spent on text messages" - # Disabled for pilot - # '0 ' - # 'email disabled during SMS pilot' - ) + table_rows = page.find_all("tbody")[0].find_all("tr") + + assert len(table_rows) == 1 + + assert "500" in table_rows[0].find_all("td")[0].text + assert "9500" in table_rows[0].find_all("td")[1].text def test_service_dashboard_shows_free_allowance( From 2178659d3138e83d198373a7c12bddef69341d1c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 Nov 2023 23:31:43 +0000 Subject: [PATCH 5/7] Bump exceptiongroup from 1.1.3 to 1.2.0 Bumps [exceptiongroup](https://github.com/agronholm/exceptiongroup) from 1.1.3 to 1.2.0. - [Release notes](https://github.com/agronholm/exceptiongroup/releases) - [Changelog](https://github.com/agronholm/exceptiongroup/blob/main/CHANGES.rst) - [Commits](https://github.com/agronholm/exceptiongroup/compare/1.1.3...1.2.0) --- updated-dependencies: - dependency-name: exceptiongroup dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- poetry.lock | 8 ++++---- pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/poetry.lock b/poetry.lock index 68a247592..1a61346ce 100644 --- a/poetry.lock +++ b/poetry.lock @@ -625,13 +625,13 @@ six = ">=1.10.0" [[package]] name = "exceptiongroup" -version = "1.1.3" +version = "1.2.0" description = "Backport of PEP 654 (exception groups)" optional = false python-versions = ">=3.7" files = [ - {file = "exceptiongroup-1.1.3-py3-none-any.whl", hash = "sha256:343280667a4585d195ca1cf9cef84a4e178c4b6cf2274caef9859782b567d5e3"}, - {file = "exceptiongroup-1.1.3.tar.gz", hash = "sha256:097acd85d473d75af5bb98e41b61ff7fe35efe6675e4f9370ec6ec5126d160e9"}, + {file = "exceptiongroup-1.2.0-py3-none-any.whl", hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"}, + {file = "exceptiongroup-1.2.0.tar.gz", hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"}, ] [package.extras] @@ -2970,4 +2970,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.12" -content-hash = "4a38fa6c01f64c2e813d2e65aa22334357fe8785fc76c2008668ed9eab7a27de" +content-hash = "7acdbc62b3764d6a65058ad66c405124dee447081046bb348a6b9ebe3c463053" diff --git a/pyproject.toml b/pyproject.toml index 661af4e57..b2647d294 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ readme = "README.md" python = ">=3.9,<3.12" ago = "~=0.0.95" blinker = "~=1.7" -exceptiongroup = "==1.1.3" +exceptiongroup = "==1.2.0" flask = "~=2.3" flask-basicauth = "~=0.2" flask-login = "^0.6" From ce21df6048dc7738f39970dafb06f3cf6e9422f2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 22 Nov 2023 14:15:17 +0000 Subject: [PATCH 6/7] Bump pytest-xdist from 3.4.0 to 3.5.0 Bumps [pytest-xdist](https://github.com/pytest-dev/pytest-xdist) from 3.4.0 to 3.5.0. - [Release notes](https://github.com/pytest-dev/pytest-xdist/releases) - [Changelog](https://github.com/pytest-dev/pytest-xdist/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-xdist/compare/v3.4.0...v3.5.0) --- updated-dependencies: - dependency-name: pytest-xdist dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- poetry.lock | 8 ++++---- pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/poetry.lock b/poetry.lock index 1a61346ce..04abd1595 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2265,13 +2265,13 @@ python-slugify = ">=6.0.0,<9.0.0" [[package]] name = "pytest-xdist" -version = "3.4.0" +version = "3.5.0" description = "pytest xdist plugin for distributed testing, most importantly across multiple CPUs" optional = false python-versions = ">=3.7" files = [ - {file = "pytest-xdist-3.4.0.tar.gz", hash = "sha256:3a94a931dd9e268e0b871a877d09fe2efb6175c2c23d60d56a6001359002b832"}, - {file = "pytest_xdist-3.4.0-py3-none-any.whl", hash = "sha256:e513118bf787677a427e025606f55e95937565e06dfaac8d87f55301e57ae607"}, + {file = "pytest-xdist-3.5.0.tar.gz", hash = "sha256:cbb36f3d67e0c478baa57fa4edc8843887e0f6cfc42d677530a36d7472b32d8a"}, + {file = "pytest_xdist-3.5.0-py3-none-any.whl", hash = "sha256:d075629c7e00b611df89f490a5063944bee7a4362a5ff11c7cc7824a03dfce24"}, ] [package.dependencies] @@ -2970,4 +2970,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.12" -content-hash = "7acdbc62b3764d6a65058ad66c405124dee447081046bb348a6b9ebe3c463053" +content-hash = "c624e38a1adc079ddca3879e654114380d275deb3a56e180488fc8f3471178f0" diff --git a/pyproject.toml b/pyproject.toml index b2647d294..b28ee9b53 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,7 +56,7 @@ pytest = "^7.4.3" pytest-env = "^1.1.1" pytest-mock = "^3.12.0" pytest-playwright = "^0.4.3" -pytest-xdist = "^3.4.0" +pytest-xdist = "^3.5.0" radon = "^6.0.1" requests-mock = "^1.11.0" vulture = "^2.10" From a6ea9fd25ca1df435bdd17e2ee8741b1e6b4bcf9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 22 Nov 2023 14:33:13 +0000 Subject: [PATCH 7/7] Bump humanize from 4.8.0 to 4.9.0 Bumps [humanize](https://github.com/python-humanize/humanize) from 4.8.0 to 4.9.0. - [Release notes](https://github.com/python-humanize/humanize/releases) - [Commits](https://github.com/python-humanize/humanize/compare/4.8.0...4.9.0) --- updated-dependencies: - dependency-name: humanize dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- poetry.lock | 8 ++++---- pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/poetry.lock b/poetry.lock index 04abd1595..ff50d9b19 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1054,13 +1054,13 @@ lxml = ["lxml"] [[package]] name = "humanize" -version = "4.8.0" +version = "4.9.0" description = "Python humanize utilities" optional = false python-versions = ">=3.8" files = [ - {file = "humanize-4.8.0-py3-none-any.whl", hash = "sha256:8bc9e2bb9315e61ec06bf690151ae35aeb65651ab091266941edf97c90836404"}, - {file = "humanize-4.8.0.tar.gz", hash = "sha256:9783373bf1eec713a770ecaa7c2d7a7902c98398009dfa3d8a2df91eec9311e8"}, + {file = "humanize-4.9.0-py3-none-any.whl", hash = "sha256:ce284a76d5b1377fd8836733b983bfb0b76f1aa1c090de2566fcf008d7f6ab16"}, + {file = "humanize-4.9.0.tar.gz", hash = "sha256:582a265c931c683a7e9b8ed9559089dea7edcf6cc95be39a3cbc2c5d5ac2bcfa"}, ] [package.extras] @@ -2970,4 +2970,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.12" -content-hash = "c624e38a1adc079ddca3879e654114380d275deb3a56e180488fc8f3471178f0" +content-hash = "f49ee7dbab2abe9884ac8576ebe3b654d5ba7754249908ccb5c50e05c2629666" diff --git a/pyproject.toml b/pyproject.toml index b28ee9b53..f325a2212 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ flask-wtf = "^1.2" govuk-bank-holidays = "==0.13" govuk-frontend-jinja = {git = "https://github.com/alphagov/govuk-frontend-jinja.git", tag = "v0.5.8-alpha"} gunicorn = {version = "==21.2.0", extras = ["eventlet"]} -humanize = "~=4.8" +humanize = "~=4.9" itsdangerous = "~=2.1" jinja2 = "~=3.1" newrelic = "*"