def test_indicators_store_correct_date(self, mock_indic, mock_load):
        mock_load.return_value = self.catalogs
        mock_indic.return_value = (self.indicators, self.network_indicators)
        with patch('monitoreo.apps.dashboard.indicators_tasks.timezone'
                   ) as mock_time:
            time = timezone.localtime().replace(hour=5, minute=0)
            mock_time.localtime.return_value = time
            task1 = IndicatorsGenerationTask.objects.create()
            generate_indicators(task1)

        self.indicator_2['ind_b'] = 10

        self.indicator_1['identifier'] = 'a'
        self.indicator_2['identifier'] = 'b'

        self.indicator_1['title'] = self.catalogs[0]['title']
        self.indicator_2['title'] = self.catalogs[1]['title']

        with patch('monitoreo.apps.dashboard.indicators_tasks.timezone'
                   ) as mock_time:
            time = timezone.localtime().replace(hour=23, minute=0)
            mock_time.localtime.return_value = time
            task2 = IndicatorsGenerationTask.objects.create()
            generate_indicators(task2)

        self.assertEqual(6, Indicador.objects.count())
        self.assertEqual(3, IndicadorRed.objects.count())
        ind_type = IndicatorType.objects.get(nombre='ind_b', tipo='RED')
        self.assertEqual(
            '10',
            Indicador.objects.get(
                jurisdiccion_nombre=self.catalogs[1]['title'],
                indicador_tipo=ind_type).indicador_valor)
 def test_task_is_finished(self, mock_indic, mock_load):
     mock_load.return_value = self.catalogs
     mock_indic.return_value = (self.indicators, self.network_indicators)
     task = IndicatorsGenerationTask.objects.create()
     generate_indicators(task)
     task.refresh_from_db()
     self.assertEqual(IndicatorsGenerationTask.FINISHED, task.status)
Exemplo n.º 3
0
 def test_default_columns_are_created(self, mock_indic, mock_load):
     mock_load.return_value = self.catalogs
     mock_indic.return_value = (self.indicators, self.network_indicators)
     task = IndicatorsGenerationTask.objects.create()
     generate_indicators(task)
     self.assertEqual(3, TableColumn.objects.count())
     self.assertEqual(1, TableColumn.objects.filter(full_name='col_a').count())
     self.assertEqual(1, TableColumn.objects.filter(full_name='col_b').count())
     self.assertEqual(1, TableColumn.objects.filter(full_name='col_c').count())
Exemplo n.º 4
0
 def test_indicator_models_are_created(self, mock_indic, mock_load):
     mock_load.return_value = self.catalogs
     mock_indic.return_value = (self.indicators, self.network_indicators)
     task = IndicatorsGenerationTask.objects.create()
     generate_indicators(task)
     self.assertEqual(6, Indicador.objects.count())
     self.assertEqual(3, IndicadorRed.objects.count())
     self.assertEqual(3, Indicador.objects.filter(jurisdiccion_nombre=self.catalogs[0]['title']).count())
     self.assertEqual(3, Indicador.objects.filter(jurisdiccion_nombre=self.catalogs[1]['title']).count())
     self.assertEqual(3, IndicadorFederador.objects.filter(jurisdiccion_nombre=self.catalogs[0]['title']).count())
     self.assertEqual(3, IndicadorFederador.objects.filter(jurisdiccion_nombre=self.catalogs[1]['title']).count())
 def test_central_node_default(self, mock_indic, mock_load):
     mock_load.return_value = self.catalogs
     mock_indic.return_value = (self.indicators, self.network_indicators)
     task = IndicatorsGenerationTask.objects.create()
     generate_indicators(task)
     mock_indic.assert_any_call(DataJson(),
                                self.catalogs,
                                identifier_search=True)
     mock_indic.assert_any_call(DataJson(),
                                self.catalogs,
                                CENTRAL,
                                identifier_search=True)
Exemplo n.º 6
0
 def test_undefined_central_node_uses_default(self, mock_indic, mock_load):
     mock_load.return_value = self.catalogs
     mock_indic.return_value = (self.indicators, self.network_indicators)
     CentralNode.objects.create()
     task = IndicatorsGenerationTask.objects.create()
     generate_indicators(task)
     mock_indic.assert_any_call(DataJson(), self.catalogs,
                                identifier_search=True,
                                broken_links=False,
                                broken_links_threads=1)
     mock_indic.assert_any_call(DataJson(), self.catalogs, CENTRAL,
                                identifier_search=True,
                                broken_links=False,
                                broken_links_threads=1)
 def test_defined_central_node_catalog(self, mock_indic, mock_load):
     mock_load.return_value = self.catalogs
     mock_indic.return_value = (self.indicators, self.network_indicators)
     harvesting = HarvestingNode.objects.create(name='aName',
                                                url='harvest_url/',
                                                apikey='apikey',
                                                enabled=True)
     CentralNode.objects.create(node=harvesting)
     task = IndicatorsGenerationTask.objects.create()
     generate_indicators(task)
     mock_indic.assert_any_call(DataJson(),
                                self.catalogs,
                                identifier_search=True)
     mock_indic.assert_any_call(DataJson(),
                                self.catalogs,
                                'harvest_url/data.json',
                                identifier_search=True)
Exemplo n.º 8
0
    def test_indicators_are_updated_without_replication(self, mock_indic, mock_load):
        mock_load.return_value = self.catalogs
        mock_indic.return_value = (self.indicators, self.network_indicators)
        task = IndicatorsGenerationTask.objects.create()
        generate_indicators(task)
        self.indicator_2['ind_b'] = 10

        self.indicator_1['identifier'] = 'a'
        self.indicator_2['identifier'] = 'b'

        self.indicator_1['title'] = self.catalogs[0]['title']
        self.indicator_2['title'] = self.catalogs[1]['title']

        generate_indicators(task)
        self.assertEqual(6, Indicador.objects.count())
        self.assertEqual(3, IndicadorRed.objects.count())
        ind_type = IndicatorType.objects.get(nombre='ind_b', tipo='RED')
        self.assertEqual('10', Indicador.objects.get(jurisdiccion_nombre=self.catalogs[1]['title'],
                                                     indicador_tipo=ind_type).indicador_valor)
Exemplo n.º 9
0
 def handle(self, *args, **options):
     # Llama sincrónicamente
     task = IndicatorsGenerationTask.objects.create()
     generate_indicators(task)