Skip to content

Commit

Permalink
Merge pull request #56 from fecgov/release/sprint-5
Browse files Browse the repository at this point in the history
Release/sprint 5
  • Loading branch information
toddlees authored Mar 25, 2022
2 parents b040569 + 7552a61 commit f205c83
Show file tree
Hide file tree
Showing 64 changed files with 6,035 additions and 2,672 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.

2 changes: 1 addition & 1 deletion fecfile_validate_python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ To install with pip:
`pip install "git+https://github.com/fecgov/fecfile-validate@main#egg=fecfile_validate&subdirectory=fecfile_validate_python"`

To include in requirements.txt add this line:
`git+https://github.com/fecgov/fecfile-validate@min#egg=fecfile_validate&subdirectory=fecfile_validate_python`
`git+https://github.com/fecgov/fecfile-validate@main#egg=fecfile_validate&subdirectory=fecfile_validate_python`

# Example

Expand Down
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"
}
31 changes: 30 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 @@ -46,6 +55,12 @@ def test_invalid_string_character(sample_f3x):
assert validation_result.errors[0].message == message_match


def test_non_required_field(sample_f3x):
sample_f3x["treasurer_middle_name"] = None
validation_result = validate.validate("F3X", sample_f3x)
assert validation_result.errors == []


def check_error(validation_error, message, path):
expected_error = validate.ValidationError(message, path)
assert validation_error.path == expected_error.path
Expand Down Expand Up @@ -80,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"
88 changes: 66 additions & 22 deletions schema/BUS_LAB_NON_CONT_ACC.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"minLength": 0,
"maxLength": 8,
"pattern": "^[ A-Za-z0-9]{0,8}$",
"examples": ["SA11AI"],
"examples": [
"SA11AI"
],
"fec_spec": {
"COL_SEQ": 1,
"FIELD_DESCRIPTION": "FORM TYPE",
Expand All @@ -49,7 +51,9 @@
"minLength": 0,
"maxLength": 9,
"pattern": "^[ A-Za-z0-9]{0,9}$",
"examples": ["C00123456"],
"examples": [
"C00123456"
],
"fec_spec": {
"COL_SEQ": 2,
"FIELD_DESCRIPTION": "FILER COMMITTEE ID NUMBER",
Expand All @@ -68,7 +72,9 @@
"minLength": 0,
"maxLength": 12,
"pattern": "^[ A-Za-z0-9]{0,12}$",
"examples": ["BUS_LAB_CAREY"],
"examples": [
"BUS_LAB_CAREY"
],
"fec_spec": {
"COL_SEQ": 3,
"FIELD_DESCRIPTION": "TRANSACTION TYPE IDENTIFIER",
Expand All @@ -87,7 +93,9 @@
"minLength": 0,
"maxLength": 20,
"pattern": "^[ A-Za-z0-9]{0,20}$",
"examples": ["A56123456789-1234"],
"examples": [
"A56123456789-1234"
],
"fec_spec": {
"COL_SEQ": 4,
"FIELD_DESCRIPTION": "TRANSACTION ID",
Expand All @@ -102,11 +110,16 @@
"back_reference_tran_id_number": {
"title": "BACK REFERENCE TRAN ID NUMBER",
"description": "",
"type": "string",
"type": [
"string",
"null"
],
"minLength": 0,
"maxLength": 20,
"pattern": "^[ A-Za-z0-9]{0,20}$",
"examples": ["A123456789-1234"],
"examples": [
"A123456789-1234"
],
"fec_spec": {
"COL_SEQ": 5,
"FIELD_DESCRIPTION": "BACK REFERENCE TRAN ID NUMBER",
Expand All @@ -121,11 +134,16 @@
"back_reference_sched_name": {
"title": "BACK REFERENCE SCHED NAME",
"description": "",
"type": "string",
"type": [
"string",
"null"
],
"minLength": 0,
"maxLength": 8,
"pattern": "^[ A-Za-z0-9]{0,8}$",
"examples": ["SA11AI"],
"examples": [
"SA11AI"
],
"fec_spec": {
"COL_SEQ": 6,
"FIELD_DESCRIPTION": "BACK REFERENCE SCHED NAME",
Expand All @@ -144,7 +162,9 @@
"minLength": 0,
"maxLength": 3,
"pattern": "^[ A-Za-z0-9]{0,3}$",
"examples": ["IND"],
"examples": [
"IND"
],
"fec_spec": {
"COL_SEQ": 7,
"FIELD_DESCRIPTION": "ENTITY TYPE",
Expand All @@ -163,7 +183,9 @@
"minLength": 0,
"maxLength": 200,
"pattern": "^[ A-Za-z0-9]{0,200}$",
"examples": ["John Smith & Co."],
"examples": [
"John Smith & Co."
],
"fec_spec": {
"COL_SEQ": 8,
"FIELD_DESCRIPTION": "CONTRIBUTOR ORGANIZATION",
Expand All @@ -182,7 +204,9 @@
"minLength": 0,
"maxLength": 34,
"pattern": "^[ A-Za-z0-9]{0,34}$",
"examples": ["123 Main Street"],
"examples": [
"123 Main Street"
],
"fec_spec": {
"COL_SEQ": 14,
"FIELD_DESCRIPTION": "CONTRIBUTOR STREET 1",
Expand All @@ -197,7 +221,10 @@
"contributor_street_2": {
"title": "CONTRIBUTOR STREET 2",
"description": "",
"type": "string",
"type": [
"string",
"null"
],
"minLength": 0,
"maxLength": 34,
"pattern": "^[ A-Za-z0-9]{0,34}$",
Expand All @@ -219,7 +246,9 @@
"minLength": 0,
"maxLength": 30,
"pattern": "^[ A-Za-z0-9]{0,30}$",
"examples": ["Anytown"],
"examples": [
"Anytown"
],
"fec_spec": {
"COL_SEQ": 16,
"FIELD_DESCRIPTION": "CONTRIBUTOR CITY",
Expand All @@ -238,7 +267,9 @@
"minLength": 0,
"maxLength": 2,
"pattern": "^[ A-Za-z0-9]{0,2}$",
"examples": ["WA"],
"examples": [
"WA"
],
"fec_spec": {
"COL_SEQ": 17,
"FIELD_DESCRIPTION": "CONTRIBUTOR STATE",
Expand All @@ -257,7 +288,9 @@
"minLength": 0,
"maxLength": 9,
"pattern": "^[ A-Za-z0-9]{0,9}$",
"examples": [981110123],
"examples": [
981110123
],
"fec_spec": {
"COL_SEQ": 18,
"FIELD_DESCRIPTION": "CONTRIBUTOR ZIP",
Expand All @@ -275,7 +308,9 @@
"type": "integer",
"minimum": 0,
"maximum": 99999999,
"examples": [20120615],
"examples": [
20120615
],
"fec_spec": {
"COL_SEQ": 21,
"FIELD_DESCRIPTION": "CONTRIBUTION DATE",
Expand All @@ -293,7 +328,9 @@
"type": "number",
"minimum": 0,
"maximum": 999999999999,
"examples": [250],
"examples": [
250
],
"fec_spec": {
"COL_SEQ": 22,
"FIELD_DESCRIPTION": "CONTRIBUTION AMOUNT",
Expand All @@ -311,7 +348,9 @@
"type": "number",
"minimum": 0,
"maximum": 999999999999,
"examples": [1000],
"examples": [
1000
],
"fec_spec": {
"COL_SEQ": 23,
"FIELD_DESCRIPTION": "CONTRIBUTION AGGREGATE",
Expand Down Expand Up @@ -344,7 +383,10 @@
"memo_code": {
"title": "MEMO CODE",
"description": "",
"type": "string",
"type": [
"string",
"null"
],
"minLength": 0,
"maxLength": 1,
"pattern": "^[ A-Za-z0-9]{0,1}$",
Expand All @@ -362,7 +404,10 @@
"memo_text_description": {
"title": "MEMO TEXT/DESCRIPTION",
"description": "",
"type": "string",
"type": [
"string",
"null"
],
"minLength": 0,
"maxLength": 100,
"pattern": "^[ A-Za-z0-9]{0,100}$",
Expand All @@ -377,6 +422,5 @@
"FIELD_FORM_ASSOCIATION": null
}
}
},
"additionalProperties": false
}
}
Loading

0 comments on commit f205c83

Please sign in to comment.