def test_nodes_csv_included_indicator_types(self): excluded_types = ('ind_b', 'ind_d', 'ind_e') IndicatorType.objects.filter(nombre__in=excluded_types).update( panel_nodos=False) for row in csv_panel_writer(Indicador, self.indicador_fieldnames): for excluded_type in excluded_types: self.assertNotIn(excluded_type, row)
def assert_dates_column_has_dates_format(self, model, fieldnames): data_rows = list(csv_panel_writer(model, fieldnames))[1:] dates_column = [row.split(',')[0] for row in data_rows] for date in dates_column: matched_pattern = re.match("\d{4}-\d{2}-\d{2}", date) self.assertTrue(matched_pattern)
def test_network_csv_included_indicator_types(self): excluded_types = ('ind_a', 'ind_b', 'ind_c') IndicatorType.objects.filter(nombre__in=excluded_types).update( panel_red=False) for row in csv_panel_writer(IndicadorRed, self.indicador_red_fieldnames): for excluded_type in excluded_types: self.assertNotIn(excluded_type, row)
def assert_dates_column_contains_indicator_created_date( self, model, fieldnames): dates_column = [ row.split(',')[0] for row in list(csv_panel_writer(model, fieldnames))[1:] ] expected_date = '2000-01-01' for date in dates_column: self.assertEquals(expected_date, date)
def setUp(self): self.indicador_red_fieldnames = \ ['fecha', 'indicador_tipo__nombre', 'indicador_valor'] self.indicador_fieldnames = \ ['fecha', 'indicador_tipo__nombre', 'indicador_valor', 'jurisdiccion_nombre', 'jurisdiccion_id'] self.indicador_federador_fieldnames = self.indicador_fieldnames self.indicador_red_headers = \ ['fecha', 'indicador_nombre', 'indicador_apertura', 'indicador_valor'] self.indicador_red_rows_list = list( csv_panel_writer(IndicadorRed, self.indicador_red_fieldnames)) self.indicador_headers = \ ['fecha', 'indicador_nombre', 'indicador_apertura', 'indicador_valor', 'nodo_nombre', 'nodo_id'] self.indicador_rows_list = list( csv_panel_writer(Indicador, self.indicador_fieldnames)) self.indicador_federador_headers = self.indicador_headers self.indicador_federador_rows_list = list( csv_panel_writer(IndicadorFederador, self.indicador_federador_fieldnames))
def _write_zip_file(self, domain, dst_dir, model, values_lookup): filename = f'indicadores-{domain}.csv.gz' with gzip.open(os.path.join(dst_dir, filename), 'wt') as zipfile: for row in csv_panel_writer(model, values_lookup): zipfile.write(row)
def test_federators_panel_zip_content(self): fieldnames = ['fecha', 'indicador_tipo__nombre', 'indicador_valor', 'jurisdiccion_nombre', 'jurisdiccion_id'] response = self.client.get(reverse('dashboard:indicadores-federadores-zip')) with gzip.open(BytesIO(response.content), 'rt') as zipfile: for expected_line, res_line in zip(csv_panel_writer(IndicadorFederador, fieldnames), zipfile): self.assertEqual(expected_line.rstrip(), res_line.rstrip())
def assert_first_row_is_header(self, model, fieldnames, headers): first_row = [ row.strip() for row in list(csv_panel_writer(model, fieldnames))[0].split(',') ] self.assertEquals(first_row, headers)
def assert_generated_rows_equals_indicator_count(self, model, fieldnames, count): data_rows_quantity = len(list(csv_panel_writer(model, fieldnames))[1:]) self.assertEquals(count, data_rows_quantity)