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

Feature/108 enhance validation rules op1 #109

Merged
merged 22 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
14d0e5f
Updates HDR Schema to better match requirements
Elaine-Krauss-TCG Aug 23, 2022
c2c8c5b
Updates to better fit requirements
Elaine-Krauss-TCG Aug 23, 2022
b3a641e
Tightens a regex:
Elaine-Krauss-TCG Aug 23, 2022
99b823d
Updates to validation rules
Elaine-Krauss-TCG Aug 24, 2022
05a99f1
Added HDR schema to documentation index.html file
mjtravers Aug 24, 2022
d4217a2
Decimal test actually checks for a decimal value, and a new test was …
Elaine-Krauss-TCG Aug 24, 2022
ef9f6d6
Expands unit tests
Elaine-Krauss-TCG Aug 24, 2022
bace755
Updates to better match requirements
Elaine-Krauss-TCG Aug 24, 2022
6b8cc10
Incorporates linting feedback
Elaine-Krauss-TCG Aug 24, 2022
3434445
Adds updated docs
Elaine-Krauss-TCG Aug 24, 2022
27de9eb
Corrects a typo
Elaine-Krauss-TCG Aug 24, 2022
838bd4a
Catches a few missed updates
Elaine-Krauss-TCG Aug 25, 2022
dcbd728
Updates docs
Elaine-Krauss-TCG Aug 25, 2022
0890032
Adds my repo patching tool. It updates the front-end's package file …
Elaine-Krauss-TCG Aug 25, 2022
419e95b
Tabs -> spaces and adjusts naming to match team standards
Elaine-Krauss-TCG Aug 25, 2022
2b5b2b2
More updates to linting
Elaine-Krauss-TCG Aug 25, 2022
0f5ebf4
More updates to linting
Elaine-Krauss-TCG Aug 25, 2022
94c4009
Renames repo patching tool and adds it to code coverage exclusion
Elaine-Krauss-TCG Aug 25, 2022
199599a
Adds repo patch tool to code coverage exclusion
Elaine-Krauss-TCG Aug 25, 2022
3106379
Removes a redundant return
Elaine-Krauss-TCG Aug 25, 2022
019ebb1
Updates committee ID pattern
Elaine-Krauss-TCG Aug 25, 2022
b486f86
Updates docs
Elaine-Krauss-TCG Aug 25, 2022
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
4 changes: 2 additions & 2 deletions bin/generate-schema-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Utility script to create the data dictionary *.html files
#
# NOTE: Be sure to run from the fecfile-Validate/schema directory
# NOTE: Be sure to run from the fecfile-validate/schema directory
#
SCHEMAS=$(ls -m *.json | tr -d '[:space:]')
generate-schema-doc ${SCHEMAS} ../docs
Expand All @@ -16,4 +16,4 @@ do
# call your procedure/other scripts here below
target_file="${schema%.*}_spec.html"
python ../bin/generate-spec-table.py $schema > ../docs/$target_file
done
done
199 changes: 199 additions & 0 deletions bin/patch-repos-with-validator-commit-hash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
import os
import sys
import time
import pkg_resources
from inspect import getsourcefile

FRONT_END_ROOT_DIR = "fecfile-web-app"
BACK_END_ROOT_DIR = "fecfile-web-api"
VALIDATOR_ROOT_DIR = "fecfile-validate"
FILE_PATH = os.path.abspath(getsourcefile(lambda: 0))
# Get the directory three steps above the directory containing this file
BASE_DIR = "/".join(FILE_PATH.split("/")[:-3])
YES_TO_ALL = False


def gitpython_is_installed():
installed_packages = pkg_resources.working_set
for package in installed_packages:
if package.key == "gitpython":
return True
return False


def get_commit_hash():
import git

os.chdir(BASE_DIR)
os.chdir(VALIDATOR_ROOT_DIR)

repo = git.Repo()
commit_hash = repo.head.object.hexsha

print("\nValidator Commit Hash:", commit_hash+"\n")
sleep(1)

return commit_hash


def patch_app(commit_hash):
os.chdir(BASE_DIR)
os.chdir(FRONT_END_ROOT_DIR)
os.chdir("front-end")

print("Patching package.json...")
sleep(0.5)

packages = open("package.json", "r")
package_lines = ""
for line in packages:
if "fecfile-validate" in line:
key, value = line.split(": ")
url = value.split("#")[0]
new_line = key+": "+url+"#"+commit_hash+'",\n'
package_lines += new_line
else:
package_lines += line

packages.close()
new_packages = open("package.json", "w")
new_packages.write(package_lines)
new_packages.close()

print("Done!\n")
sleep(0.5)


def patch_api(commit_hash):
os.chdir(BASE_DIR)
os.chdir(BACK_END_ROOT_DIR)

print("Patching requirements.txt...")
sleep(0.5)

new_requirements = ""
requirements_file = open("requirements.txt", "r")
for line in requirements_file:
if "fecfile-validate" in line:
url = line.split("@")[0]
parameters = line.split("#")[1]
new_line = url+"@"+commit_hash+"#"+parameters
new_requirements += new_line
else:
new_requirements += line

requirements_file.close()
new_requirements_file = open("requirements.txt", "w")
new_requirements_file.write(new_requirements)
new_requirements_file.close()

print("Done!\n")
sleep(0.5)


def delete_app_cache():
print("Deleting .angular & node_modules...")

os.chdir(BASE_DIR)
os.chdir(FRONT_END_ROOT_DIR)
os.chdir("front-end")
os.system("rm -r .angular")
os.system("rm -r node_modules")

print("Done!\nBe sure to run `npm install`\n")
sleep(0.5)


def delete_api_docker_images(docker_images):
print("Deleting .angular & node_modules...")
os.chdir(BASE_DIR)
os.chdir(BACK_END_ROOT_DIR)
print("Spinning down Docker...")
os.system("docker-compose down")
for image in docker_images:
print("Removing", image, "...")
os.system("docker rmi "+image)

print("Done!\nBe sure to run `docker-compose up`")
sleep(0.5)


def sleep(t):
if "-q" not in sys.argv:
time.sleep(t)


def ask_true_false(question):
if YES_TO_ALL:
return True

response = input(question+" (y/N): ")
if (len(response) == 0 or response.upper() not in ["Y", "YES"]):
return False
return True


def check_user_is_ready():
print("This script acts upon the active branches of the following repos:")
for repo in [FRONT_END_ROOT_DIR, BACK_END_ROOT_DIR, VALIDATOR_ROOT_DIR]:
padded_repo = repo+" "*(48-len(repo))
print(padded_repo+BASE_DIR+"/"+repo)
return ask_true_false("\nAre these directories correct?")


def help():
help_string = """
This script uses the active branch of your fecfile-validate repo to
update the validator commit hashes of your local app and api repos.
Optionally, it also deletes the .angular and node_modules directories
as well as the relevant docker images.

For this script to work, it needs to be placed in the directory
wherein each of the three repos can be found.

Command line arguments:
-y or --yes | auto-confirm all options
"""
print(help_string)


def main():
if "-h" in sys.argv or "--help" in sys.argv:
return help()
if "-y" in sys.argv or "--yes" in sys.argv:
global YES_TO_ALL
YES_TO_ALL = True

if not gitpython_is_installed():
print("Please install gitpython!")
print("python -m pip install gitpython")
return

if not check_user_is_ready():
return

commit_hash = get_commit_hash()
patch_app(commit_hash)
patch_api(commit_hash)

if ask_true_false(
"Would you like to delete the .angular and node_modules directories within " +
FRONT_END_ROOT_DIR
):
delete_app_cache()

docker_images = [
"fecfile-db",
"fecfile-api",
"fecfile-celery-worker",
"redis:6.2-alpine"
]
if ask_true_false(
"Would you like to delete the following docker images?\n" +
"\n".join(docker_images)+"\n"
):
delete_api_docker_images(docker_images)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion docs/BUS_LAB_NON_CONT_ACC.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
</pre></div> </div> </div> </div> </div> </div> <div class=accordion id=accordioncontribution_date> <div class=card> <div class=card-header id=headingcontribution_date> <h2 class=mb-0> <button class="btn btn-link property-name-button" type=button data-toggle=collapse data-target=#contribution_date aria-expanded aria-controls=contribution_date onclick="setAnchor('#contribution_date')"><span class=property-name>contribution_date</span> <span class="badge badge-warning required-property">Required</span></button> </h2> </div> <div id=contribution_date class="collapse property-definition-div" aria-labelledby=headingcontribution_date data-parent=#accordioncontribution_date> <div class="card-body pl-5"> <div class=breadcrumbs>root <svg width=1em height=1em viewbox="0 0 16 16" class="bi bi-arrow-right-short" fill=currentColor xmlns=http://www.w3.org/2000/svg> <path fill-rule=evenodd d="M4 8a.5.5 0 0 1 .5-.5h5.793L8.146 5.354a.5.5 0 1 1 .708-.708l3 3a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708-.708L10.293 8.5H4.5A.5.5 0 0 1 4 8z"/> </svg> <a href=#contribution_date onclick="anchorLink('contribution_date')">contribution_date</a></div><span class="badge badge-dark value-type">Type: string or null</span><br> <span class=pattern-value id=contribution_date_pattern>Must match regular expression: <code>^[0-9]{4}-[0-9]{2}-[0-9]{2}$</code></span> <br> <div class="badge badge-secondary">Example:</div> <br><div id=contribution_date_ex1 class="jumbotron examples"><div class=highlight><pre><span></span><span class=s2>&quot;2018-11-13&quot;</span><span class=w></span>
</pre></div> </div> </div> </div> </div> </div> <div class=accordion id=accordioncontribution_amount> <div class=card> <div class=card-header id=headingcontribution_amount> <h2 class=mb-0> <button class="btn btn-link property-name-button" type=button data-toggle=collapse data-target=#contribution_amount aria-expanded aria-controls=contribution_amount onclick="setAnchor('#contribution_amount')"><span class=property-name>contribution_amount</span> <span class="badge badge-warning required-property">Required</span></button> </h2> </div> <div id=contribution_amount class="collapse property-definition-div" aria-labelledby=headingcontribution_amount data-parent=#accordioncontribution_amount> <div class="card-body pl-5"> <div class=breadcrumbs>root <svg width=1em height=1em viewbox="0 0 16 16" class="bi bi-arrow-right-short" fill=currentColor xmlns=http://www.w3.org/2000/svg> <path fill-rule=evenodd d="M4 8a.5.5 0 0 1 .5-.5h5.793L8.146 5.354a.5.5 0 1 1 .708-.708l3 3a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708-.708L10.293 8.5H4.5A.5.5 0 0 1 4 8z"/> </svg> <a href=#contribution_amount onclick="anchorLink('contribution_amount')">contribution_amount</a></div><span class="badge badge-dark value-type">Type: number</span><br> <p><span class="badge badge-light restriction numeric-restriction" id=contribution_amount_number>Value must be greater or equal to <code>0</code> and lesser or equal to <code>999999999.99</code></span></p> <br> <div class="badge badge-secondary">Example:</div> <br><div id=contribution_amount_ex1 class="jumbotron examples"><div class=highlight><pre><span></span><span class=mf>250</span><span class=w></span>
</pre></div> </div> </div> </div> </div> </div> <div class=accordion id=accordioncontribution_aggregate> <div class=card> <div class=card-header id=headingcontribution_aggregate> <h2 class=mb-0> <button class="btn btn-link property-name-button" type=button data-toggle=collapse data-target=#contribution_aggregate aria-expanded aria-controls=contribution_aggregate onclick="setAnchor('#contribution_aggregate')"><span class=property-name>contribution_aggregate</span> <span class="badge badge-warning required-property">Required</span></button> </h2> </div> <div id=contribution_aggregate class="collapse property-definition-div" aria-labelledby=headingcontribution_aggregate data-parent=#accordioncontribution_aggregate> <div class="card-body pl-5"> <div class=breadcrumbs>root <svg width=1em height=1em viewbox="0 0 16 16" class="bi bi-arrow-right-short" fill=currentColor xmlns=http://www.w3.org/2000/svg> <path fill-rule=evenodd d="M4 8a.5.5 0 0 1 .5-.5h5.793L8.146 5.354a.5.5 0 1 1 .708-.708l3 3a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708-.708L10.293 8.5H4.5A.5.5 0 0 1 4 8z"/> </svg> <a href=#contribution_aggregate onclick="anchorLink('contribution_aggregate')">contribution_aggregate</a></div><span class="badge badge-dark value-type">Type: number</span><br> <p><span class="badge badge-light restriction numeric-restriction" id=contribution_aggregate_number>Value must be greater or equal to <code>0</code> and lesser or equal to <code>999999999.99</code></span></p> <br> <div class="badge badge-secondary">Example:</div> <br><div id=contribution_aggregate_ex1 class="jumbotron examples"><div class=highlight><pre><span></span><span class=mf>1000</span><span class=w></span>
</pre></div> </div> </div> </div> </div> </div> <div class=accordion id=accordioncontribution_purpose_descrip> <div class=card> <div class=card-header id=headingcontribution_purpose_descrip> <h2 class=mb-0> <button class="btn btn-link property-name-button" type=button data-toggle=collapse data-target=#contribution_purpose_descrip aria-expanded aria-controls=contribution_purpose_descrip onclick="setAnchor('#contribution_purpose_descrip')"><span class=property-name>contribution_purpose_descrip</span> <span class="badge badge-warning required-property">Required</span></button> </h2> </div> <div id=contribution_purpose_descrip class="collapse property-definition-div" aria-labelledby=headingcontribution_purpose_descrip data-parent=#accordioncontribution_purpose_descrip> <div class="card-body pl-5"> <div class=breadcrumbs>root <svg width=1em height=1em viewbox="0 0 16 16" class="bi bi-arrow-right-short" fill=currentColor xmlns=http://www.w3.org/2000/svg> <path fill-rule=evenodd d="M4 8a.5.5 0 0 1 .5-.5h5.793L8.146 5.354a.5.5 0 1 1 .708-.708l3 3a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708-.708L10.293 8.5H4.5A.5.5 0 0 1 4 8z"/> </svg> <a href=#contribution_purpose_descrip onclick="anchorLink('contribution_purpose_descrip')">contribution_purpose_descrip</a></div><span class="badge badge-dark value-type">Type: string</span><br> <span class=pattern-value id=contribution_purpose_descrip_pattern>Must match regular expression: <code>^[ -~]{0,100}$</code></span> <p><span class="badge badge-light restriction min-length-restriction" id=contribution_purpose_descrip_minLength>Must be at least <code>0</code> characters long</span></p><p><span class="badge badge-light restriction max-length-restriction" id=contribution_purpose_descrip_maxLength>Must be at most <code>100</code> characters long</span></p> </div> </div> </div> </div> <div class=accordion id=accordionmemo_code> <div class=card> <div class=card-header id=headingmemo_code> <h2 class=mb-0> <button class="btn btn-link property-name-button" type=button data-toggle=collapse data-target=#memo_code aria-expanded aria-controls=memo_code onclick="setAnchor('#memo_code')"><span class=property-name>memo_code</span></button> </h2> </div> <div id=memo_code class="collapse property-definition-div" aria-labelledby=headingmemo_code data-parent=#accordionmemo_code> <div class="card-body pl-5"> <div class=breadcrumbs>root <svg width=1em height=1em viewbox="0 0 16 16" class="bi bi-arrow-right-short" fill=currentColor xmlns=http://www.w3.org/2000/svg> <path fill-rule=evenodd d="M4 8a.5.5 0 0 1 .5-.5h5.793L8.146 5.354a.5.5 0 1 1 .708-.708l3 3a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708-.708L10.293 8.5H4.5A.5.5 0 0 1 4 8z"/> </svg> <a href=#memo_code onclick="anchorLink('memo_code')">memo_code</a></div><span class="badge badge-dark value-type">Type: boolean or null</span><br> </div> </div> </div> </div> <div class=accordion id=accordionmemo_text_description> <div class=card> <div class=card-header id=headingmemo_text_description> <h2 class=mb-0> <button class="btn btn-link property-name-button" type=button data-toggle=collapse data-target=#memo_text_description aria-expanded aria-controls=memo_text_description onclick="setAnchor('#memo_text_description')"><span class=property-name>memo_text_description</span></button> </h2> </div> <div id=memo_text_description class="collapse property-definition-div" aria-labelledby=headingmemo_text_description data-parent=#accordionmemo_text_description> <div class="card-body pl-5"> <div class=breadcrumbs>root <svg width=1em height=1em viewbox="0 0 16 16" class="bi bi-arrow-right-short" fill=currentColor xmlns=http://www.w3.org/2000/svg> <path fill-rule=evenodd d="M4 8a.5.5 0 0 1 .5-.5h5.793L8.146 5.354a.5.5 0 1 1 .708-.708l3 3a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708-.708L10.293 8.5H4.5A.5.5 0 0 1 4 8z"/> </svg> <a href=#memo_text_description onclick="anchorLink('memo_text_description')">memo_text_description</a></div><span class="badge badge-dark value-type">Type: string or null</span><br> <span class=pattern-value id=memo_text_description_pattern>Must match regular expression: <code>^[ -~]{0,100}$</code></span> </div> </div> </div> </div> <footer> <p class=generated-by-footer>Generated using <a href=https://github.com/coveooss/json-schema-for-humans>json-schema-for-humans</a> on 2022-08-12 at 13:02:15 -0400</p> </footer></body> </html>
</pre></div> </div> </div> </div> </div> </div> <div class=accordion id=accordioncontribution_purpose_descrip> <div class=card> <div class=card-header id=headingcontribution_purpose_descrip> <h2 class=mb-0> <button class="btn btn-link property-name-button" type=button data-toggle=collapse data-target=#contribution_purpose_descrip aria-expanded aria-controls=contribution_purpose_descrip onclick="setAnchor('#contribution_purpose_descrip')"><span class=property-name>contribution_purpose_descrip</span> <span class="badge badge-warning required-property">Required</span></button> </h2> </div> <div id=contribution_purpose_descrip class="collapse property-definition-div" aria-labelledby=headingcontribution_purpose_descrip data-parent=#accordioncontribution_purpose_descrip> <div class="card-body pl-5"> <div class=breadcrumbs>root <svg width=1em height=1em viewbox="0 0 16 16" class="bi bi-arrow-right-short" fill=currentColor xmlns=http://www.w3.org/2000/svg> <path fill-rule=evenodd d="M4 8a.5.5 0 0 1 .5-.5h5.793L8.146 5.354a.5.5 0 1 1 .708-.708l3 3a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708-.708L10.293 8.5H4.5A.5.5 0 0 1 4 8z"/> </svg> <a href=#contribution_purpose_descrip onclick="anchorLink('contribution_purpose_descrip')">contribution_purpose_descrip</a></div><span class="badge badge-dark value-type">Type: string</span><br> <span class=pattern-value id=contribution_purpose_descrip_pattern>Must match regular expression: <code>^[ -~]{0,100}$</code></span> <p><span class="badge badge-light restriction min-length-restriction" id=contribution_purpose_descrip_minLength>Must be at least <code>0</code> characters long</span></p><p><span class="badge badge-light restriction max-length-restriction" id=contribution_purpose_descrip_maxLength>Must be at most <code>100</code> characters long</span></p> </div> </div> </div> </div> <div class=accordion id=accordionmemo_code> <div class=card> <div class=card-header id=headingmemo_code> <h2 class=mb-0> <button class="btn btn-link property-name-button" type=button data-toggle=collapse data-target=#memo_code aria-expanded aria-controls=memo_code onclick="setAnchor('#memo_code')"><span class=property-name>memo_code</span></button> </h2> </div> <div id=memo_code class="collapse property-definition-div" aria-labelledby=headingmemo_code data-parent=#accordionmemo_code> <div class="card-body pl-5"> <div class=breadcrumbs>root <svg width=1em height=1em viewbox="0 0 16 16" class="bi bi-arrow-right-short" fill=currentColor xmlns=http://www.w3.org/2000/svg> <path fill-rule=evenodd d="M4 8a.5.5 0 0 1 .5-.5h5.793L8.146 5.354a.5.5 0 1 1 .708-.708l3 3a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708-.708L10.293 8.5H4.5A.5.5 0 0 1 4 8z"/> </svg> <a href=#memo_code onclick="anchorLink('memo_code')">memo_code</a></div><span class="badge badge-dark value-type">Type: boolean or null</span><br> </div> </div> </div> </div> <div class=accordion id=accordionmemo_text_description> <div class=card> <div class=card-header id=headingmemo_text_description> <h2 class=mb-0> <button class="btn btn-link property-name-button" type=button data-toggle=collapse data-target=#memo_text_description aria-expanded aria-controls=memo_text_description onclick="setAnchor('#memo_text_description')"><span class=property-name>memo_text_description</span></button> </h2> </div> <div id=memo_text_description class="collapse property-definition-div" aria-labelledby=headingmemo_text_description data-parent=#accordionmemo_text_description> <div class="card-body pl-5"> <div class=breadcrumbs>root <svg width=1em height=1em viewbox="0 0 16 16" class="bi bi-arrow-right-short" fill=currentColor xmlns=http://www.w3.org/2000/svg> <path fill-rule=evenodd d="M4 8a.5.5 0 0 1 .5-.5h5.793L8.146 5.354a.5.5 0 1 1 .708-.708l3 3a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708-.708L10.293 8.5H4.5A.5.5 0 0 1 4 8z"/> </svg> <a href=#memo_text_description onclick="anchorLink('memo_text_description')">memo_text_description</a></div><span class="badge badge-dark value-type">Type: string or null</span><br> <span class=pattern-value id=memo_text_description_pattern>Must match regular expression: <code>^[ -~]{0,100}$</code></span> </div> </div> </div> </div> <footer> <p class=generated-by-footer>Generated using <a href=https://github.com/coveooss/json-schema-for-humans>json-schema-for-humans</a> on 2022-08-25 at 12:35:29 -0400</p> </footer></body> </html>
Loading