Validations - Gary-Community-Ventures/benefits-api GitHub Wiki
Validations
Validations are how MFB detects changes to a program. When testing a program, if a program is displaying the correct eligibility and value, the admin can mark that program as a validation. If the value of that program changes in the future, then you would be notified about it when you run the validate
command.
Admin
Accessing the admin view:
To access the admin view add ?admin=true
to the end of the url on any results page. This will do the following of things:
- Show all programs regardless of eligibility.
- Show the validations associated with that screen.
- Add a login box that the admin can use to mark validations.
Example: https://screener.myfriendben.org/e9e2a906-d689-4198-a37f-78ef703d9c0f/results/benefits?admin=true
Login
To login, enter your email and password used in the Django admin.
The user must be a staff user to create or delete validations
You must log in every time you visit the admin page. If the login box does not say "You are logged in", than you are not logged in.
Creating a validation
To create a validations follow these steps:
- Create a screen you want to test a program for.
- Go to the admin view on the results page.
- Login.
- Click "More Info" on the program that you want to validate.
- If the value is correct, click the "Create Validation" button.
The screen must be marked as a test to create a validation
Remove a validation
To remove a validation, click "Remove Validation" on the program page (the same button used to create the validation).
Sometimes a change in value is expected. To mark a validation as such, remove the validation, and then add it again.
What things mean
The banner that says "This screen is frozen. Changes you make will not be saved." means that if you go back and edit the screen, than those changes will not be reflected in the results, and will be reverted if you refresh the page. This is to prevent the situation where someone creates a validation, and then someone edits the screen resulting in a different results value.
The green highlighted program boxes mean that a validation passed, while the red highlighted program box means that the validation failed.
The validations category is all of the validations for that screen.
The "Estimated Savings" (and "Estimated Annual Value" on the program page) on the validations follows this structure:
[old_value] => [new_value]
old_value
: the value when the validation was creatednew_value
: the value right now
Scripts
Run validations
To check if any of the validations have changes run the following script python manage.py validate
The output is structured like:
[url] [external_name] [old_value] => [new_value]
url
: a url taking you to the program page of the validated program (make sure to configure theFRONTEND_DOMAIN
environment variable)external_name
: theexternal_name
on the program modelold_value
: the value when the validation was creatednew_value
: the value right now
Skipped means that the program is not active in this environment
There are a couple of flags available:
-p
or--program
: run the validations for a specific program--hide-skipped
: don't display the skipped programs-s
or--sheet-id
: Add results to a Google sheet
To use the Google Sheets integration:
- Share the spreadsheet you want the integration to use with your Google Service account.
- Run the validate command with
-s
set to the spreadsheet id. - View the validations in the Google Sheet.
Pull validations form another environment
You may want to get the validations from the production environment on your development environment this can be done with python manage.py pull_validations [domain_of_environment]
The domain_of_environment
is the same domain of the Django admin in the environment that you want to pull from (remove the trailing slash).
You will be prompted for a API Key:
. The API key can be any token that has access to the screen endpoint in the environment you are pulling from.
Notes:
- Screens will be updated when a screen is pulled that already exists.
- If there are multiple validations on a screen, than they will be attached to the same screen in the local environment.
- It might fail, if the environments are different versions.
Brief technical overview
- All validation logic is in the validations app
- Validations are stored using the model in validation/models.py
- The code for the scripts is located in validations/management/commands