Ejemplo n.º 1
0
    def handle(self, *args, **options):
        start_period = options['period'][0]
        current_period = date.today().strftime("%Y%m")

        DataSyncTracker.update_periods(current_period, start_period)

        one_day_ago = timezone.now() - timedelta(days=1)
        trackers = DataSyncTracker.objects.filter(last_parsed__lte=one_day_ago) \
            .filter(Q(status=DataSyncTrackerStatus.INIT_DOWNLOAD) | Q(status=DataSyncTrackerStatus.DOWNLOADED))
        data_sets = DataSet.objects.all()

        for tracker in trackers:
            try:
                for data_set in data_sets:
                    try:
                        parser = DataSetParser(data_set, tracker.period)
                        parser.parse()
                    except Exception, e:
                        print e.message

                tracker.last_parsed = timezone.now()
                tracker.status = DataSyncTrackerStatus.PARSED
                tracker.save()

            except Exception, e:
                print e.message
    def handle(self, *args, **options):
        period = options['period'][0]

        data_sets = DataSet.objects.all()
        for data_set in data_sets:
            parser = DataSetParser(data_set, period)
            parser.parse()
Ejemplo n.º 3
0
    def test_that_invalid_data_element_is_ignored(self):
        period = 201505
        test_data_values = [{'dataElement': 'wrong'}]

        with patch.object(DataSetParser, 'get_data_values', return_value=test_data_values) as mock_get_values:
            with patch.object(DataSetParser, 'save_data_value', return_value=test_data_values) as mock_method:
                parser = DataSetParser(self.data_set, period)
                parser.parse()

        assert not mock_method.called
Ejemplo n.º 4
0
    def test_that_valid_data_element_is_saved(self):
        period = 201505
        test_data_values = [{'dataElement': self.rdt_data_element.identifier}]

        with patch.object(DataSetParser, 'get_data_values', return_value=test_data_values) as mock_get_values:
            with patch.object(DataSetParser, 'save_data_value', return_value=None) as mock_method:
                parser = DataSetParser(self.data_set, period)
                parser.parse()

        assert mock_method.called
Ejemplo n.º 5
0
    def test_data_value_is_updated_if_integrity_error_occurs(self):
        # Create data value
        period = 201505

        parser = DataSetParser(self.data_set, period)
        parser.save_data_value({'dataElement': self.rdt_data_element.identifier,
                                'categoryOptionCombo': self.positive_under5.identifier,
                                'orgUnit': self.facility1.identifier,
                                'period': 'xx',
                                'value': 10})

        parser.save_data_value({'dataElement': self.rdt_data_element.identifier,
                                'categoryOptionCombo': self.positive_under5.identifier,
                                'orgUnit': self.facility1.identifier,
                                'period': 'xx',
                                'value': 20})

        dv = DataValue.objects.get(facility=self.facility1, data_element=self.rdt_data_element,
                                   category_option_combo=self.positive_under5, period=period)

        self.assertEqual(20, dv.value)