def test_initial_upload_with_enough_data(self, new_upload): new_upload.return_value = None os.makedirs('2016/01/26') open('2016/01/26/testdata.txt', 'w').write('x' * 2048) tstamp = int(time.time()) - 48 * 60 * 60 os.utime('2016/01/26/testdata.txt', (tstamp, tstamp)) # Only the younger of the files should be uploaded. The most recent # mtime is used as evidence of the last time rsync was run, and then the # system backs up for the max time between rsync runs before picking a # set of data to upload. os.makedirs('2016/01/27') open('2016/01/27/testdata.txt', 'w').write('x' * 2048) tstamp = int(time.time()) - 24 * 60 * 60 os.utime('2016/01/27/testdata.txt', (tstamp, tstamp)) mock_status = mock.MagicMock() mock_status.get_last_archived_mtime.return_value = datetime.datetime( 2016, 1, 25, 9, 9, 9) mock_args = mock.Mock() mock_args.data_wait_time = datetime.timedelta(hours=1) mock_args.data_buffer_threshold = 1000 self.assertEqual(new_upload.call_count, 0) scraper.upload_stale_disk(mock_args, mock_status, '.', None) self.assertEqual(new_upload.call_count, 1) self.assertLess(new_upload.call_args[0][-1], datetime.datetime(2016, 1, 27, 9, 45, 1))
def test_initial_upload_empty_disk(self, new_upload): mock_status = mock.MagicMock() mock_status.get_last_archived_mtime.return_value = datetime.datetime( 2016, 1, 27, 9, 9, 9) mock_args = mock.Mock() mock_args.data_wait_time = datetime.timedelta(hours=1) scraper.upload_stale_disk(mock_args, mock_status, '.', None) self.assertEqual(new_upload.call_count, 0)
def test_initial_upload_one_safe_dir(self, new_upload): new_upload.return_value = None os.makedirs('2016/01/26') os.makedirs('2016/01/27') self.assertEqual(new_upload.call_count, 0) scraper.upload_stale_disk({}, None, '.', None) self.assertEqual(new_upload.call_count, 1) self.assertEqual(new_upload.call_args[0][-1], datetime.date(2016, 1, 26))
def test_initial_upload_no_safe_dirs(self, new_upload): os.makedirs('2016/01/28') scraper.upload_stale_disk({}, None, '.', None) new_upload.assert_not_called()
def test_initial_upload_empty_disk(self, new_upload): scraper.upload_stale_disk({}, None, '.', None) new_upload.assert_not_called()