<s> import os <EOL> import unittest <EOL> import requests <EOL> import requests_cache <EOL> from nytcampfin import NytCampfin , NytCampfinError , NytNotFoundError <EOL> CURRENT_CYCLE = <NUM_LIT> <EOL> try : <EOL> API_KEY = os . environ [ '<STR_LIT>' ] <EOL> except : <EOL> print "<STR_LIT>" <EOL> class APITest ( unittest . TestCase ) : <EOL> def check_response ( self , result , url , parse = lambda r : r [ '<STR_LIT>' ] ) : <EOL> with requests_cache . disabled ( ) : <EOL> response = requests . get ( url ) <EOL> if parse and callable ( parse ) : <EOL> response = parse ( response . json ) <EOL> self . assertEqual ( result , response ) <EOL> def setUp ( self ) : <EOL> self . finance = NytCampfin ( API_KEY ) <EOL> class FilingTest ( APITest ) : <EOL> def test_todays_filings ( self ) : <EOL> today = self . finance . filings . today ( offset = <NUM_LIT:20> ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( today , url ) <EOL> def test_filings_for_date ( self ) : <EOL> july4th = self . finance . filings . date ( <NUM_LIT> , <NUM_LIT:0> <NUM_LIT:7> , <NUM_LIT:0> <NUM_LIT:4> ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( july4th , url ) <EOL> def test_form_types ( self ) : <EOL> form_types = self . finance . filings . form_types ( ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( form_types , url ) <EOL> def test_filings_by_form_type ( self ) : <EOL> f2s = self . finance . filings . by_type ( '<STR_LIT>' ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( f2s , url ) <EOL> def test_amended_filings ( self ) : <EOL> amendments = self . finance . filings . amendments ( ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( amendments , url ) <EOL> class IndependentExpenditureTest ( APITest ) : <EOL> def test_latest ( self ) : <EOL> latest = self . finance . indexp . latest ( ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( latest , url ) <EOL> def test_ies_for_date ( self ) : <EOL> july3rd = self . finance . indexp . date ( <NUM_LIT> , <NUM_LIT:0> <NUM_LIT:7> , <NUM_LIT:0> <NUM_LIT:3> ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( july3rd , url ) <EOL> def test_committee_ies ( self ) : <EOL> ies = self . finance . indexp . committee ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( ies , url ) <EOL> def test_race_totals ( self ) : <EOL> races = self . finance . indexp . race_totals ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( races , url ) <EOL> def test_candidate_ies ( self ) : <EOL> ies = self . finance . indexp . candidate ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( ies , url ) <EOL> def test_president_ies ( self ) : <EOL> ies = self . finance . indexp . president ( ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( ies , url ) <EOL> def test_superpacs ( self ) : <EOL> superpacs = self . finance . indexp . superpacs ( ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( superpacs , url ) <EOL> class CandidateTest ( APITest ) : <EOL> def test_latest ( self ) : <EOL> latest = self . finance . candidates . latest ( ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( latest , url ) <EOL> def test_detail ( self ) : <EOL> detail = self . finance . candidates . get ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> response = requests . get ( url ) <EOL> self . check_response ( detail , url , parse = lambda r : r [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> def test_filter ( self ) : <EOL> wilson = self . finance . candidates . filter ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( wilson , url ) <EOL> def test_leaders ( self ) : <EOL> loans = self . finance . candidates . leaders ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( loans , url ) <EOL> def test_candidates_for_state ( self ) : <EOL> candidates = self . finance . candidates . seats ( '<STR_LIT>' ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( candidates , url ) <EOL> def test_candidates_for_state_and_chamber ( self ) : <EOL> candidates = self . finance . candidates . seats ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( candidates , url ) <EOL> def test_candidates_for_state_and_chamber_and_district ( self ) : <EOL> candidates = self . finance . candidates . seats ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:6> ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( candidates , url ) <EOL> def test_late_contributions ( self ) : <EOL> late_contribs = self . finance . candidates . late_contributions ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( late_contribs , url ) <EOL> class CommitteeTest ( APITest ) : <EOL> def test_latest ( self ) : <EOL> latest = self . finance . committees . latest ( ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( latest , url ) <EOL> def test_detail ( self ) : <EOL> detail = self . finance . committees . get ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> response = requests . get ( url ) <EOL> self . check_response ( detail , url , parse = lambda r : r [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> def test_filter ( self ) : <EOL> hallmark = self . finance . committees . filter ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( hallmark , url ) <EOL> def test_contributions ( self ) : <EOL> contributions = self . finance . committees . contributions ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( contributions , url ) <EOL> def test_contributions_to_candidate ( self ) : <EOL> contributions = self . finance . committees . contributions_to_candidate ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( contributions , url ) <EOL> def test_late_contributions ( self ) : <EOL> late_contribs = self . finance . committees . late_contributions ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( late_contribs , url ) <EOL> def test_filings ( self ) : <EOL> filings = self . finance . committees . filings ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( filings , url ) <EOL> def test_ie_totals ( self ) : <EOL> ie_totals = self . finance . committees . ie_totals ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( ie_totals , url ) <EOL> def test_leadership ( self ) : <EOL> leadership = self . finance . committees . leadership ( ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( leadership , url ) <EOL> class LateContributionTest ( APITest ) : <EOL> def test_latest ( self ) : <EOL> late_contribs = self . finance . late_contribs . latest ( ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( late_contribs , url ) <EOL> def test_date ( self ) : <EOL> late_contribs = self . finance . late_contribs . date ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( late_contribs , url ) <EOL> class PresidentTest ( APITest ) : <EOL> def test_candidates ( self ) : <EOL> candidates = self . finance . president . candidates ( ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( candidates , url ) <EOL> def test_detail_using_id ( self ) : <EOL> candidate = self . finance . president . detail ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( candidate , url , parse = lambda r : r [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> def test_detail_using_name ( self ) : <EOL> candidate = self . finance . president . detail ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( candidate , url , parse = lambda r : r [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> def test_state_total ( self ) : <EOL> state = self . finance . president . state ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( state , url ) <EOL> def test_zip_total ( self ) : <EOL> zipcode = self . finance . president . zipcode ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" % API_KEY <EOL> self . check_response ( zipcode , url ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
