Skip to content

Commit

Permalink
Merge pull request #311 from fecgov/release/sprint-42
Browse files Browse the repository at this point in the history
Release/sprint 42
  • Loading branch information
lbeaufort authored May 28, 2024
2 parents 4f12136 + bc24cb9 commit 537c6ab
Show file tree
Hide file tree
Showing 370 changed files with 3,471 additions and 275 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- run:
name: Run python tests, save a coverage report, and save coverage percentage
command: |
pytest --cov=. --cov-report=xml --cov-report=html:htmlcov_py --cov-report=term | tee pytest.out
python3 -m pytest --cov=. --cov-report=xml --cov-report=html:htmlcov_py --cov-report=term | tee pytest.out
export NEW_PYTHON_LINES=$(cat pytest.out | grep TOTAL | awk '{print $2}' | grep -oE "[0-9]+" )
export NEW_PYTHON_HITS=$(($NEW_PYTHON_LINES - $(cat pytest.out | grep TOTAL | awk '{print $3}' | grep -oE "[0-9]+" )))
export NEW_PYTHON_PERCENT=$(cat pytest.out | grep TOTAL | awk '{print $4}' | grep -oE "[0-9]+" )
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.pot
*.pyc
*.pyo
.venv/
build/
dist/
helloworld.db
Expand Down
98 changes: 60 additions & 38 deletions bin/schema-update-utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,36 @@ def encoder_override(obj):
if isinstance(obj, Decimal):
# We block out Decimals in | symbols so that we can
# clean them of their surrounding quotation marks later.
return '|'+str(obj)+'|'
return "|" + str(obj) + "|"

return json.JSONEncoder.default(obj)


def restore_decimal_values(json_string):
regex = re.compile(r'"\|(.*)\|"')
return regex.sub('\\1', json_string)
return regex.sub("\\1", json_string)


def process(file, schema):
print('*** ' + file)
print("*** " + file)

report_type = {
"title": "REPORT TYPE",
"description": "",
"type": "string",
"maxLength": 5,
"examples": ["F3X"],
"fec_spec": {
"FIELD_DESCRIPTION": "REPORT TYPE",
"TYPE": "A/N-100",
"REQUIRED": "X (error)",
"SAMPLE DATA": "F3X",
"VALUE REFERENCE": None,
"RULE REFERENCE": None,
"FIELD_FORM_ASSOCIATION": None,
},
}

# if 'filer_committee_id_number' in schema['properties']:
# schema['properties']['filer_committee_id_number']['pattern'] = \
# '^[C|P][0-9]{8}$|^[H|S][0-9]{1}[A-Z]{2}[0-9]{5}$'
Expand All @@ -41,47 +59,51 @@ def process(file, schema):
# for property_key in schema['properties'].keys():
# del schema['properties'][property_key]['fec_spec']['COL_SEQ']

properties = schema['properties']
conditionals = schema.get('allOf', [])
# properties = schema['properties']
# conditionals = schema.get('allOf', [])
changed = False

for property in properties.keys():
property_type = properties[property].get('type', [])
if property in schema.get('required', []):
if properties[property].get('minLength') == 0:
properties[property]['minLength'] = 1
changed = True

if isinstance(property_type, list):
if "null" in property_type:
properties[property]['type'] = "string"
changed = True

if "examples" in properties[property]:
examples = properties[property]["examples"]
if "none" in examples:
examples.remove("none")
changed = True

for condition in conditionals:
if property in condition['then'].get('required', []):
if property in condition['then']:
if condition['then'][property].get('minLength') == 0:
condition['then'][property]['minLength'] = 1
changed = True

if isinstance(property_type, list):
if "none" in property_type:
condition['then'][property]['type'] = 'string'
changed = True
if "report_type" in schema["properties"]:
schema["properties"]["report_type"] = report_type
schema["required"].pop(0)
changed = True

# for property in properties.keys():
# property_type = properties[property].get('type', [])
# if property in schema.get('required', []):
# if properties[property].get('minLength') == 0:
# properties[property]['minLength'] = 1
# changed = True

# if isinstance(property_type, list):
# if "null" in property_type:
# properties[property]['type'] = "string"
# changed = True

# if "examples" in properties[property]:
# examples = properties[property]["examples"]
# if "none" in examples:
# examples.remove("none")
# changed = True

# for condition in conditionals:
# if property in condition['then'].get('required', []):
# if property in condition['then']:
# if condition['then'][property].get('minLength') == 0:
# condition['then'][property]['minLength'] = 1
# changed = True

# if isinstance(property_type, list):
# if "none" in property_type:
# condition['then'][property]['type'] = 'string'
# changed = True

return [schema, changed]


exclude_file_list = [
]
exclude_file_list = []

for file in (glob.glob('*.json')):
for file in glob.glob("*.json"):

if file in exclude_file_list:
continue
Expand All @@ -93,7 +115,7 @@ def process(file, schema):
schema, changed = process(file, schema)

if changed:
f = open(file, 'w')
f = open(file, "w")

output = json.dumps(schema, indent=4, default=encoder_override)
cleaned_output = restore_decimal_values(output)
Expand Down
Loading

0 comments on commit 537c6ab

Please sign in to comment.