Exemple #1
0
    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)
Exemple #2
0
    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)
Exemple #3
0
    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)
Exemple #4
0
    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')
Exemple #5
0
    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')
Exemple #6
0
    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)
Exemple #7
0
    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')
Exemple #8
0
    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')