Skip to content

Commit

Permalink
Working on contribution tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davepeck committed Nov 22, 2023
1 parent 16ef4a9 commit 4f56adc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
5 changes: 3 additions & 2 deletions server/data/fec/contributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
)
Expand Down
22 changes: 22 additions & 0 deletions server/data/fec/test_contributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 4f56adc

Please sign in to comment.