def test_getAmt(self): donation = Donation('C00384516', 'ABBOTT, JOSEPH', '028956146'[0:5], '01122018', '333', '') self.assertEqual(donation.getAmt(), float(333))
viewed = Dictionary() repeated = Dictionary() with open(sys.argv[1]) as file: for record in file: record = record.split('|') CMTE_ID, NAME, ZIP_CODE = record[0], record[7], record[10] TRANSACTION_DT, TRANSACTION_AMT, OTHER_ID = record[13], record[ 14], record[15] if ZIP_CODE is None: continue else: donation = Donation(CMTE_ID, NAME, ZIP_CODE[0:5], TRANSACTION_DT, TRANSACTION_AMT, OTHER_ID) if donation.isValid(): don_id = donation.getID() if viewed.check(don_id): repeated.add_long(donation.getRecipient(), donation.getZip(), donation.getYear(), donation.getAmt()) key = donation.getRecipient(), donation.getZip( ), donation.getYear() total_donations = repeated.get(key) # calculate percentile of contributions dollar_donations = total_donations
def test_isValid(self): donation = Donation('C00384516', 'ABBOTT, JOSEPH', '028956146'[0:5], '01122018', '333', '') self.assertEqual(donation.isValid(), True) donation = Donation(None, 'ABBOTT, JOSEPH', '028956146'[0:5], '01122018', '333', '') self.assertEqual(donation.isValid(), False) donation = Donation('', 'ABBOTT, JOSEPH', '028956146'[0:5], '01122018', '333', '') self.assertEqual(donation.isValid(), False) donation = Donation('$00384516', 'ABBOTT, JOSEPH', '028956146'[0:5], '01122018', '333', '') self.assertEqual(donation.isValid(), False) donation = Donation('C00384516', None, '028956146'[0:5], '01122018', '333', '') self.assertEqual(donation.isValid(), False) donation = Donation('C00384516', '', '028956146'[0:5], '01122018', '333', '') self.assertEqual(donation.isValid(), False) donation = Donation('C00384516', 'ABBOTT,*JOSEPH', '028956146'[0:5], '01122018', '333', '') self.assertEqual(donation.isValid(), False) donation = Donation('C00384516', 'ABBOTT, JOSEPH', '028'[0:5], '01122018', '333', '') self.assertEqual(donation.isValid(), False) donation = Donation('C00384516', 'ABBOTT, JOSEPH', '028#95146'[0:5], '01122018', '333', '') self.assertEqual(donation.isValid(), False) donation = Donation('C00384516', 'ABBOTT, JOSEPH', '028956146'[0:5], None, '333', '') self.assertEqual(donation.isValid(), False) donation = Donation('C00384516', 'ABBOTT, JOSEPH', '028956146'[0:5], '', '333', '') self.assertEqual(donation.isValid(), False) donation = Donation('C00384516', 'ABBOTT, JOSEPH', '028956146'[0:5], '&1-2?18', '333', '') self.assertEqual(donation.isValid(), False) donation = Donation('C00384516', 'ABBOTT, JOSEPH', '028956146'[0:5], '01122018', None, '') self.assertEqual(donation.isValid(), False) donation = Donation('C00384516', 'ABBOTT, JOSEPH', '028956146'[0:5], '01122018', '', '') self.assertEqual(donation.isValid(), False) donation = Donation('C00384516', 'ABBOTT, JOSEPH', '028956146'[0:5], '01122018', '333', 'abc') self.assertEqual(donation.isValid(), False)