def test_get_apt_last_update_date_when_file_does_not_exist(self): # Prepare data and mocks with patch('builtins.open', raise_file_not_found_error): update = Update(None) # Run test scenario result = update.get_apt_last_update_date('/tmp/this/file/does/not/exist') # Assertions self.assertIsNone(result)
def test_get_apt_last_update_date_when_file_does_not_exist(self): # Prepare data and mocks with patch('builtins.open', raise_file_not_found_error): update = Update(None) # Run test scenario result = update.get_apt_last_update_date( '/tmp/this/file/does/not/exist') # Assertions self.assertIsNone(result)
def test_get_apt_last_update_date_when_file_exists(self): # Prepare data and mocks with patch('builtins.open', raise_file_not_found_error), NamedTemporaryFile() as temp_file: update = Update(None) seconds_epoch_in_1999 = 923398970 os.utime(temp_file.name, (seconds_epoch_in_1999, seconds_epoch_in_1999)) # Run test scenario result = update.get_apt_last_update_date(temp_file.name) # Assertions self.assertEqual(result.timestamp(), seconds_epoch_in_1999)
def test_scan_debian_when_last_update_date_not_found(self): # Prepare data and mocks config = {'update': {'warn_last_update_interval_days': '2'}} update = Update(config) update.get_apt_last_update_date = MagicMock(return_value=None) # Run test scenario result = update.scan_debian() # Assertions self.assertEqual(result[0], ScanStatus.unknown) update.get_apt_last_update_date.assert_called_once_with( '/var/lib/apt/periodic/update-success-stamp')
def test_scan_debian_when_is_newer(self): # Prepare data and mocks config = {'update': {'warn_last_update_interval_days': '2'}} update = Update(config) update.get_apt_last_update_date = MagicMock( return_value=datetime.today() - timedelta(days=1)) # Run test scenario result = update.scan_debian() # Assertions self.assertEqual(result[0], ScanStatus.success) update.get_apt_last_update_date.assert_called_once_with( '/var/lib/apt/periodic/update-success-stamp')
def test_get_apt_last_update_date_when_file_exists(self): # Prepare data and mocks with patch( 'builtins.open', raise_file_not_found_error), NamedTemporaryFile() as temp_file: update = Update(None) seconds_epoch_in_1999 = 923398970 os.utime(temp_file.name, (seconds_epoch_in_1999, seconds_epoch_in_1999)) # Run test scenario result = update.get_apt_last_update_date(temp_file.name) # Assertions self.assertEqual(result.timestamp(), seconds_epoch_in_1999)
def test_scan_debian_when_last_update_date_not_found(self): # Prepare data and mocks config = { 'update': { 'warn_last_update_interval_days': '2' } } update = Update(config) update.get_apt_last_update_date = MagicMock(return_value=None) # Run test scenario result = update.scan_debian() # Assertions self.assertEqual(result[0], ScanStatus.unknown) update.get_apt_last_update_date.assert_called_once_with('/var/lib/apt/periodic/update-success-stamp')
def test_scan_debian_when_is_newer(self): # Prepare data and mocks config = { 'update': { 'warn_last_update_interval_days': '2' } } update = Update(config) update.get_apt_last_update_date = MagicMock(return_value=datetime.today() - timedelta(days=1)) # Run test scenario result = update.scan_debian() # Assertions self.assertEqual(result[0], ScanStatus.success) update.get_apt_last_update_date.assert_called_once_with('/var/lib/apt/periodic/update-success-stamp')