def test_add_demographics_rows(self, app): import tempfile with tempfile.TemporaryFile() as demo_file, tempfile.TemporaryFile() as ethn_file, tempfile.TemporaryFile() as visa_file: feed_files = { 'demographics': demo_file, 'ethnicities': ethn_file, 'visas': visa_file, } feed_counts = { 'demographics': 0, 'ethnicities': 0, 'visas': 0, } raw_feed = get_term_gpas_registration_demog('1234567890').get('demographics') parsed = add_demographics_rows('1234567890', raw_feed, feed_files, feed_counts) assert not parsed.get('filtered_ethnicities') assert parsed['ethnicities'] == ['Korean / Korean-American', 'White'] feed_files['demographics'].seek(0) assert feed_files['demographics'].read() == b'1234567890\tFemale\tFalse\n' assert feed_counts['demographics'] == 1 feed_files['ethnicities'].seek(0) assert feed_files['ethnicities'].read() == b'1234567890\tKorean / Korean-American\n' assert feed_counts['ethnicities'] == 1 feed_files['visas'].seek(0) assert feed_files['visas'].read() == b'1234567890\tG\tF1\n' assert feed_counts['visas'] == 1
def test_api_visa_parsing(self, app): raw_feed = get_term_gpas_registration_demog('1234567890').get('demographics') parsed = parse_sis_demographics_api(raw_feed) assert parsed['ethnicities'] == ['Korean / Korean-American', 'White'] assert parsed['visa']['status'] == 'G' assert parsed['visa']['type'] == 'F1' assert parsed['nationalities'] == ['Korea, Republic of'] assert parsed['filtered_ethnicities'] == ['Korean / Korean-American']
def _async_get_feed(self, app_obj, sid): with app_obj.app_context(): app.logger.info(f'Fetching registration history for SID {sid}') feed = sis_student_api.get_term_gpas_registration_demog(sid, self.include_demographics) result = { 'sid': sid, 'feed': feed, } return result
def test_api_parsing(self, app): raw_feed = get_term_gpas_registration_demog('11667051').get('demographics') parsed = parse_sis_demographics_api(raw_feed) assert parsed['ethnicities'] == ['White'] assert not parsed['underrepresented'] assert parsed['gender'] == 'Female' assert not parsed['visa'] assert not parsed['nationalities'] assert parsed['filtered_ethnicities'] == ['White']
def async_get_feed(app_obj, sid): with app_obj.app_context(): app.logger.info(f'Fetching registration history for SID {sid}') feed = sis_student_api.get_term_gpas_registration_demog( sid, with_demog=False) result = { 'sid': sid, 'feed': feed, } return result
def test_get_term_gpas_registration_demog(self, app): reg_feed = student_api.get_term_gpas_registration_demog(11667051) gpas = reg_feed['term_gpas'] assert len(gpas) == 7 assert gpas['2148']['gpa'] == 3.3 assert gpas['2158']['unitsTakenForGpa'] > 0 assert gpas['2152']['gpa'] == 4.0 assert gpas['2152']['unitsTakenForGpa'] > 0 assert gpas['2155']['gpa'] == 0.0 assert gpas['2155']['unitsTakenForGpa'] == 0 assert gpas['2168']['gpa'] == 3.0 assert gpas['2168']['unitsTakenForGpa'] > 0 last_registration = reg_feed['last_registration'] assert last_registration['term']['id'] == '2172' assert last_registration['academicCareer']['code'] == 'UGRD' assert len(last_registration['academicLevels']) == 2 assert last_registration['academicLevels'][0]['type']['code'] == 'BOT' assert len(last_registration['termUnits']) == 3 assert last_registration['termGPA']['average'] == 3.3
def test_get_demog_data(self, app): demog_feed = student_api.get_term_gpas_registration_demog(1234567890)['demographics'] ethn = demog_feed['ethnicities'] assert len(ethn) == 2 assert ethn[0]['group']['description'] == 'White' assert ethn[1]['detail']['description'] == 'Korean' assert ethn[1]['group']['description'] == 'Asian' foreign = demog_feed['foreignCountries'] assert len(foreign) == 1 assert foreign[0]['code'] == 'KOR' assert foreign[0]['description'] == 'Korea, Republic of' gender = demog_feed['gender'] assert gender['genderOfRecord']['description'] == 'Female' assert gender['sexAtBirth']['description'] == 'Female' assert demog_feed['residency']['official']['description'] == 'Non-Resident' assert demog_feed['usaCountry']['citizenshipStatus']['description'] == 'Alien Temporary' visa = demog_feed['usaCountry']['visa'] assert visa['status'] == 'G' assert visa['type']['code'] == 'F1' assert visa['type']['description'] == 'Student in Academic Program'