Commit Graph

103 Commits

Author SHA1 Message Date
Carlo Costino
4b1db40cbd Fix failing tests
This includes a fix for the commit hash test, which was not referencing the Flask app in a valid way.

Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
2024-03-19 15:53:38 -04:00
Kenneth Kehl
e4087ca9d5 fix commit hash 2024-03-14 13:26:05 -07:00
Kenneth Kehl
3aacdcb3ef fix_commit_hash 2024-03-14 13:25:02 -07:00
Carlo Costino
95ba7c3099 More formatting fixes for tests
Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
2023-10-12 10:24:48 -04:00
Kenneth Kehl
8c9721d8e2 notify-api-412 use black to enforce python coding style 2023-08-25 09:12:23 -07:00
Chris Hill-Scott
4f672cb5dc Make logo CDN domain into simple config
Having this as a function which does string parsing and manipulation
surprised me a bit when I was trying to figure out why something wasn’t
working.

It’s more in line with the way we do other config like this (for example
`ASSET_PATH`) to make it a simple config variable, rather than trying to
be clever and guess things based on other config variables.

It’s also less code, and is explicit enough that it doesn’t need tests.
2022-01-27 10:33:05 +00:00
Chris Hill-Scott
6540701aa7 Replace uses of client to set request context
Some tests use the `client` fixture but don’t call any of its methods.
The reason for doing this is because the test depends on something in
the request context.

This commit replaces all those instances with `client_request`, which
also sets the request context.

These tests are the last ones that still use the `client` fixture. By
replacing it with `client_request` we will be able to say that no tests
should be using the `client` fixture directly.
2022-01-10 14:39:46 +00:00
Ben Thorner
1c4a903b65 Move tests to match the module they are in
Previously some of the tests for code in the "formatters" module
were in tests for the "utils" module. This moves them to where
they should be. While two of these methods are probably more utils
than formatters, I'd like to postpone a refactor of that module
for now, and focus on slimming down test for utils/__init__.py.
2021-06-14 12:52:57 +01:00
Ben Thorner
c17d438de8 DRY-up email revalidation check
Previously this was duplicated between the "two_factor" and the
"webauthn" views, and required more test setup. This DRYs up the
check and tests it once, using mocks to simplify the view tests.

As part of DRYing up the check into a util module, I've also moved
the "is_less_than_days_ago" function it uses.
2021-06-14 12:52:54 +01:00
Ben Thorner
edb0b8214d Move pagination utils into own module
This continues the pattern established in [1], just to chip away a
bit more at the random collection of stuff in utils/__init__.py.

[1]: https://github.com/alphagov/notifications-admin/pull/3923
2021-06-14 11:00:05 +01:00
Ben Thorner
0326005aeb Extract template / csv utility code into modules
This follows a similar approach to the previous commits, noting that
one module depends on the other, so we have to extract both together.
2021-06-09 15:19:00 +01:00
Ben Thorner
2a4aa8b4e1 Extract letter utility code into own module
This provides more room for expansion, and reduces the amount of
arbitrary code in the __init__.py file for the new package.
2021-06-09 13:59:06 +01:00
Rebecca Law
9a4b6de37d Bump utils version for new invalid address character 2021-05-27 13:04:46 +01:00
Ben Thorner
5bfce61bcf Rename "app_" fixture to "notify_admin"
This naming was introduced in 2016 without explanation [1]. I find it
confusing because:

- It's reminiscent of "_app", which is a Python convention indicating
the variable is internal, so maybe avoid using it.

- It suggests there's some other "app" fixture I should be using (there
isn't, though).

The Python style guide describes using an underscore suffix to avoid
clashes with inbuilt names [1], which is sort of applicable if we need
to import the "app" module [2]. However, we can also avoid clashes by
choosing a different name, without the strange underscore.

[1]: 3b1d521c10
[2]: 78824f54fd/tests/app/main/views/test_forgot_password.py (L5)
2021-05-19 11:44:20 +01:00
Chris Hill-Scott
7013eb9696 Make get_current_financial_year timezone aware
It would have given the wrong answer for the first hour of the 2021
financial year.

This was OK before, because we didn’t need this kind of precision. But
now it could mean someone signing up in the middle of the night getting
the wrong free text message allowance, so we should fix it.
2021-03-08 17:01:04 +00:00
Rebecca Law
f0ce2c6f5b Update utils to version 43.8.
Invalid characters for the first line of a postal address now include < >
2021-02-09 14:07:01 +00:00
Tom Byers
67392e97ee Fix issue with looping in list merging
The last_dest_idx variable should always have been
tracking the last index in the source list. The
original intention, implemented incorrectly, was
to just append any items which source has no item
at that index.
2021-01-26 12:16:08 +00:00
Tom Byers
1059cf4d81 Remove extend_params in favour of merge_jsonlike
A comment on the pull request for this branch
pointed out that it's not clear why the 'items'
list is deleted and then reassigned in
extend_params:

https://github.com/alphagov/notifications-admin/pull/3770#pullrequestreview-573067465

The simple reason is that we want to use
merge_jsonlike to merge params and
param_extensions (passed in as extensions) but
merge_jsonlike doesn't merge lists correctly.

I realised that if we just make merge_jsonlike
merge lists correctly, we can use it for
everything extend_params does.

This commit does that, and replaces all calls to
extend_params with merge_jsonlike.

Because extend_params is used across many form
field classes, and so many pages, I took the
following precautions after making those changes:
1. found every use of param_extensions
2. looked at the merges onto params that each would
   cause and deduped them to a final list of 6(!)
3. tested pages containing fields from that list
4. added new testcases to the merge_jsonlike tests
   for any merges that exist in our codebase but
   not in our tests
2021-01-22 15:40:28 +00:00
Tom Byers
23d391e3fc Change how merge_jsonlike treats lists
Current behaviour is to check item-against-item
and merge based on whether items match, irrelevant
of position. This doesn't produce the results we
need for our usecases (merging data to send to
GOVUK Frontend components).

We actually want:
- items to be compared based on their position
- new primitive items at the same position to
  overwrite existing ones
- dicts or lists at the same position to be merged

For example,

Starting with this list:

[{"name": "option-1", "value": "1"}]

Merging in this list:

[{"hint": {"text": "Choose one option"}}]

You currently get this:

[
  {"name": "option-1", "value": "1"},
  {"hint": {"text": "Choose one option"}}
]

We want to get this:

[
  {
    "name": "option-1", "value": "1",
    "hint": {"text": "Choose one option"}
  }
]
2021-01-21 21:15:51 +00:00
Chris Hill-Scott
7a95e1618e Extract formatters into their own module
We have lots of functions for converting various types of data into
strings to be displayed to the user somewhere.

This commit collects all these functions into their own module, rather
than having them cluttering up `app/__init__.py` or buried amongst
various other things that have ended up in `app/utils.py`.
2021-01-07 11:57:30 +00:00
Chris Hill-Scott
5c2469b24e Refactor to use shared date comparison function
This means we don’t have to repeatedly do timezone conversions or string
to datetime conversions in our business logic.
2020-09-29 13:38:00 +01:00
Tom Byers
a75cde039f Merge pull request #3624 from alphagov/add-accessible-letter-specification
Add accessible letter specification
2020-09-22 16:36:15 +01:00
Chris Hill-Scott
2d64306e88 Link to specification page, not PDF directly 2020-09-22 15:49:38 +01:00
Chris Hill-Scott
ae17ff1f07 Fix significant figure round for value of 0
You can’t do `log10(0)` in maths, so we need to handle it as a special
case.
2020-09-17 11:08:36 +01:00
Chris Hill-Scott
f824b3a5eb Give specific error if international letters off
If a service doesn’t have permission to send international letters but
someone tries to upload a letter with a valid international address we
just tell them that the last line must be a UK postcode.

This is a bit opaque and:
- suggests that we’re not recognising at all that it’s not a UK letter
- doesn’t explain why it must be a UK postcode

This commit adds a new, error message which tells users why their letter
can’t be sent. And hopefully will give them a better idea of how to
resolve the problem, if they really do need to be able to send
international letters.
2020-09-10 11:25:17 +01:00
Pea Tyczynska
67da2c28bf Deep merge jsonlike objects
Also remove duplicate checkboxes code
2020-08-14 14:58:05 +01:00
Katie Smith
ba5f7d7c36 Check for invalid chars in letter addresses
This now adds validation for invalid characters on the
LetterAddressForm for one off letters. It also adds a validation failed
message for uploaded letters, precompiled letters sent through the API,
and CSV rows with errors.
2020-07-31 08:51:07 +01:00
Chris Hill-Scott
34f5417844 Group uploaded letters by day of printing
Some teams have started uploading quite a lot of letters (in the
hundreds per week). They’re also uploading CSVs of emails. This means
the uploads page ends up quite jumbled.

This is because:
- there’s just a lot of items to scan through
- conceptually it’s a bit odd to have batches of things displayed
  alongside individual things on the same page

So instead we’re going to start grouping together uploaded letters. This
will be by the date on which we ‘start’ printing them, or in other
words the time at which they can no longer be cancelled.

This feels like a natural grouping, and it matches what we know about
people’s mental models of ‘batches’ and ‘runs’ when talking about
printing.

This grouping will be done in the API, so all this commit need to do is:
- be ready to display this new type of pseudo-job
- link to the page that displays all the uploaded letters for a given
  print day
2020-05-11 14:29:03 +01:00
David McDonald
b6935a3c6c Fix bug with letter job CSV downloads
We were throwing an exception when instantiating a LetterImageTemplate
as we weren't giving it all the arguments it needed.

 Now we give it all the correct parameters and add a
test for the method. Ideally we would add a unit test for the flask
route for downloading a letter job CSV (which is currently lacking) but
I did the minimal to be confident I've fixed the bug as I think this
whole code may be fresh for a bit of a rewrite according to Chris.

Original error:
```
File "/Users/davidmcdonald/.virtualenvs/notifications-admin/lib/python3.6/site-packages/notifications_utils/template.py", line 669, in __init__
    raise TypeError('image_url is required')
TypeError: image_url is required
```
2020-05-06 14:44:37 +01:00
Chris Hill-Scott
4cf218f5c8 Add error messages for bad international addresses
Template preview started putting these in the metadata of the S3 object
in this pull request: https://github.com/alphagov/notifications-template-preview/pull/445

Specific error key is defined here:
800b48fce5/app/precompiled.py (L558)
2020-05-04 10:14:16 +01:00
Leo Hemsted
671d0872c2 fix letter notification status around UTC/BST
timezones grr blah blah blah
2020-04-14 09:52:13 +01:00
Katie Smith
13650b7d4b Update error messages for letters that are too long
To specify the number of sheets as well as pages in case this is not
clear.
2020-04-09 11:03:07 +01:00
Chris Hill-Scott
54d7c6fcbd Get ready to error for precompiled letters with bad addresses
Template preview is going to start returning these errors; we need to be
ready to handle them.
2020-04-07 09:09:03 +01:00
Pea Tyczynska
86ab0a6a0f Add missing test cases for precompiled validation messages 2020-04-02 13:39:40 +01:00
Pea Tyczynska
e413798b4d Change email_access_validated_at formatting to be more in line with other dates on User model 2020-02-17 11:34:25 +00:00
Pea Tyczynska
7d460fe483 Move date-checking logic to utils and unit test it 2020-02-17 11:34:25 +00:00
Katie Smith
f425fe75cf Update link in error messages for uploaded letters 2020-02-13 16:14:11 +00:00
Leo Hemsted
4e1fcfbff1 handle invalid upload errors correctly
previously it assumed that invalid_pages would always exist, however it
might be `None` if the error isn't on a specific page. Errors on
specific pages include a page not being A4 or content being outside the
boundary. Errors not on specific pages include the file not being a pdf,
or containing too many pages
2020-01-27 15:11:37 +00:00
Chris Hill-Scott
34f209a08b Fix mixed-up error messages
The too many pages error was being returned when the file couldn’t be
read. This commit corrects the error message, and adds a test to make
sure this case is covered.
2020-01-20 15:54:07 +00:00
Chris Hill-Scott
1fc0f58541 Add test for plural form of error message 2020-01-20 15:50:16 +00:00
Chris Hill-Scott
3762daad84 Add a redirect for the letter specification
This way we have a URL we can give people that always points to the
latest version of the spec.

And it makes our code more Flask-idiomatic to be using `url_for` to be
generating a URL, rather than passing around a constant.
2020-01-15 11:54:14 +00:00
Chris Hill-Scott
b57e4a0d0d Test URLs separately
It’s hard to read the tests when they have HTML bundled up with content.
So this commit:
- introduces BeautifulSoup to parse the HTML
- asserts separately on the text and any links found in the HTML
2020-01-14 13:50:22 +00:00
Chris Hill-Scott
540945539b Add some summaries of letter validation errors
We show letter validation errors in two places:

1. In response to a user uploading a PDF
   Here we use the error banner pattern because the problem is as a
   direct consequence of a user’s action, and is blocking them from
   continuing.

2. Once a PDF provided through the API has been validated
   We use a less prominent pattern of red text with no border because
   the message is reporting on something that’s already happened, and
   which wasn’t a direct consequence of the user clicking something

Because the context and patterns used are different we need slightly
different content in each of these situations. Previously we tried to
reuse the same content to make the code cleaner and less repetitive. But
ultimately a clear interface trumps clear code.
2020-01-14 13:34:18 +00:00
Chris Hill-Scott
72abd89fe0 Fix indentation and trailing commas
This will make the diffs introducing substative changes easier to read.
Consistent indenting and always having trailing commas on lists and
dictionaries makes for smaller diffs.
2020-01-14 13:31:29 +00:00
Rebecca Law
f7b3f9b06a - Remove the trailing comma from the first line of the "to" field
- Add client_reference to the activity CSV report
- Show the recipient on the CSV report the same way as the view activity page.
2020-01-10 16:00:40 +00:00
Rebecca Law
47ec4912db Merge pull request #3253 from alphagov/new-no-address-message
Added a new error message when the letter is missing an address block.
2020-01-10 15:44:47 +00:00
Rebecca Law
70276cb526 Added a new error message when the letter is mising an address block.
Before deploying a change to template-preview to return a validation error for letters that are missing the address block, we need to add the new erorr message to admin.

Some content changes have been made to other messages.
The format of the message has changed.
2020-01-10 14:42:56 +00:00
Katie Smith
8e9b7ae368 Remove arguments from fixtures
These can't be used, since we fixtures can no longer be called as if
they were functions, so we can simply the code by removing them.
2020-01-10 12:17:56 +00:00
Katie Smith
8f7a05200d Add function to map template-preview errors to user-friendly errors
Template preview now returns a short string as it's error message plus
a list of invalid pages.
2019-10-21 08:35:04 +01:00
Pea Tyczynska
4a679a6583 Letter job can't be cancelled if already printed
Non-cancellable letter statuses mean that it's too late to cancel a job
2019-07-04 14:44:21 +01:00