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

Handle empty reports and totals. #69

Merged
merged 1 commit into from
Apr 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
}
}