diff --git a/server/data/fec/contributions.py b/server/data/fec/contributions.py index 4e0168e..f8d9082 100644 --- a/server/data/fec/contributions.py +++ b/server/data/fec/contributions.py @@ -330,10 +330,11 @@ def from_data(cls, value: t.Any) -> "ContributionSummary": zip_code=v.get_str(data, "zip_code"), total=v.get_convert_decimal(data, "total"), by_party={ - party: Decimal(amount) for party, amount in by_party_data.items() + party: v.validate_convert_decimal(amount) + for party, amount in by_party_data.items() }, by_committee={ - committee: Decimal(amount) + committee: v.validate_convert_decimal(amount) for committee, amount in by_committee_data.items() }, ) diff --git a/server/data/fec/test_contributions.py b/server/data/fec/test_contributions.py index 00d3dd9..1aea79b 100644 --- a/server/data/fec/test_contributions.py +++ b/server/data/fec/test_contributions.py @@ -254,3 +254,25 @@ def test_add(self): self.assertEqual(summary.by_committee.get("C12345"), Decimal(10)) self.assertEqual(summary.by_committee.get("C67890"), Decimal(20)) self.assertEqual(summary.by_committee.get("CABCDE"), Decimal(50)) + + def test_from_data_valid(self): + data = { + "fuzzy_id": "SMITH-JOHN-98101", + "name": "Smith, John", + "zip_code": "98101", + "total": "80", + "by_party": {Party.DEMOCRAT: "30", Party.GREEN: "50"}, + "by_committee": {"C12345": "10", "C67890": "20", "CABCDE": "50"}, + } + summary = cont.ContributionSummary.from_data(data) + self.assertEqual(summary.fuzzy_id, "SMITH-JOHN-98101") + self.assertEqual(summary.name, "Smith, John") + self.assertEqual(summary.zip_code, "98101") + self.assertEqual(summary.total, Decimal(80)) + self.assertEqual(len(summary.by_party), 2) + self.assertEqual(summary.by_party.get(Party.DEMOCRAT), Decimal(30)) + self.assertEqual(summary.by_party.get(Party.GREEN), Decimal(50)) + self.assertEqual(len(summary.by_committee), 3) + self.assertEqual(summary.by_committee.get("C12345"), Decimal(10)) + self.assertEqual(summary.by_committee.get("C67890"), Decimal(20)) + self.assertEqual(summary.by_committee.get("CABCDE"), Decimal(50))