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/75 Add boolean and date fields to validation #142

Merged
merged 11 commits into from
Jun 27, 2022
1,498 changes: 749 additions & 749 deletions django-backend/fecfiler/f3x_summaries/fixtures/test_db_f3x_summaries.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[
{
"model": "f3x_summaries.f3xsummary",
"fields": {
"form_type": "F3XN",
"filer_committee_id_number": "C00000000",
"treasurer_last_name": "Lastname",
"treasurer_first_name": "Firstname",
"date_signed": "20040729",
"created": "2022-02-09T00:00:00.000Z",
"updated": "2022-02-09T00:00:00.000Z",
"committee_account_id": 1000
}
{
"model": "f3x_summaries.f3xsummary",
"fields": {
"form_type": "F3XN",
"filer_committee_id_number": "C00000000",
"treasurer_last_name": "Lastname",
"treasurer_first_name": "Firstname",
"date_signed": "2004-07-29",
"created": "2022-02-09T00:00:00.000Z",
"updated": "2022-02-09T00:00:00.000Z",
"committee_account_id": 1000
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.2.12 on 2022-06-09 21:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('f3x_summaries', '0010_auto_20220525_1157'),
]

operations = [
migrations.AlterField(
model_name='f3xsummary',
name='coverage_from_date',
field=models.DateField(blank=True, null=True),
),
migrations.AlterField(
model_name='f3xsummary',
name='coverage_through_date',
field=models.DateField(blank=True, null=True),
),
migrations.AlterField(
model_name='f3xsummary',
name='date_of_election',
field=models.DateField(blank=True, null=True),
),
migrations.AlterField(
model_name='f3xsummary',
name='date_signed',
field=models.DateField(blank=True, null=True),
),
]
8 changes: 4 additions & 4 deletions django-backend/fecfiler/f3x_summaries/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ class F3XSummary(SoftDeleteModel, CommitteeOwnedModel):
db_column="report_code",
)
election_code = models.TextField(null=True, blank=True)
date_of_election = models.TextField(null=True, blank=True)
date_of_election = models.DateField(null=True, blank=True)
state_of_election = models.TextField(null=True, blank=True)
coverage_from_date = models.TextField(null=True, blank=True)
coverage_through_date = models.TextField(null=True, blank=True)
coverage_from_date = models.DateField(null=True, blank=True)
coverage_through_date = models.DateField(null=True, blank=True)
qualified_committee = models.BooleanField(default=False, null=True, blank=True)
treasurer_last_name = models.TextField(null=True, blank=True)
treasurer_first_name = models.TextField(null=True, blank=True)
treasurer_middle_name = models.TextField(null=True, blank=True)
treasurer_prefix = models.TextField(null=True, blank=True)
treasurer_suffix = models.TextField(null=True, blank=True)
date_signed = models.TextField(null=True, blank=True)
date_signed = models.DateField(null=True, blank=True)
L6b_cash_on_hand_beginning_period = models.IntegerField(null=True, blank=True)
L6c_total_receipts_period = models.IntegerField(null=True, blank=True)
L6d_subtotal_period = models.IntegerField(null=True, blank=True)
Expand Down
2 changes: 1 addition & 1 deletion django-backend/fecfiler/f3x_summaries/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def setUp(self):
filer_committee_id_number="C00123456",
treasurer_last_name="Validlastname",
treasurer_first_name="Validfirstname",
date_signed="20220101",
date_signed="2022-01-01",
committee_account_id=1000,
)

Expand Down
4 changes: 2 additions & 2 deletions django-backend/fecfiler/f3x_summaries/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ def setUp(self):
"filer_committee_id_number": "C00123456",
"treasurer_last_name": "Validlastname",
"treasurer_first_name": "Validfirstname",
"date_signed": "20220101",
"date_signed": "2022-01-01",
}

self.invalid_f3x_summary = {
"form_type": "invalidformtype",
"treasurer_last_name": "Validlastname",
"date_signed": "20220101",
"date_signed": "2022-01-01",
}

self.mock_request = Request(HttpRequest())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.12 on 2022-06-09 21:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('scha_transactions', '0008_alter_schatransaction_memo_code'),
]

operations = [
migrations.AlterField(
model_name='schatransaction',
name='contribution_date',
field=models.DateField(blank=True, null=True),
),
]
2 changes: 1 addition & 1 deletion django-backend/fecfiler/scha_transactions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SchATransaction(SoftDeleteModel, CommitteeOwnedModel):
contributor_zip = models.TextField(null=True, blank=True)
election_code = models.TextField(null=True, blank=True)
election_other_description = models.TextField(null=True, blank=True)
contribution_date = models.TextField(null=True, blank=True)
contribution_date = models.DateField(null=True, blank=True)
contribution_amount = models.IntegerField(null=True, blank=True)
contribution_aggregate = models.IntegerField(null=True, blank=True)
contribution_purpose_descrip = models.TextField(null=True, blank=True)
Expand Down
8 changes: 7 additions & 1 deletion django-backend/fecfiler/validation/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import date
from rest_framework import serializers
from fecfile_validate import validate
from rest_framework import exceptions
Expand Down Expand Up @@ -50,7 +51,8 @@ def get_schema_name(self, data):

def get_validation_candidate(self, data):
"""Returns a copy of data where foreign key fields are replaced with the
underlying foreign key field.
underlying foreign key field. Also dates and datetimes will be replaced
with iso8601 strings

Example: the f3x table is related to the report code label table by the
report code field. DRF gives us the whole
Expand All @@ -66,6 +68,10 @@ def get_validation_candidate(self, data):
validation_candidate.get(foreign_key_field, {}), actual_key
)

for key, value in validation_candidate.items():
if isinstance(value, date):
validation_candidate[key] = value.isoformat()

return validation_candidate

def get_foreign_key_fields(self):
Expand Down
2 changes: 1 addition & 1 deletion django-backend/fecfiler/validation/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setUp(self):
"filer_committee_id_number": "C00123456",
"treasurer_last_name": "Validlastname",
"treasurer_first_name": "Validfirstname",
"date_signed": "20220101",
"date_signed": "2022-01-01",
}

self.invalid_f3x_summary = {
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ django-cors-headers==3.11.0
djangorestframework==3.13.1
djangorestframework-jwt==1.11.0
drf-spectacular==0.21.2
git+https://github.com/fecgov/fecfile-validate@be23cab922b2c263f2071be3d7d827d195c01397#egg=fecfile_validate&subdirectory=fecfile_validate_python
git+https://github.com/fecgov/fecfile-validate@1fa8c59b83e17b7fb51e8763549885315f9475f2#egg=fecfile_validate&subdirectory=fecfile_validate_python
GitPython==3.1.27
gunicorn==19.10.0
Jinja2==2.11.3
Expand Down