def test_build_field_string(self): field_string = api_utils.build_field_string() self.assertTrue(field_string.startswith('id')) self.assertEqual( len(field_string.split(',')), (len(api_utils.BASE_FIELDS) + len(api_utils.YEAR_FIELDS) + len(api_utils.PROGRAM_FIELDS)))
def test_single_school_request(self, mock_get_data): mock_get_data.return_value = self.mock_results.get('results')[0] update_colleges.update(single_school=408039) self.assertEqual(mock_get_data.call_count, 1) self.assertTrue(mock_get_data.called_with( 408039, api_utils.build_field_string() ))
from requests.exceptions import SSLError from paying_for_college.disclosures.scripts import api_utils from paying_for_college.disclosures.scripts.api_utils import (DECIMAL_MAP, MODEL_MAP) from paying_for_college.models import CONTROL_MAP, FAKE_SCHOOL_PK, School logger = logging.getLogger(__name__) DATESTAMP = datetime.datetime.now().strftime("%Y-%m-%d") HOME = os.path.expanduser("~") NO_DATA_FILE = "{}/no_data_{}.json".format(HOME, DATESTAMP) SCRIPTNAME = os.path.basename(__file__).partition('.')[0] ID_BASE = "{}?api_key={}".format(api_utils.SCHOOLS_ROOT, api_utils.API_KEY) FIELDS = sorted(MODEL_MAP.keys()) FIELDSTRING = api_utils.build_field_string() def fix_zip5(zip5): """Add leading zeros if they have been stripped by the scorecard db.""" if len(zip5) == 4: return "0{}".format(zip5) if len(zip5) == 3: return "00{}".format(zip5) else: return zip5[:5] def get_scorecard_data(url): """Make our API call to Scorecard.""" try:
def test_build_field_string(self): fstring = api_utils.build_field_string(YEAR) self.assertTrue(fstring.startswith('id')) self.assertTrue(fstring.endswith('25000'))