def test_that_download_url_has_lastUpdated_if_status_of_tracker_changed(self):
        five_days_ago = timezone.now() - timedelta(days=5)

        downloader = DataSetDownloader(self.data_set, 201505, 'xxxx', DataSyncTrackerStatus.INIT_DOWNLOAD)
        url = downloader.get_download_url()


        self.assertTrue(('lastUpdated=%s&' % five_days_ago.strftime('%Y-%m-%d')) in url)
    def handle(self, *args, **options):
        period = options['period'][0]
        root_org_unit = 'akV6429SUqu'

        data_sets = DataSet.objects.all()

        for data_set in data_sets:
            downloader = DataSetDownloader(data_set, period, root_org_unit)
            downloader.download()
Ejemplo n.º 3
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_downloaded__lte=one_day_ago) \
            .filter(Q(status=DataSyncTrackerStatus.UNKNOWN) | Q(status=DataSyncTrackerStatus.PARSED)|
                    Q(status=DataSyncTrackerStatus.INIT_PARSE))
        data_sets = DataSet.objects.all()

        for tracker in trackers:
            for data_set in data_sets:
                downloader = DataSetDownloader(data_set, tracker.period, self.ROOT_ORG_UNIT, tracker.status)
                downloader.download()

            tracker.last_downloaded = timezone.now()
            if tracker.status is DataSyncTrackerStatus.UNKNOWN:
                tracker.status = DataSyncTrackerStatus.INIT_DOWNLOAD
            else:
                tracker.status = DataSyncTrackerStatus.DOWNLOADED
            tracker.save()
    def test_that_download_url_has_not_lastUpdated_field_at_beginning(self):
        downloader = DataSetDownloader(self.data_set, 201505, 'xxxx', DataSyncTrackerStatus.UNKNOWN)
        url = downloader.get_download_url()

        self.assertTrue('lastUpdated' not in url)