Commit Graph

12691 Commits

Author SHA1 Message Date
Jim Moffet
b07ad873e8 Merge branch 'main' into jim/063022/protectbeta 2022-07-19 18:35:21 -07:00
Jim Moffet
4a6d3fee2d Merge pull request #12 from 18F/jim/071922/cachecomment
comment cache decorator
2022-07-19 18:32:28 -07:00
James Moffet
f1d9aef9cd comment cache decorator 2022-07-19 18:31:01 -07:00
James Moffet
50e660a73f devcontainer config 2022-07-19 18:23:48 -07:00
Jim Moffet
845ecdd17f Merge pull request #11 from 18F/jim/071522/adminupdates
configs etc...
2022-07-19 17:33:39 -07:00
James Moffet
6ad5cefe30 minor configs 2022-07-15 13:53:48 -05:00
James Moffet
d2052f136f configs etc... 2022-07-15 13:25:35 -05:00
Jim Moffet
b932294a9c formatting 2022-07-01 11:49:31 -07:00
Jim Moffet
8e9be686d2 clean obsolete import 2022-07-01 11:48:17 -07:00
Jim Moffet
522ed32a01 clean obsolete import 2022-07-01 11:47:44 -07:00
Jim Moffet
b5e2b67576 clean obsolete import 2022-07-01 11:38:19 -07:00
Jim Moffet
4001332741 clean comments 2022-07-01 11:36:47 -07:00
Jim Moffet
b8d5a0b5eb clean comments 2022-07-01 11:36:15 -07:00
Jim Moffet
e9a3b3d5e3 move CustomBasicAuth override to import 2022-07-01 11:34:51 -07:00
Jim Moffet
f8f87e0596 ignore local log file 2022-07-01 11:24:51 -07:00
Jim Moffet
8fa0af523b delete local log file 2022-07-01 11:24:25 -07:00
Jim Moffet
1c5d432427 clean up and turn off auth for test env 2022-07-01 11:19:58 -07:00
Jim Moffet
1e979ad519 fix basic auth for live environment 2022-07-01 07:58:58 -07:00
Jim Moffet
509cce38f4 set up basicauth config to protect staging site 2022-06-30 17:05:42 -07:00
Christa Hartsock
6d3f67fb9b Initial config for local deployments
Not yet working properly on cloud.gov
2022-06-23 15:53:23 -07:00
Jim Moffet
2a918dbe98 Merge pull request #5 from 18F/jim/061522/registration-mods
config buckets
2022-06-23 14:09:22 -07:00
Jim Moffet
e17c26d1f6 config buckets 2022-06-23 14:08:29 -07:00
Jim Moffet
28df5fec65 Merge pull request #3 from 18F/local-dev-upgrades
local dev upgrades
2022-06-17 14:05:07 -07:00
Jim Moffet
ddd13b9995 disable cache persistence & env updates 2022-06-13 21:41:59 -07:00
Jim Moffet
c88d6f7a6b sample env 2022-06-13 14:42:50 -07:00
Jim Moffet
18eefc87c0 clean makefile 2022-06-13 14:31:51 -07:00
Jim Moffet
2b727e13b4 local dev upgrades 2022-06-13 14:26:46 -07:00
Ben Thorner
543be77776 Merge pull request #4258 from alphagov/speed-up-templates-page-179736794
Optimise load time for service "Templates" page
2022-06-08 13:37:58 +01:00
Chris Hill-Scott
f52a8c56d7 Merge pull request #4265 from alphagov/fix-service-url-support-ticket
Fix relative URLs appearing in support tickets
2022-06-08 09:46:59 +01:00
Chris Hill-Scott
b91babc67e Fix relative URLs in support tickets
When we get a support ticket we put a link to the service at the end.

As part of 8b7f2fbf04 we accidentally made
these URLs relative, rather than absolute. This means they aren’t made
into links by email clients or Zendesk.

This commit fixes the links to include the domain again.
2022-06-07 13:50:24 +01:00
Chris Hill-Scott
197e98d891 Refactor support ticket into a template
This is the same thing we do for go live requests and branding requests.

It’s easier to do templating logic in a templating language than in
Python.
2022-06-07 13:50:24 +01:00
Ben Thorner
5b52aa2381 Simplify test setup for Template List model 2022-06-07 11:31:10 +01:00
Ben Thorner
5db2581669 Simplify tests for TemplateList class
In response to: [^1][^2][^3].

Originally there were three tests:

- One was testing the "get_user_template_folders" method directly.

- The other two were testing "get_template_folders", which calls
the "_user_" method if a user is passed - this is what the tests
were primarily checking, by passing or not passing a User object.

The two tests of "get_template_folders" also implicitly checked
that it filtered folders based on a "parent_folder_id". I wanted
to emulate the tests but it makes more sense to simplify them, as
the methods are now only used by TemplateList internally.

To simplify, we just keep just two tests to check that the overall
set of folders is filtered based on the presence of a User. We do
lose the implicit check of filtering by "parent_folder_id", but:

- We are still checking this implicitly in the sense that the loop
to generate the overall set of folders terminates. If the method
didn't do any filtering, the loop would be infinite.

- We need to acknowledge that these tests were incomplete to begin
with. There is also lots of coverage in higher level tests [^4],
although it's harder to reason exactly what is covered.

[^1]: https://github.com/alphagov/notifications-admin/pull/4258#discussion_r890144076
[^2]: https://github.com/alphagov/notifications-admin/pull/4258#discussion_r890151220
[^3]: https://github.com/alphagov/notifications-admin/pull/4258#discussion_r890147506
[^4]: 1787f9f42f/tests/app/main/views/test_template_folders.py
2022-06-07 11:31:09 +01:00
Ben Thorner
1c4a2b4790 Cache templates and folders in TemplateList
This gives us the performance gains identified in [^1] for the test
service described in the spike:

- user_template_folders - from 10s to a little above 3s on its own

- get_templates_and_folders - from 10s to below 6s on its own

In combination, these two uses of caching reduce the test page load
time from 10s to a little above 3s. This is slightly higher than in
the spike PR due to all the extra work we're doing to generate the
"move to" list of folders, as described in a previous commit.

The render time is unchanged for services with few folders. We start
to see the benefit of this change at around 200 templates + folders,
with no evidence that any service will experience worse render times,
despite the extra work we're doing from previous commits.

[^1]: https://github.com/alphagov/notifications-admin/pull/4251
2022-06-07 11:05:36 +01:00
Ben Thorner
2771ae1274 Remove redundant user param from template methods
This will finally make it possible to cache some of the methods.
2022-06-07 11:05:35 +01:00
Ben Thorner
9126c8ca5e Move _template_ methods to TemplateList class
This is a straight move with a few minor tweaks:

- Some references to self.X in the code from Service now need to
become self.service.X.

- Some reference to self.service.Y in TemplateList can now become
self.Y for the methods that were migrated.

The remaining _template_ methods in Service are still called from
multiple places and there's no performance gain to motivate moving
them out of the Service class, which is now a more manageable size.
2022-06-07 11:05:34 +01:00
Ben Thorner
bcfc6ce707 Decouple deletion tests from "get_templates" fn
Using create_template here is easier than template_json as it has
various parameters preset [^1].

[^1]: https://github.com/alphagov/notifications-admin/blob/master/tests/conftest.py#L3986
2022-06-07 11:05:33 +01:00
Ben Thorner
487dc1b488 Test _template_folders functions via TemplateList
This is part of the overall migration of the "_template_folders"
methods to the TemplateList class. Moving the existing tests now
will make the actual migration easier to follow.

To emulate the second and third tests, we need to grab a specific
folder from the TemplateList and then look at its folders - these
are set based on "get_template_folders" as before.
2022-06-07 11:05:30 +01:00
Ben Thorner
057b4ee7a5 Simplify tests for get_(user)_template_folders
This will make it easier to understand the diff when we move these
tests to operate via TemplateList. Despite the verbosity, the only
attribute we were actually checking here was the name, as a way of
identifying which folders had been returned.

Looking at the three tests:

1. The first is checking we can correctly filter all folders that a
user can access, which involves appending the names of any parent
folders the user doesn't have direct access to.

2. The second is checking the same thing but also that we filter the
set of folders to just the children of a parent.

3. The third is just checking the filtering of child folders, without
any user filtering or name aggregation applied.

I've adapted tests (2) and (3) to make it clearer what is tested,
focussing the tests on a specific folder and its contents.
2022-06-07 10:44:35 +01:00
Ben Thorner
b97bf19b45 Make creating TemplateListServices consistent
TemplateListServices are used when we want to show the service
as an additional layer of hierarchy when a user copies a template,
potentially across services [^1].

Normally a TemplateFolder is given "folders" and "templates" by
TemplateList [^2]; TemplateListService was doing it the other
way round and getting its own instead.

Using a subclass of TemplateList means we can make the approach
consistent, which will support the caching approach later on, as
well as simplifying how we work with templates and folders.

[^1]: 2e637f801f/app/main/views/templates.py (L356)
[^2]: bef0382cca/app/models/template_list.py (L31-L36)
2022-06-07 10:43:30 +01:00
Chris Hill-Scott
1787f9f42f Merge pull request #4261 from alphagov/refactor-permissions-tests
Refactor permissions tests
2022-06-06 16:05:04 +01: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