Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ A set of developer tools in the form of management commands.

### API

There is an api now available at `/wagtail-devtools-api/` which will list all available commands.
There is an api available at `/wagtail-devtools-api/` which will list all available endpoints.

- List all editor listing pages
- List all editor edit pages

### Admin Responses

The `admin_responses` command will make a requests to the admin interface using get requests for a range of models. It will write a response result to the console.
The `admin_responses` command will use the API endpoints above to create a report of error and success pages in the console.

- [Documentation](docs/admin_responses.md)

Expand Down
186 changes: 32 additions & 154 deletions docs/admin_responses.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,172 +4,50 @@ The `admin_responses` command will make a requests to the admin interface using

**Note:** As the command makes requests to the admin interface it will need a local development site to be running in `DEBUG` mode. It will work best if you have a full set of test data for all models.

Reports can be generated for:
Reports are generated for:

- Admin Listing and Edit pages
- Frontend Pages

You can also add admin reports covering:

- Snippets
- Settings
- ModelAdmin
- Pages
- and more...

## Usage

Create a command class in your app's `management/commands` directory thats inherits from `BaseAdminResponsesCommand` with the following content:

```python
from wagtail_devtools.management.commands._base_admin_responses import (
BaseAdminResponsesCommand,
)


class Command(BaseAdminResponsesCommand):
def get_reports(self, *args, **options):
session = self._log_in(options)

register_reports = [
# Add your reports here
]
```

You can use any name for the command file, but it must be in a `management/commands` directory.

I'll use `report_responses.py` as an example.

**Note:** A full command that uses all available checks can be found in the [cmd_test_admin_responses.py](../wagtail_devtools/test/management/commands/cmd_test_admin_responses.py) file which you can use as a quick start.

### Page Models Report

Will generate a report for all admin edit pages for all page type models and corresponding frontend pages.

It does this by automatically finding all page models, then using a get request it will check the response status code for the admin edit page and the frontend page.

#### Setup

Add the following item to the `register_reports` list:

```python
{
"function": self.report_pages,
"args": [session, options],
}
```bash
python manage.py admin_responses
```

- `function` is the function that will be called to generate the report.
- `args` is a list of arguments that will need to be passed to the function.
- `session` is the session object that will be used to make the requests.
- `options` is the commands options object that is passed to the command.

#### Example Console Output
### Example Console Output

![Page Model Report](./assets/pages-output.jpg)

If your terminal allows it the links should be clickable.

Any pages that return a response code other than 200 will be highlighted in red.

### Admin Listing Pages Report

Will generate a report for all admin listing pages.

```python
{
"function": self.report_admin_list_pages,
"args": [
session,
"Dashboard",
f"{options['host']}{reverse('wagtailadmin_home')}",
],
}
```

It does this by making a get request to the specified admin listing page and checking the response status code.

- `function` is the function that will be called to generate the report.
- `args` is a list of arguments that will need to be passed to the function.
- `session` is the session object that will be used to make the requests.
- `Dashboard` is the title of the report.
- `f"{options['host']}{reverse('wagtailadmin_home')}"` is the url of the admin listing page to check.

#### Other admin listing page reports

You can also generate reports for other admin listing pages. Use the following wagtail urls as the third argument and a title of the report as the second argument:

- Aging Pages: `f"{options['host']}{reverse('wagtailadmin_reports:aging_pages')}"`
- Collections: `f"{options['host']}{reverse('wagtailadmin_collections:index')}"`
- Dashboard: `f"{options['host']}{reverse('wagtailadmin_home')}"`
- Documents: `f"{options['host']}{reverse('wagtaildocs:index')}"`
- Groups: `f"{options['host']}{reverse('wagtailusers_groups:index')}"`
- Images: `f"{options['host']}{reverse('wagtailimages:index')}"`
- Locked Pages: `f"{options['host']}{reverse('wagtailadmin_reports:locked_pages')}"`
- Redirects: `f"{options['host']}{reverse('wagtailredirects:index')}"`
- Search: `f"{options['host']}{reverse('wagtailadmin_explore_root')}"`
- Site History: `f"{options['host']}{reverse('wagtailadmin_reports:site_history')}"`
- Sites: `f"{options['host']}{reverse('wagtailsites:index')}"`
- Snippets: `f"{options['host']}{reverse('wagtailsnippets:index')}"`
- Users: `f"{options['host']}{reverse('wagtailusers_users:index')}"`
- Workflow List: `f"{options['host']}{reverse('wagtailadmin_workflows:index')}"`
- Workflow Tasks: `f"{options['host']}{reverse('wagtailadmin_workflows:task_index')}"`

### Admin Model Edit Pages Report

Will generate a report for the admin edit page using the specified app and model.

It does this by making a get request to the corresponding admin edit page for the model and checking the response status code.

```python
{
"function": self.report_admin_app_model,
"args": [
session,
options,
"WORKFLOWS EDIT",
"wagtailcore",
"Workflow",
],
},
```

- `function` is the function that will be called to generate the report.
- `args` is a list of arguments that will need to be passed to the function.
- `session` is the session object that will be used to make the requests.
- `options` is the commands options object that is passed to the command.
- `WORKFLOWS EDIT` is the title of the report.
- `wagtailcore` is the app name.
- `Workflow` is the model name.

#### Other admin app.model reports

You can also generate reports for edit pages for other models:

- Documents: `report_documents`
- Images: `report_images`
- Users: `report_users`
- Groups: `report_groups`
- Sites: `report_sites`
- Collections: `report_collections`
- Snippets: `report_snippets`


### ModelAdmin Reports

Will generate a report for the admin edit page using the specified modeladmin models.

It does this by making a get request to the corresponding admin edit page for the model and checking the response status code.

```python
{
"function": self.report_model_admin,
"args": [session, options, ["app.Model"]],
}
```

- `function` is the function that will be called to generate the report.
- `args` is a list of arguments that will need to be passed to the function.
- `session` is the session object that will be used to make the requests.
- `options` is the commands options object that is passed to the command.
- `["app.Model"]` is a list of registered modeladmin app.model strings.
#### Listing Page Checks

- Aging Pages: `wagtailadmin_reports:aging_pages`
- Collections: `wagtailadmin_collections:index`
- Dashboard: `wagtailadmin_home`
- Documents: `wagtaildocs:index`
- Groups: `wagtailusers_groups:index`
- Images: `wagtailimages:index`
- Locked Pages: `wagtailadmin_reports:locked_pages`
- Redirects: `wagtailredirects:index`
- Search: `wagtailadmin_explore_root`
- Site History: `wagtailadmin_reports:site_history`
- Sites: `wagtailsites:index`
- Snippets: `wagtailsnippets:index`
- Users: `wagtailusers_users:index`
- Workflow List: `wagtailadmin_workflows:index`
- Workflow Tasks: `wagtailadmin_workflows:task_index`

### Edit Page Checks

- Documents
- Images
- Users
- Groups
- Sites
- Collections
- Snippets
- ModelAdmin Models
10 changes: 0 additions & 10 deletions wagtail_devtools/api/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,6 @@
"app_name": None,
"listing_name": "wagtailusers_groups:index",
},
{
"title": "Example Calendar (admin view)",
"app_name": None,
"listing_name": "calendar",
},
{
"title": "Example Calendar (admin view - month)",
"app_name": None,
"listing_name": "calendar-month",
},
]


Expand Down
38 changes: 38 additions & 0 deletions wagtail_devtools/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import requests


class LoginHandler:
def __init__(self, url):
self.url = url
self._is_authenticated = False
self.login_url = f"{self.url}/admin/login/"
self.session = requests.Session()

def login(self, username, password):
login_form = self.session.get(self.login_url)
if login_form.status_code == 404:
raise Exception("Login page not found")

user = {
"username": username,
"password": password,
"csrfmiddlewaretoken": login_form.cookies["csrftoken"],
}
response = self.session.post(self.login_url, data=user)
if response.status_code == 200:
self._is_authenticated = True
return self

def logout(self):
self._is_authenticated = False
self.session = requests.Session()
return self

def get_response(self, url):
# a request that can be used to make authenticated requests
# for accessing the wagtail admin pages
response = self.session.get(url)
return response

def is_authenticated(self):
return self._is_authenticated
Loading