Beispiel #1
0
def reload_yesterday_druid_data():
    """
    Refreshes druid data for records created the day before today
    Ideally should be set up as a periodic task that runs at 12:01am
    """
    today = timezone.now()
    yesterday = today - timedelta(days=1)
    get_historical_data(day=yesterday.day,
                        month=yesterday.month,
                        year=yesterday.year)
Beispiel #2
0
 def test_get_historical_data_year(self, json_file_mock, ingest_mock):
     """
     Asset that the filename is correct when you supply just the year
     """
     if not hasattr(settings, "AWS_S3_BASE_URL"):
         self.skipTest("AWS_S3_BASE_URL is not configured.")
     path = "/".join([str(x) for x in [2017, None, None] if x is not None])
     filename = ("{}/".format(settings.DRUID_SPRAYDAY_DATASOURCE) + path +
                 "/sprayday.json")
     get_historical_data(year=2017)
     self.assertTrue(json_file_mock.called)
     self.assertTrue(ingest_mock.called)
     args, kwargs = json_file_mock.call_args_list[0]
     self.assertEqual(kwargs["filename"], filename)
Beispiel #3
0
 def test_get_historical_data(self, json_file_mock, ingest_mock,
                              intervals_mock):
     """
     Test that get historical data actually works by ensuring it calls
     ingest_sprayday with the right arguments
     """
     if not hasattr(settings, "AWS_S3_BASE_URL"):
         self.skipTest("AWS_S3_BASE_URL is not configured.")
     path = "/".join([str(x) for x in [2017, 10, 10] if x is not None])
     filename = ("{}/".format(settings.DRUID_SPRAYDAY_DATASOURCE) + path +
                 "/sprayday.json")
     json_file_mock.return_value = filename
     intervals_mock.return_value = "2013-01-01/2013-01-02"
     get_historical_data(day=10, month=10, year=2017)
     self.assertTrue(json_file_mock.called)
     self.assertTrue(ingest_mock.called)
     mock1_args, mock1_kwargs = json_file_mock.call_args_list[0]
     self.assertEqual(mock1_kwargs["filename"], filename)
     mock2_args, mock2_kwargs = ingest_mock.call_args_list[0]
     self.assertEqual(mock2_args[0], settings.AWS_S3_BASE_URL + filename)
     self.assertEqual(mock2_kwargs["intervals"], "2013-01-01/2013-01-02")