Commit Graph

59 Commits

Author SHA1 Message Date
Kenneth Kehl
36987e7202 notify-api-861 show eastern time 2023-11-16 12:24:27 -08:00
Kenneth Kehl
6e19fab1d5 more tests 2023-11-03 10:38:38 -07:00
Kenneth Kehl
90025ded54 notify-admin-866 improve tests with noqa comments 2023-10-26 08:33:59 -07:00
Carlo Costino
06fab2dd03 Ignoring two specific warnings about wrong values type
The test makes use of list item unpacking and expects the parameter data structure to allow for that.  It does not make sense to modify the code in this case just to make test format linting pass.

Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
2023-10-12 10:24:48 -04: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
5bc752a826 fix tests 2023-09-22 10:05:50 -07:00
Kenneth Kehl
8c9721d8e2 notify-api-412 use black to enforce python coding style 2023-08-25 09:12:23 -07:00
Steven Reilly
13d0e46b52 blunt rename of org (#620) 2023-07-12 12:09:44 -04:00
Kenneth Kehl
4229448a67 fix tests 2023-07-03 08:20:12 -07:00
Kenneth Kehl
618c2eb6bb fix skips and xfails 2023-05-26 12:35:48 -07:00
Ryan Ahearn
2ad21a6f4f Replace UK phone numbers in tests with US numbers 2023-01-06 11:19:56 -05:00
stvnrlly
944715ac46 big commit with letters removal 2022-12-05 15:33:44 -05:00
stvnrlly
a8b8d09fb7 post-gray test updates 2022-12-02 10:30:37 -05:00
stvnrlly
e12e780a05 code cleanup 2022-11-28 15:53:56 -05:00
stvnrlly
77c0faf4e5 more test fixes, one test remaining 2022-11-28 13:51:37 -05:00
stvnrlly
ca1897973a test time fixes and bonus letter removal 2022-11-22 17:03:42 -05:00
stvnrlly
218eb3559f Merge branch 'main' into stvnrlly-remove-broadcasts 2022-10-26 01:27:44 +00:00
stvnrlly
f16b5dd1c4 remove broadcast-related code 2022-10-04 03:04:13 +00:00
stvnrlly
947140bd60 isort has opinions, fine 2022-09-15 20:37:38 +00:00
stvnrlly
f2eaa120e4 satisfy flake8 2022-09-15 19:14:19 +00:00
stvnrlly
3e7b5b4370 update tests based on updated orgs 2022-09-15 18:47:04 +00:00
jimmoffet
b465131338 all tests passing 2022-08-05 01:22:32 -07:00
jimmoffet
dad051a662 2767 passing 2022-08-05 00:25:03 -07:00
Chris Hill-Scott
30eebf3586 Reorder and label test cases
This commit takes the existing test cases, removes duplicates, and tries
to add a human-readable comment explaining what each one is testing.
2022-06-06 15:10:27 +01:00
Chris Hill-Scott
ea9c7e6102 Use existing user fixture 2022-06-06 15:10:27 +01:00
Chris Hill-Scott
f779a97b5c Use decorator as decorator
This syntax makes it clearer what is being tested here, because it’s
unusual to see a decorator being manually called with function as its
first argument.

It’s also consistent with how the later tests in this file are written.
2022-06-06 13:55:25 +01:00
Chris Hill-Scott
122a045142 Define user inside each test
This user is only re-used once, which isn’t a big saving. By putting it
inside the test it’s easy to see what special conditions are being set
up that result in the expected outcometest result.
2022-06-06 13:46:39 +01:00
Chris Hill-Scott
60870c69a7 Split platform admin test out
By making the one platform admin case a separate test we no longer
need to pass in a `user` or `kwargs` to the parametrize every time,
making it easier to read.
2022-06-06 13:45:29 +01:00
Chris Hill-Scott
f79c3f27e3 Use fixture to create user dict
This removes a bunch of dummy data which isn’t relevant to the tests
being run.
2022-06-06 13:44:36 +01:00
Chris Hill-Scott
e6e2770a04 Rewrite test_permissions with parametrize
It’s easier to see what the different test cases are when they are laid
out with `parametrize`, rather than separate functions with lots of
boilerplate.
2022-06-06 13:43:46 +01:00
Chris Hill-Scott
15131d003b Let client_request do user mocking
`client_request.login` already mocks calls to get the current user, so
we don’t need to do it manually.
2022-06-06 13:41:52 +01:00
Chris Hill-Scott
684fc5057a Move non-success handling out of helper
The helper function handles both tests that pass, and tests that are
expected to fail (either by raising an exception or returning a redirect
to the login page).

By moving the handling of cases which are expected to fail out of the
helper function we can make the helper function less complex, which will
make further refactoring easier.
2022-06-06 13:39:42 +01:00
Chris Hill-Scott
84d4c1e0b5 Remove catching of exception that is never raised
View functions won’t raise an `Unauthorized` exception, they will return
a redirect to the login page instead.
2022-06-06 13:38:59 +01:00
Chris Hill-Scott
5b5d4af681 Work around inconsistent request context in tests
The failing test here[1] does two things:
1. makes a request to /sign-out
2. calls the index route, without actually making a request

This means that when the `login_manager.unauthorized_handler`[2] looks
at Flask’s `request` object it gets the request context from 1., not 2.,
because 2. isn’t actually a request. The means it sets the value of the
`next` parameter to that of the request, not of the index route.

Basically at some point Flask has changed and decided that 2. isn’t a
proper request, so won’t set new request context.

This isn’t a realistic test because nothing would call the index
function directly, it would always be as part of a request to that page.

But to make the minimal change to fix the breaking tests this commit
makes the check a bit more general, i.e. that the redirect is to the
sign in page with any `next` parameter, not a specific `next` parameter.

1. 9111a7fc86/tests/app/utils/test_user.py (L130-L138)
2. 9111a7fc86/app/main/views/sign_in.py (L86)
2022-06-06 12:12:52 +01:00
Ben Thorner
1a7ecd85c9 Add tests for branding options conditional on name 2022-03-30 17:46:49 +01:00
Ben Thorner
15247bd780 Add missing test cases for default branding 2022-03-30 17:46:48 +01:00
Ben Thorner
3beb56be57 DRY-up tests by parametrizing on existing branding
This is possible now we're testing letters and emails separately.
I've added a few missing cases for NHS and non-central branding.
In the next commits we'll look at the remaining special cases.
2022-03-30 17:46:47 +01:00
Ben Thorner
330c23ad30 Remove excess tests for other org types
These all behave the same as each other so there's little value in
testing all of them - if we had 100 org types we wouldn't test them
all, but it's easy to get carried away when there are fewer.
2022-03-30 17:46:46 +01:00
Ben Thorner
e7d59263d1 Split out tests for letter and email branding
This also fills a gap where we weren't checking the central org
case for letters.
2022-03-30 17:46:45 +01:00
Ben Thorner
8f55972aae Split "get_available_choices" by branding type
We already had different functionality for email branding and will
soon be adding more for email branding pools.

Note that the "get_available_choices" class method was only used for
email branding - we can do it in the constructor for letters.
2022-03-30 17:46:39 +01:00
Ben Thorner
6e81d05504 Rename test values to clarify they're branding IDs
In response to: [^1]

[^1]: https://github.com/alphagov/notifications-admin/pull/4182#discussion_r832009706
2022-03-22 13:02:39 +00:00
Ben Thorner
acd69b8d7d Combine tests for central org email branding
Central orgs have more options than others, including the option
to revert back to GOV.UK once branding is set. Combining the tests
together should make that a bit clearer.
2022-03-15 12:10:13 +00:00
Ben Thorner
fa3e6435a6 Fix small issues identified in PR review
In response to: [^1], [^2], [^3], [^4], [^5] and [^6].

[^1]: https://github.com/alphagov/notifications-admin/pull/4182#discussion_r825824485
[^2]: https://github.com/alphagov/notifications-admin/pull/4182#discussion_r825824805
[^3]: https://github.com/alphagov/notifications-admin/pull/4182#discussion_r825857745
[^4]: https://github.com/alphagov/notifications-admin/pull/4182#discussion_r825859850
[^5]: https://github.com/alphagov/notifications-admin/pull/4182#discussion_r825859982
[^6]: https://github.com/alphagov/notifications-admin/pull/4182#discussion_r826001823
2022-03-15 11:47:21 +00:00
Ben Thorner
857b8b04b0 Duplicate tests for options with branding set
This is a step towards further refactoring of the page tests, which
don't need to check in this level of detail anymore.
2022-03-15 11:47:20 +00:00
Ben Thorner
5a39e310aa Migrate two more tests to the branding utility
All of the mock / UI assertions in these tests are covered by the
tests above them - these tests were mostly targetting which options
were being shown, which we can check at a lower level.
2022-03-15 11:47:19 +00:00
Ben Thorner
1946d3c928 Migrate two branding tests to utils module
This is much simpler than trying to test the function via the page,
although there are still two scenarios to test there:

- The page with radio buttons (using NHS as an example).
- The page with a text form (using "other" as an example).

In future work we could split this test in two to make it clearer
what it's trying to test. For now, this keeps the diff simple.
2022-03-15 11:47:18 +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
Chris Hill-Scott
07318b2d11 Replace instances of client.login with client_request
We have a `client_request` fixture which does a bunch of useful stuff
like:
- checking the status code of the response
- returning a `BeautifulSoup` object

Lots of our tests still use an older fixture called `client`. This is
not as good because it:
- returns a raw `Response` object
- doesn’t do the additional checks
- means our tests contain a lot of repetetive boilerplate like `page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')`

This commit converts all the tests which had a `client.login(…)`
statement to use `client_request` (which is already logged in by
default).

Subsequent commits will remove uses of `client` in other tests, but
doing it this way means the work can be broken up into more manageable
chunks.
2022-01-10 14:39:45 +00:00
Ben Thorner
4a5345f011 Move Spreadsheet models tests into own file
Previously this class was in app/utils.py, so it made sense for the
tests to be in "utils/test_csv.py". Since the class is now a proper
model [1], we can also move the tests into their own file.

[1]: 2c46d023da (diff-ac7b8d56e509c921efaadb5a776e1c9037531c4d2af78787f06f67a1f3533ae4)
2021-12-03 17:17:15 +00:00
Ben Thorner
dcfff87cc0 Continue to remove "roles" terminology
This renames the two functions we have to translate between UI and
DB permissions, as well as some of their associated variables to
make it clearer which kind of permission they contain.
2021-07-28 12:37:17 +01:00