Skip to content

Commit

Permalink
Merge pull request #53 from fecgov/feature/61-contact-pages
Browse files Browse the repository at this point in the history
Converted contact type and candidate type to code values
  • Loading branch information
mjtravers authored Mar 18, 2022
2 parents a2088fe + 596467e commit 7552a61
Show file tree
Hide file tree
Showing 11 changed files with 1,146 additions and 1,283 deletions.
18 changes: 9 additions & 9 deletions docs/Contact_Candidate.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/Contact_Committee.html

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions docs/Contact_Individual.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/Contact_Organization.html

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion fecfile_validate_python/src/fecfile_validate/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def get_schema(schema_name):
Returns:
dict: JSON schema that matches the schema_name"""
schema_file = f"{schema_name}.json"
schema_path = os.path.join(os.path.dirname(__file__), "schema/", schema_file)
schema_path = os.path.join(os.path.dirname(__file__), "schema/",
schema_file)
#: Handle case where we are not running from a pip package
if not os.path.isfile(schema_path):
logger.warning(f"Schema file ({schema_path}) not found in package.")
Expand Down
23 changes: 23 additions & 0 deletions fecfile_validate_python/tests/sample_IND_contact.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"type": "IND",
"candidate_id": null,
"committee_id": "C00601211",
"name": "Gilbert Smith",
"last_name": "Smith",
"first_name": "Gilbert",
"middle_name": null,
"prefix": null,
"suffix": null,
"street_1": "602 Tlumacki St",
"street_2": null,
"city": "Mclean City",
"state": "VA",
"zip": "22204",
"employer": "Byron Inc",
"occupation": "Business Owner",
"candidate_office": "P",
"candidate_state": null,
"candidate_district": null,
"telephone": "3043892120",
"country": "US"
}
25 changes: 24 additions & 1 deletion fecfile_validate_python/tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@ def sample_f3x():
return form_data


@pytest.fixture
def sample_ind_contact():
with open(os.path.join(os.path.dirname(__file__),
"sample_IND_contact.json")) as f:
form_data = json.load(f)
return form_data


@pytest.fixture
def test_schema():
with open(os.path.join(os.path.dirname(__file__), "test_schema.json")) as f:
with open(os.path.join(os.path.dirname(__file__),
"test_schema.json")) as f:
schema = json.load(f)
return schema

Expand Down Expand Up @@ -86,3 +95,17 @@ def test_parse_required_error(test_schema):
"'nested_field' is a required property",
"top_level_field.nested_field",
)


def test_invalid_const_value(sample_ind_contact):
# Make sure our Individual Contact schema is valid
validation_result = validate.validate("Contact_Individual",
sample_ind_contact)
assert validation_result.errors == []

# Check the const type property works by setting an invalid "type" property
sample_ind_contact["type"] = "Individual"
validation_result = validate.validate("Contact_Individual",
sample_ind_contact)
assert validation_result.errors[0].path == "type"
assert validation_result.errors[0].message == "'IND' was expected"
Loading

0 comments on commit 7552a61

Please sign in to comment.