def test_load_percentile_model(self): self.mox.StubOutWithMock(db_util, 'load_percentile_model') db_util.load_percentile_model('test_format').AndReturn(TEST_MCDI_MODEL) self.mox.ReplayAll() adapter = recalc_util.CachedMCDIAdapter() result_1 = adapter.load_percentile_model('test_format') result_2 = adapter.load_percentile_model('test_format') self.assertEqual(result_1, TEST_MCDI_MODEL) self.assertEqual(result_2, TEST_MCDI_MODEL)
def load_percentile_model(self, type_name): if type_name in self.percentiles: return self.percentiles[type_name] percentile_model = db_util.load_percentile_model(type_name) self.percentiles[type_name] = percentile_model return percentile_model
def parse_csv(contents, mcdi_type, languages, hard_of_hearing, act_as_file=False): mcdi_model = db_util.load_mcdi_model(mcdi_type) percentile_names = mcdi_model.details['percentiles'] male_percentiles_name = percentile_names['male'] female_percentiles_name = percentile_names['female'] other_percentiles_name = percentile_names['other'] male_percentiles = db_util.load_percentile_model(male_percentiles_name) female_percentiles = db_util.load_percentile_model(female_percentiles_name) other_percentiles = db_util.load_percentile_model(other_percentiles_name) percentile_tables = { constants.MALE: male_percentiles, constants.FEMALE: female_percentiles, constants.OTHER_GENDER: other_percentiles } connection = db_util.get_db_connection() cursor = connection.cursor() parse_info = parse_csv_prototypes(contents, percentile_tables, act_as_file) if parse_info['error']: connection.commit() connection.close() return {'error': parse_info['error']} prototypes = parse_info['prototypes'] ids = map(lambda x: x['child_id'], prototypes) for prototype in prototypes: build_snapshot(prototype, mcdi_type, languages, hard_of_hearing, cursor) connection.commit() connection.close() return {'error': None, 'ids': ids}