Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script for validating redirects #6023

Merged
merged 2 commits into from
Sep 22, 2020
Merged

Conversation

chosak
Copy link
Member

@chosak chosak commented Sep 22, 2020

This new script allows for validation of a set of redirects as defined in a CSV or XLSX file. The first line of the file will be ignored as headers. The "from" and "to" paths default to being read from the 6th and 7th column of the input file, respectively.

To run against www.consumerfinance.gov, using an input XLSX:

cfgov/scripts/validate_redirects.py redirects.xlsx

To run against localhost, using an input CSV:

cfgov/scripts/validate_redirects.py redirects.csv http://localhost:8000

To specify alternate CSV columns for the "from" and "to" paths:

cfgov/scripts/validate_redirects.py redirects.xlsx --from-index=1 --to-index=2

How to test this PR

To test, run without one of the redirects and observe that the check fails. Now add the redirect and note that the check passes as long as it redirects to the correct path.

Checklist

  • PR has an informative and human-readable title
    • PR titles are used to generate the change log in releases; good ones make that easier to scan.
    • Consider prefixing, e.g., "Mega Menu: fix layout bug", or "Docs: Update Docker installation instructions".
  • Changes are limited to a single goal (no scope creep)
  • Code follows the standards laid out in the CFPB development guidelines

Copy link
Member

@wpears wpears left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks/works great overall, just a note about making this script more reusable.

cfgov/scripts/validate_redirects.py Outdated Show resolved Hide resolved
default='https://www.consumerfinance.gov',
nargs='?'
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the comment above, let's add arguments for the from and to indexes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent suggestion as always. Will do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wpears just added a commit that adds optional --from-index and --to-index parameters, for review at your convenience.

This new script allows for validation of a set of redirects as defined
in a CSV or XLSX file. The first line of the file will be ignored as
headers. The "from" and "to" paths must live in the 6th and 7th column
of the input file, respectively.

To run against www.consumerfinance.gov, using an input XLSX:

cfgov/scripts/validate_redirects.py redirects.xlsx

To run against localhost, using an input CSV:

cfgov/scripts/validate_redirects.py redirects.csv http://localhost:8000

To test, run without one of the redirects and observe that the check
fails. Now add the redirect and note that the check passes as long as it
redirects to the correct path.
@chosak chosak force-pushed the feature/validate-redirects-cmd branch from ae88224 to 901771f Compare September 22, 2020 18:22
Copy link
Member

@wpears wpears left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇 love it

@chosak chosak merged commit c150652 into main Sep 22, 2020
@chosak chosak deleted the feature/validate-redirects-cmd branch September 22, 2020 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants