Commit Graph

12559 Commits

Author SHA1 Message Date
Ben Thorner
3449ccd923 Support multiple SMS rates per month on usage page 2022-05-03 16:01:13 +01:00
Ben Thorner
75e0d53e76 Simplify test for only showing historic months
This goal wasn't clear from the original test, which was checking
the entire return value, even though this is covered implicitly by
tests of the usage page itself.
2022-05-03 16:01:12 +01:00
Ben Thorner
c05502835b Simplify monthly letter breakdown ordering test
This doesn't need to test variable rates for every postage class,
which is more an aspect of grouping. It only needs to check that
some out-of-order usage gets reordered appropriately.
2022-05-03 16:01:11 +01:00
Ben Thorner
63c35ec3d9 Remove redundant test for letter usage breakdown
This is covered sufficiently by the main "test_usage" assertions,
which prove the usage is broken down by postage.

I don't think we need to explicitly test the usage is broken down
by month as we already prove this for SMS and we also check the
usage is associated with the correct month in the "ordering" test.
2022-05-03 16:01:10 +01:00
Ben Thorner
91e902bc2c Tidy up "format" method for monthly letter usage
This did more than it said and had some unconventional behaviour:

- It modified the input data. We can avoid this by computing the
postage group on-the-fly and using "sorted" instead of "sort".

- It defined a custom, named tuple. This isn't necessary as Jinja
allows us to access elements by qualification (".") already.

We can also use the same lambda function to group and sort items,
since the sort predicate is the same one we use to group them.
2022-05-03 16:01:09 +01:00
Ben Thorner
fb7c116046 Finish migration from billing_units to API fields
This is now only used for letters and represents the number sent
[^1].  We could use the chargeable_units field, but using "_sent"
is more consistent with the annual attributes [^2].

In fact, chargeable_units isn't actually used anywhere, but I've
kept it in the test data as it is part of the real API and helps
clarify the other values for SMS - free vs. charged.

Note: for SMS I've used an arbitrary "1234" for "chargeable_units"
to indicate it's not used and may be different to the number sent -
for SMS it's related to the number of fragments.

[^1]: bb62d22f25/app/dao/fact_billing_dao.py (L339)
[^2]: 3a1ac189ff/app/main/views/dashboard.py (L339)
2022-05-03 16:01:08 +01:00
Ben Thorner
c0ee24ff19 Migrate letter cost calculation to use API field
The values in the tests are calculated manually from other fields
in the mocked API response.
2022-05-03 16:01:07 +01:00
Ben Thorner
d798a0d60f Replace manual SMS monthly calculations with API
This starts using the sms_{cost, charged, free_allowance_used}
fields in the new API to replace the "get_free_paid_breakdown"
function we had before, which could not support multiple rates.

In order to use "get_free_paid_breakdown" the calling method had
to store a "cumulative" variable to calculate the free allowance
used so far, which is now done by the API.

To calculate the data for conftest.py, I had to start from the
bottom ("April") and manually calculate the free allowance used
to emulate the API - this is what "cumulative" used to do.
2022-05-03 16:01:06 +01:00
Ben Thorner
f6dc30665f Reorder monthly usage assertions (group by month)
This also removes an extremely confusing assertion of "40" free
messages, which was passing because we have "140" free messages.
2022-05-03 16:01:04 +01:00
Ben Thorner
ce8bdea9be Fix inaccurate test data for monthly usage API
It has never been possible to get multiple rows for the same month
and rate. This was making it hard to switch to the new API fields,
which will require some manual calculations. I've added the billing
units together in the remaining data so the tests still pass.

I've also moved the "April" row to the end as it was out-of-order
with all the others: it's the _start_ of the financial year.
2022-05-03 16:01:03 +01:00
Ben Thorner
4ab795ad68 Replace "sum_billing_units" with inline code
This is also an opportunity to DRY-up the filtering of usage by
month, which we will reuse in the following commits. Doing a sum
is simple enough that it can be done inline, avoiding indirection.
2022-05-03 16:01:02 +01:00
Ben Thorner
246356649f Rename monthly usage attributes to match API
This should make the subsequent changes to use the new API fields
a bit clearer, and also matches the annual usage attributes [^1].

[^1]: 3a1ac189ff/app/main/views/dashboard.py (L343-L350)
2022-05-03 16:01:01 +01:00
Ben Thorner
215a688250 Reuse helper function to filter usage rows
I've also dispensed with the "units" terminology here, which didn't
represent the "rows" returned by the API.
2022-05-03 16:01:00 +01:00
Ben Thorner
ca2ff00931 Rename monthly helper function to match annual one 2022-05-03 16:00:59 +01:00
Ben Thorner
4ab7e3ceec Rename billing API methods to be recognisable
I struggled to distinguish which was which as neither mentioned if
the data they returned was monthly or annual.
2022-05-03 16:00:57 +01:00
Ben Thorner
3a1ac189ff Merge pull request #4225 from alphagov/free-allowance-api-181934027
Change annual usage to work with multiple SMS rates
2022-04-29 13:22:54 +01:00
Chris Hill-Scott
208985aa25 Merge pull request #4222 from alphagov/1-may-price-change
Update text message rate on 1 May 2022
2022-04-29 11:16:57 +01:00
Chris Hill-Scott
b142136380 Merge pull request #4224 from alphagov/bump-utils-55.1.6
Bump utils to 55.1.6
2022-04-29 11:16:50 +01:00
Chris Hill-Scott
4a0f5e8a41 Make text message price dependent on date
So we don’t have to deploy a change on a Saturday.

In the future this could pull from the rates in the database, but while
that code is shifting around I didn’t want to touoch it. We’d also have
to think about caching so as not to have a non-authenticated route
hitting the database.
2022-04-28 10:48:44 +01:00
Ben Thorner
5511f15ae8 Add missing dashboard test for zero SMS cost 2022-04-27 17:08:44 +01:00
Ben Thorner
e6c04ef556 Support variable rates for annual usage stats
Note: I've removed the pricing assertion in the "0_free_allowance"
test as it's covered elsewhere - the value of the test is really to
check that we don't show the remainder if there never was any.
2022-04-27 17:06:17 +01:00
Ben Thorner
715a3c137f Rename ambiguous "sms_chargeable" Jinja variable
Now that we have the term "charge*able*_units" we should clarify
this variable is the number we will actually charge for.
2022-04-27 17:06:16 +01:00
Ben Thorner
e0aa51c306 Use new "cost" field in usage APIs
The previous, manual calculation could be incorrect depending on
which SMS rates the free allowance was attributed to.

The new field also supersedes the old "letter_total" bolt-on so we
can get cost information consistently for both types.
2022-04-27 17:06:12 +01:00
Ben Thorner
82c3e8093d Remove redundant SMS test data for annual usage 2022-04-27 16:58:18 +01:00
Ben Thorner
4925264fb7 Remove duplicate test for usage page
This is covered by the main test for the page.
2022-04-27 16:57:11 +01:00
Ben Thorner
c6f5467009 Extend main test for service usage page
This adds missing assertions for email and SMS usage, as well as
letters with the help of some additional test data.

Previously we were only checking monthly usage (in other tests).
2022-04-27 16:57:06 +01:00
Ben Thorner
2aa3e78db2 Tidy up monthly usage test assertions
The "with_letters" was mostly a duplicate of the one before - no
change in test setup - bar the three assertions at the end.

Having the assertions in a separate test will help keep the one
above manageable as we add more assertions for the annual usage.
2022-04-27 16:37:17 +01:00
Ben Thorner
55ea5d90c7 Migrate away from ambiguous "billing_units"
This uses two new fields in the annual usage API instead of the
old one, which was actually a mix of two kinds of data [^1].

[^1]: fc378fed96
2022-04-27 16:32:52 +01:00
Ben Thorner
0648f80b9d Refactor "calculate_usage" function
This will make the following changes clearer.

In the next commits we'll go into more detail about "billing_units"
and how it differs for SMS vs. emails and letters.
2022-04-27 16:30:26 +01:00
Ben Thorner
afd3f5461a Merge pull request #4221 from alphagov/usage-tidyup
Show monthly usage rate correctly if the sms rate has changed during the financial year
2022-04-27 15:37:45 +01:00
Ben Thorner
e671df1d2c Merge pull request #4226 from alphagov/update-accessibility-statement-april-2022
Review accessibility statement
2022-04-27 15:37:39 +01:00
karlchillmaid
ef9332fce5 Update review and completion dates 2022-04-27 10:53:12 +01:00
Katie Smith
417e7370bb Merge pull request #4223 from alphagov/roadmap-april-2022
Update public roadmap, April 2022
2022-04-27 08:55:38 +01:00
karlchillmaid
fdc121d529 Bump date 2022-04-27 08:38:51 +01:00
Chris Hill-Scott
a5517f2360 Bump utils to 55.1.6
Brings in:
- [x] https://github.com/alphagov/notifications-utils/pull/966/files
2022-04-26 16:40:22 +01:00
karlchillmaid
ae2644b81c Update roadmap content 2022-04-26 16:20:29 +01:00
Ben Thorner
a02e1adbc5 Tweak usage dashboard test to cover rate changes 2022-04-26 14:02:54 +01:00
karlchillmaid
dfc37c2371 Update date 2022-04-26 12:31:19 +01:00
karlchillmaid
fa40c70267 Update dates 2022-04-26 12:21:40 +01:00
karlchillmaid
d4c19140e8 Update text message rate 2022-04-26 12:05:57 +01:00
karlchillmaid
45884b6a2e Update text message rate 2022-04-26 12:05:16 +01:00
David McDonald
2706ec4c73 Take sms_rate from monthly usage data
At the moment, we put the sms rate on the usage page for each
months billing data by taking the single sms rate for the year.

The assumption that there will be a single sms rate for the year is
no longer going to be true. Therefore, instead we take the sms
rate from the monthly data itself which tells us the rate for
a months worth of sent SMS.
2022-04-26 10:38:10 +01:00
David McDonald
d18c787a02 Give better names to usage page variables
`free` becomes `sms_free_count`
`paid` becomes `sms_paid_count`

This small change is just to help with readability for this
complex area of code
2022-04-25 11:27:03 +01:00
David McDonald
c5d729b5f2 Remove unused letter_cumulative field
I have searched for this in the code and can't see it being used
anywhere so have removed it!
2022-04-25 11:11:45 +01:00
karlchillmaid
c63660d56d Merge pull request #4217 from alphagov/may-2022-price-changes
Announce May 2022 text message price increase
2022-04-22 15:20:56 +01:00
karlchillmaid
e1ff1bc4b2 Update date 2022-04-22 14:57:37 +01:00
Leo Hemsted
19d501e2aa Merge pull request #4214 from alphagov/0-free-allowance
Hide remaining free allowance if it starts at 0
2022-04-22 13:32:16 +01:00
Leo Hemsted
46658de009 Merge pull request #4219 from alphagov/enable-redis
remove redis_enabled flag
2022-04-22 13:04:43 +01:00
Leo Hemsted
3bda2aa36c remove redis_enabled flag
there's no reason we need to configure this per environment. You can
still use it as before for local development
2022-04-22 12:21:27 +01:00
Sakis
77a96b3e5f Merge pull request #4218 from alphagov/custom-prometheus-preparation
Use our own fork of gds_metrics_python and add shared auth token
2022-04-21 13:57:24 +01:00