Skip to content
This repository has been archived by the owner on Dec 23, 2017. It is now read-only.

Commit

Permalink
Handle empty reports and totals.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarp committed Apr 9, 2015
1 parent 37d4663 commit 5b6ee5a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
4 changes: 2 additions & 2 deletions openfecwebapp/data_prep/financial_summaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def _map_committee_financials(vals):
from the 'totals' endpoint for use on candidate
and committee pages
"""
reports = vals['reports'][0]
totals = vals['totals'][0]
reports = vals['reports'][0] if vals['reports'] else {}
totals = vals['totals'][0] if vals['totals'] else {}
totals_mapped = {}
value_map = {
'total_receipts': totals.get('receipts'),
Expand Down
17 changes: 17 additions & 0 deletions openfecwebapp/tests/data_prep/financial_summaries_tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import copy
import unittest

from openfecwebapp.data_prep.financial_summaries import _map_committee_financials
from openfecwebapp.tests.mock_data import *


class TestFinancialSummaries(unittest.TestCase):

def test_map_committee_financials(self):
Expand All @@ -21,3 +24,17 @@ def test_map_committee_financials(self):
self.assertEqual('$0.00', c['total_disbursements'])
self.assertEqual('$0.00', c['total_cash'])
self.assertEqual('$0.00', c['total_debt'])

def test_map_committee_financials_empty_reports(self):
result = copy.deepcopy(totals['results'][0])
result['reports'] = []
res = _map_committee_financials(result)
self.assertNotIn('total_cash', res)
self.assertNotIn('total_debt', res)

def test_map_committee_financials_empty_totals(self):
result = copy.deepcopy(totals['results'][0])
result['totals'] = []
res = _map_committee_financials(result)
self.assertNotIn('total_receipts', res)
self.assertNotIn('total_disbursements', res)
10 changes: 5 additions & 5 deletions openfecwebapp/tests/mock_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'committee_id': 'D1234',
'committee_name': 'Friends of McPersonson',
'committee_designation': 'A',
'committee_designation_full': 'Authorized committee'
'committee_designation_full': 'Authorized committee'
}
]
}],
Expand All @@ -35,14 +35,14 @@
'committee_id': 'D1234',
'name': 'Friends of McPersonson',
'designation_full': 'Authorized',
'designation_code': 'PC'
'designation_code': 'PC'
},
'affiliated_committees': {
'D1234': {
'id': 'D1234',
'name': 'Friends of McPersonson',
'designation_full': 'Authorized',
'designation_code': 'A'
'designation_code': 'A'
}
}
}
Expand Down Expand Up @@ -103,7 +103,7 @@
'committee_id': 'D1234',
'committee_name': 'Friends of McPersonson',
'designation_full': 'Authorized',
'designation_code': 'A'
'designation_code': 'A'

}
]
Expand All @@ -113,7 +113,7 @@
'committee_id': 'D1234',
'committee_name': 'Friends of McPersonson',
'designation_full': 'Authorized',
'designation_code': 'A'
'designation_code': 'A'
}
}

0 comments on commit 5b6ee5a

Please sign in to comment.